Compiling an OpenMP Application

Compiling an OpenMP application is done with the -fopenmp option to GCC and the -openmp or -qopenmp option for Intel.  For example, the command could be:

$ gcc -o openmp-app.exe -fopenmp openmp-app.c

GCC will perform all of the OpenMP pragmas.

OpenMP applications have OpenMP pragmas like #pragma omp <options>

#pragma omp parallel for reduction(+: sum) 
  for (i = 0; i<NUM_STEPS; i++) {
    x = 2.0 * (double)i / (double)(NUM_STEPS); /* value of x */
    sum += x * x;
  }

An example application code is integrate_mp.c. Compiling integrate_mp.c is done with the gcc command:

$ gcc -o integrate_mp.exe -fopenmp integrate_mp.c

See Submitting an OpenMP Job for instructions on how to submit integrate_mp.exe to the cluster.