Difference between revisions of "How to Use OpenMP"

From HPC Wiki
Jump to navigation Jump to search
(Created page with "== Basics == This will give you a general overview of how to compile and execute a program that has been parallelized with MPI. Many of the optio...")
 
Line 1: Line 1:
 
== Basics ==
 
== Basics ==
  
This will give you a general overview of how to compile and execute a program that has been [[Parallel_Programming|parallelized]] with [[MPI]]. Many of the options listed below are the same for both Open MPI and Intel MPI, however, be care if they do differentiate.
+
This will give you a general overview of how to compile and execute a program that has been [[Parallel_Programming|parallelized]] with [[OpenMP]].
  
  
Line 21: Line 21:
 
For example: if you plan to use an Intel compiler for your OpenMP code written in C, you have to type this to create an application called "omp_code.exe":
 
For example: if you plan to use an Intel compiler for your OpenMP code written in C, you have to type this to create an application called "omp_code.exe":
 
  $ icc -fopenmp omp_code.c -o omp_code.exe
 
  $ icc -fopenmp omp_code.c -o omp_code.exe
 +
 +
 +
== How to Run an OpenMP Application ==
 +
 +
=== Setting OMP_NUM_THREADS ===
 +
 +
If you forget to set OMP_NUM_THREADS to any value, the default value of your cluster environment will be used. In most cases, the default is 1, so that your program is executed serially.
 +
 +
One way to specify the number of threads

Revision as of 16:05, 4 April 2018

Basics

This will give you a general overview of how to compile and execute a program that has been parallelized with OpenMP.


How to Compile OpenMP Code

As opposed to MPI, you do not have to load any modules to use OpenMP, but set an additional compiler flags to tell the compiler to enable OpenMP. Otherwise, the OpenMP pragmas in the code will be ignored by the compiler.

Depending on which compiler you have loaded, use one of the flags below to compile your code.

Compiler Flag
GNU -fopenmp
Intel -openmp
Oracle -xopenmp

For example: if you plan to use an Intel compiler for your OpenMP code written in C, you have to type this to create an application called "omp_code.exe":

$ icc -fopenmp omp_code.c -o omp_code.exe


How to Run an OpenMP Application

Setting OMP_NUM_THREADS

If you forget to set OMP_NUM_THREADS to any value, the default value of your cluster environment will be used. In most cases, the default is 1, so that your program is executed serially.

One way to specify the number of threads