Replace Annotations with OpenMP* Code
Replace
Annotations with OpenMP* CodeThis topic explains the steps needed to implement parallelism proposed by the
Intel Advisor
annotations by adding OpenMP* parallel framework code.
- Add OpenMP code to provide appropriate synchronization of shared resources, using the LOCK annotations as a guide.Adding OpenMP Code to Synchronize the Shared Resources provides an overview of the following OpenMP synchronization techniques:
- Add code to create OpenMP tasks, using the SITE/TASK annotations as a guide.The following topics cover the OpenMP task creation options:
The recommended order for replacing the annotations with OpenMP code:
- Add appropriate synchronization of shared resources, using LOCK annotations as a guide.
- Test to verify you did not break anything, before adding the possibility of non-deterministic behavior with parallel tasks.
- Add code to create OpenMP parallel sections or equivalent, using the SITE/TASK annotations as a guide.
- Test with one thread to verify that your program still works correctly. For example, set the environment variableOMP_NUM_THREADSto 1 before you run your program.
- Test with more than one thread to see that the multithreading works as expected.
After you rewrite your code to use OpenMP* parallel framework, you can analyze its performance with
Intel® Advisor
perspectives. Use the
Vectorization and Code Insights
perspective to analyze how well you OpenMP code is vectorized or use the
Offload Modeling
perspective to model its performance on a GPU.
OpenMP creates worker threads automatically. In general, you should concern yourself only with the tasks, and leave it to the parallel frameworks to create and destroy the worker threads.
If you do need some control over creation and destruction of worker threads, see the compiler documentation. For example, to limit the number of threads, set the
OMP_THREAD_LIMIT
or the
OMP_NUM_THREADS
environment variable.
The table below shows the serial, annotated program code in the left column and the equivalent OpenMP C/C++ and Fortran parallel code in the right column for some typical code to which parallelism can be applied.
Serial C/C++ and Fortran Code with
Intel Advisor Annotations | Parallel C/C++ and Fortran Code using OpenMP
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|