With the C++17 standard, the contents of the Parallelism Technical Specification are added to modern C++, and as a result, make their way into many C++ compilers and IDEs, such as the latest C++ Builder 12. This feature adds new overloads, taking an additional execution policy argument, to many algorithms, as well as entirely new algorithms. Three execution policies are supported, which respectively provide sequential, parallel, and vectorized execution.
Table of Contents
What is parallel programming (parallelism, parallel computing) ?
Parallel computing (Parallel Programming, Parallelism, Parallelization) is a type of computation that applies many calculations or processes simultaneously.
Parallel Programming is generally used to solve heavy calculation problems such as real-time analysis of multi-dimensional data, image processing, calculations on fluid mechanics, thermodynamics, and other engineering problems. Parallel Programming is a method that uses multiple computational resources, processors, or processing by groups of servers. Generally, in this type of programming, it takes a problem, breaks it down into a series of smaller steps, delivers instructions, and processors execute the solutions of each part at the same time in different Threads, CPU Cores, CPUs, GPUs. There are many ways to use parallel programming methods and skills, here is an example,
What is the development history of parallelism in C++?
We can classify the parallel computation level by the level of the hardware technology that supports parallel computation technologies. This depends on your CPU, GPU, Hardware (board, rams, chipsets, …) and Networking technologies (Connection protocols, fibers, WiFi, 5G, etc.) . In other words, this is mostly depends to the distance between computational nodes and its architecture. In the early ages of computers, and computation, some high-processing computer (such as Cray computers) became famous for their vector-processing computers in the 1970s and 1980s. However, vector processors—both as CPUs and as full computer systems—have generally disappeared. Today, we have modern processor instruction sets that have modern vector processing instructions. In addition to these Vector processor examples, we have many Parallelism examples, such as; Multi-core computing, Symmetric multiprocessing, Distributed computing, Cluster computing, Massively parallel computing, Grid computing, Cloud computing, Specialized parallel computers, Reconfigurable computing with field-programmable gate arrays, General-purpose computing on graphics processing units (GPGPU), Application-specific integrated circuits.
In 2012, by the improvements in GPUs, representatives from NVIDIA, Microsoft and Intel, independently proposed library approaches to parallel computing in the C++ Standard Library. The authors of these proposals submitted a design in a joint proposal to parallelize the existing standard algorithms library. This proposal was refined under the name of the “Parallelism Technical Specification” over two years. During this process, the Parallelism Technical Specification community, added a lot of feedback from their experimental implementations, since the final version which was published in 2015. As a result, the C++ Standardization Committee had spend three years of experience with the Technical Specification’s design, then all these Parallelism Technical Specifications are added to the C++17 standard, and they are improved in C++20, and still being improved in C++23. (source: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0024r2.html).
Parallelism is very important part of programming, because your algorithm can speed up 100-200 times or more (depends of number of CPU cores or GPU cores/transistors). This is why it needs to be improved in every new standard.
What is the std::sort algorithm parallelism feature in C++?
One of the great examples of parallelism is the std::sort algorithm in modern C++. The Standard Template Library or STL has many algorithms for operations like searching, counting, and manipulation of ranges and their elements. C++17 has a new feature that you can sort with the std::sort parallel STL algorithm.
The std::sort parallel STL Algorithm sorts the elements in the range from the first member to the last member in non-descending order. If it sorts equal elements can’t be guaranteed that their positions will be preserved.
The syntax for the std::sort algorithm can be described below.
As an ExecutionPolicy std::execution::seq
is used for the sequential execution, std::execution::par
is used for parallel execution. In total, there are 3 ExecutionPolicy values you can use here:
std::execution::seq
std::execution::par
std::execution::par_unseq
Are there any examples of parallelism or parallel programming in C++
The modern C++ has many features to be used in parallel programming, such as lambda, templates, vectors, algorithms, STL compare functions, etc. etc. Here are some posts and very simple C++ examples below,
For more details about changes in C++17 standard, please see this https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0024r2.html or see other papers such as P0336R1, P0394R4, P0452R1, P0467R2, P0502R0, P0518R1, P0523R1, P0574R1, P0623R0.
C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.