High-performance Computing in C++ : Open Muti Processing(OpenMP)
Open Multi-Processing:
?Let's consider the parallelization approaches, basically, we can think of imperative Parallelization and Declarative parallelization.
In the above case, OpenMP comes into the picture. OpenMP is the standard API?for decorating code for multiprocessing
Essentially the OpenMP is a compiler+library solution. Here we completely depend on the compiler to optimize the code but use some library to perform some operations.
In c++, we use #pragma directives to indicate the parallelization. Plenty of compiler clauses support Data Sharing, synchronization, scheduling, etc.?
The following picture gives some details on how the OpenMP works.
Let's see, how that omp for and omp do parallelize the loops to improve the performance and section(s) which assign different code blocks to different threads to optimize the execution. Similarly omp provide the single thread approach, it assigns the single block to a single thread and executes it separately. It implies the barrier at the end of execution. One more concept is "master", in this case, code is always executed by the master thread, and no barrier at end of the execution.?
领英推荐
The following techniques are used in omp for synchronization of code execution.
Let's consider the following code for synchronization.
??????All variables except the loop counter shared by default
?Refer to the following example to check the implementation