Using OpenMP*

To run the Intel® compiler in OpenMP mode, invoke the compiler with the -openmp (Linux* and Mac OS*) or /Qopenmp (Windows*) option using a command structured similar to the following:

Platform

Description

Linux and Mac OS

icc -openmp input_file

Windows

icl /Qopenmp input_file

Before you run the multi-threaded code, you can set the number of desired threads in the OpenMP environment variable, OMP_NUM_THREADS. For more information, see the OpenMP Environment Variables section. The Intel Extension Routines topic describes the OpenMP extensions to the specification that have been added by Intel to the Intel® compiler.

OpenMP Option

The -openmp (Linux and Mac OS) or /Qopenmp (Windows) option enables the parallelizer to generate multithreaded code based on the OpenMP directives. The code can be executed in parallel on uniprocessor, multiprocessor, and dual-core processor systems.

The openmp option works with both -O0 (Linux and Mac OS) and /Od (Windows) and with any optimization level of -O1, -O2 and -O3. (Linux and Mac OS) or /O1, /O2 and /O3 (Windows).

Specifying -O0 (Linux and Mac OS) or /Od (Windows) with the OpenMP option helps to debug OpenMP applications.

Note

Intel® Itanium®-based systems: Specifying this option implies -opt-mem-bandwith1 (Linux and Mac OS) or /Qopt-mem-bandwidth1 (Windows).

OpenMP Pragma Format and Syntax

OpenMP pragmas use a specific format and syntax. The following syntax and example help illustrate how to use the pragmas with your source.

Syntax

#pragma omp directive-name [clause, ...] newline

where:

The following example demonstrates one way of using an OpenMP* pragma to parallelize loops within parallel regions.

Example

int i;

void simple_omp(int *a){

  #pragma omp parallel for

  for (i=0; i<1024; i++)

    a[i] = i*2;

}

Assume that you compile the sample above, using the commands similar to the following, where -c (Linux and Mac OS) or /c (Windows) instructs the compiler to compile the code without generating an executable:

Platform

Description

Linux and Mac OS*

icc -openmp -c parallel.cpp

Windows

icl /Qopenmp /c parallel.cpp

The compiler might return a message similar to the following:

parallel.c(20) : (col. 3) remark: OpenMP DEFINED LOOP WAS PARALLELIZED.