To run the Intel® compiler in OpenMP mode, invoke the compiler with the -openmp (Linux*) or /Qopenmp (Windows*) option using a command structured similar to the following:
Platform |
Description |
---|---|
Linux |
ifort -openmp input_file |
Windows |
ifort /Qopenmp input_file |
Before you run the multithreaded 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.
The -openmp (Linux*) 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 (Linux) or /Qopenmp (Windows) option works with both -O0 (Linux) and /Od (Windows), or with any optimization level of -O1, -O2 and -O3. (Linux) or /O1, /O2 and /O3 (Windows). Specifying -O0 (Linux) or /Od (Windows) with the OpenMP option helps to debug OpenMP applications.
Intel® Itanium®-based systems: Specifying this option implies -opt-mem-bandwith1 (Linux) or /Qopt-mem-bandwidth1 (Windows).
OpenMP directives use a specific format and syntax. The following syntax and example help illustrate how to use the directives with your source.
Syntax |
---|
<prefix> <directive> [<clause>[[,]<clause>...]] |
where:
<prefix>: Required for OpenMP. For fixed form source input, the prefix is !$OMP or C$OMP. For free form source input, the prefix is !$OMP only.
<directive>: Required must immediately follow the prefix; for example: !$OMP PARALLEL
[<clause>]: Must be specified if a directive uses one or more clauses
[,]: Commas between the <clause>s are optional.
Since OpenMP directives begin with an exclamation point, the directives are interpreted as comments if you omit the -openmp (Linux) or /Qopenmp ((Windows) option.
The following example demonstrates one way of using an OpenMP* directive to parallelize loops within parallel regions.
Example |
---|
subroutine simple_omp(a, N) integer :: N, a(N) !$OMP PARALLEL DO do i = 1, N a(i) = i*2 end do end subroutine simple_omp |
Assume that you compile the sample above, using the commands similar to the following, where -c (Linux) or /c (Windows) instructs the compiler to compile the code without generating an executable:
Platform |
Description |
---|---|
Linux |
ifort -openmp -c parallel.f90 |
Windows |
ifort /Qopenmp /c parallel.f90 |
The compiler might return a message similar to the following:
parallel.f90(20) : (col. 6) remark: OpenMP DEFINED LOOP WAS PARALLELIZED.
The OpenMP constructs defining a parallel region have one of the following syntax forms:
Example |
---|
!$OMP <directive> <structured block of code> !$OMP END <directive> or !$OMP <directive> <structured block of code> or !$OMP <directive> |
where <directive> is the name of a particular OpenMP directive.
The -openmp-report (Linux) or /Qopenmp-report (Windows) option controls the OpenMP* parallelizer's diagnostic levels 0, 1, or 2 as follows:
Windows* |
Linux* |
Description |
---|---|---|
/Qopenmp-report0 |
-openmp-report0 |
No diagnostic information is displayed. |
/Qopenmp-report1 |
-openmp-report1 |
Display diagnostics indicating loops, regions, and sections successfully parallelized. |
/Qopenmp-report2 |
-openmp-report2 |
Same as specifying 1 plus diagnostics indicating constructs like MASTER, SINGLE, CRITICAL, ORDERED, ATOMIC directives, and so forth are successfully handled. |
For more information about the option behaviors listed above, see the following topic in Compiler Options: