- OpenMP Directives
- Complier Flags
- OpenMP Environment Variables
- Running an OpenMP Program as a Batch Job
OpenMP is a parallel programming specification used to create C/C++ and Fortran shared-memory parallel programs on multi-processor nodes. For large problems, where you want to run on more processors than are available on a single node, you can combine MPI with OpenMP to run on more than one node, where some or all of the nodes are SMP nodes. OpenMP is portable across a number of platforms and compilers. If you are unfamiliar with the OpenMP Standard and would like additional information to that which is provided here, you can read the OpenMP Specifications.
With OpenMP, parallel execution on shared memory processors is achieved by adding parallelization directives to existing programs. The form of a parallelization directive for Fortran is:
and for C/C++ is:
#pragma omp directive
See OpenMP Directives for more information and examples.
To enable OpenMP, add the following compiler flag when you compile your program:
To run an OpenMP job in parallel you must set the OMP_NUM_THREADS runtime environment variable to specify the number of threads to use during the execution of the parallel regions of the code. If you omit setting this variable, it will default to 1 and your program will not run in parallel. While you can request a number of threads that is greater than the number of physical processors (cores) on the node and the program will execute correctly, the performance of programs executed in this manner is unpredictable and often poor. Therefore, do not specify a number of threads that is greater than the number of cores per node on the cluster you are using.
For the C Shell specify:
setenv OMP_NUM_THREADS number
For the Bash Shell specify:
Other OpenMP Environment Variables
The following table lists other less often used environment variables that can be set at runtime.
|OMP_SCHEDULE||Sets the run-time schedule type and chunk size.||static, no chunk size specified|
|OMP_NESTED||Enables or disables nested parallelism.||false|
|OMP_DYNAMIC||Enables or disables the dynamic adjustment of the number of threads.||false|
There are two ways to submit an OpenMP batch job to the Hoffman2 Cluster. They are from easiest to hardest:
- via the queue script:
- by generating a UGE command file for the job and using UGE commands to submit it.