GNU OpenMP Example
Disclaimer: This is NOT a course on learning OpenMP. This is a very basic example on compiling an OpenMP example using the GNU compilers.
1 What is OpenMP? | 1.1 Example | 1.2 Compile and Link Libraries | 1.3 Using OMP_NUM_THREADS Environment Variable
What is OpenMP?
OpenMP is a “specification for a set of compiler directives, library routines, and environment variables that can be used to specify high-level parallelism in Fortran and C/C++ programs.”
Example
Compile and Link Libraries
To indicate to the compile you’re using OpenMP use the -fopenmp
compile option and link the gomp
library.
Do not link using -lomp
, this is related to the LLVM/Clang project and not GNU.
This library is not part of the standard compute node image.
Using OMP_NUM_THREADS Environment Variable
We can limit the number of cores for OpenMP to use by setting the OMP_NUM_THREADS
environment variable: