Intel® Fortran Compiler 17.0 Developer Guide and Reference
To add OpenMP* support to your application, do the following:
Add the appropriate OpenMP* directives to your source code.
Compile the application with the Qopenmp (Windows) or qopenmp (Linux* and OS X*) option.
For applications with large local or temporary arrays, you may need to increase the stack space available at run-time. In addition, you may need to increase the stack allocated to individual threads by using the OMP_STACKSIZE environment variable or by setting the corresponding library routines.
You can set other environment variables to control multi-threaded code execution.
To add OpenMP* support to your application, first add appropriate OpenMP* directives to your source code.
OpenMP* directives use a specific format and syntax. Intel Extension Routines to OpenMP* describes the OpenMP* extensions to the specification that have been added to the Intel® Fortran Compiler.
The following syntax illustrates using the directives in your source.
Example |
---|
|
where:
<prefix> - Required for all OpenMP* directives. For free form source input, the prefix is !$OMP only; for fixed form source input, the prefix is !$OMP or C$OMP.
<directive> - A valid OpenMP* directive. Must immediately follow the prefix; for example: !$OMP PARALLEL.
[<clause>] - Optional. Clauses can be in any order and repeated as necessary, unless otherwise restricted.
[<newline>] - A required component of directive syntax. It precedes the structured block which is enclosed by this directive.
[,]: Optional. Commas between more than one <clause> are optional.
The directives are interpreted as comments if you omit the Qopenmp (Windows) or qopenmp (Linux* and OS X*) option.
The OpenMP* constructs defining a parallel region have one of the following syntax forms:
Example |
---|
|
The following example demonstrates one way of using an OpenMP* directive to parallelize a loop.
Example |
---|
|
The Qopenmp (Windows) or qopenmp (Linux* and OS X*) option enables the parallelizer to generate multi-threaded code based on the OpenMP* directives in the source. The code can be executed in parallel on single processor, multi-processor, or multi-core processor systems.
The Qopenmp (Windows) or qopenmp (Linux* and OS X*) option works with both -O0 (Linux* and OS X*) and /Od (Windows*) and with any optimization level of O1, O2 and O3.
Specifying -O0 (Linux* and OS X*) or /Od (Windows*) with the Qopenmp (Windows) or qopenmp (Linux* and OS X*) option helps to debug OpenMP* applications.
Compile your application using commands similar to those shown below:
Operating System |
Syntax Example |
---|---|
Linux* |
ifort -qopenmp source_file |
OS X* |
ifort -qopenmp source_file |
Windows* |
ifort /Qopenmp source_file |
Assume that you compile the sample above, using commands similar to the following, where the c option instructs the compiler to compile the code without generating an executable:
Operating System |
Extended Syntax Example |
---|---|
Linux* |
ifort -qopenmp -c parallel.f90 |
OS X* |
ifort -qopenmp -c parallel.f90 |
Windows* |
ifort /Qopenmp /c parallel.f90 |
The compiler might return a message similar to the following:
Example |
---|
|
Configure the OpenMP* Environment
Before you run the multi-threaded code, you can set the number of desired threads using the OpenMP* environment variable, OMP_NUM_THREADS.