Skip to main content

7.3) Compiling And Submitting OpenMP Jobs (cont'd)


To compile OpenMP code a suitable flag must be passed to the compiler. For the Intel compilers, the flag is –openmp, and can be used in conjunction with other valid compiler flags and optimisations. For instance, the basic compilation of an OpenMP code in Fortran would take the form:

[bash]
$ ifort –openmp –o omp_prog omp_prog.f90
[/bash]

And for C:

[bash]
$ icc –openmp –o omp_prog omp_prog.c
[/bash]

If the OpenMP flag to the compiler is omitted, the compiler will ignore all OpenMP directives and compile the code as a serial code.

By default, when executed the compiled OpenMP code will launch a single process. The environment variable $OMP_NUM_THREADS is used to set the number of processes the OpenMP program will launch. In the Bash shell the variable can be set on the command line:

[bash]
$ export OMP_NUM_THREADS=n
[/bash]

Where n is the number of processes/cores.