This section describes the steps needed to set up and use the OpenMP* Libraries from the command line. On Windows* systems, you can also build applications compiled with the OpenMP libraries in the Microsoft Visual Studio* development environment.
For a list of the options and libraries used by the OpenMP libraries, see OpenMP* Support Libraries.
Set up your environment for access to the Intel® Fortran Compiler to ensure that the appropriate OpenMP library is available during linking. On Windows systems, you can either execute the appropriate batch (.bat) file or use the command-line window supplied in the compiler program folder that already has the environment set up. On Linux* and macOS* systems, you can source the appropriate script file (setvars file).
To use the gfortran Compiler with the Intel® OpenMP library along with the OpenMP API functions, do the following:
Use the use omp_lib statement to compile the omp_lib.f90 source file, which is in the include directory.
Add the -I option to the compile command line with appropriate path to the directory containing the resulting module file.
During compilation, ensure that the version of omp_lib.h or omp_lib.mod used when compiling is the version provided by that compiler.
Be aware that when using the GCC or Microsoft* Compiler, you may inadvertently use inappropriate header/module files. To avoid this, copy the header/module file(s) to a separate directory and put it in the appropriate include path using the -I option.
If a program uses data structures or classes that contain members with data types defined in omp_lib.h file, then source files that use those data structures should all be compiled with the same omp_lib.h file.
The command for Intel® Fortran Compiler Classic is ifort. The command for Intel® Fortran Compiler is ifx. In all the below Windows* and Linux* examples, the command ifx can be substituted for the command ifort.
For information on the OpenMP libraries and options used by the compiler, see OpenMP* Support Libraries.
To compile and link (build) the entire application with one command using the Intel OpenMP libraries, specify the following Intel Fortran Compiler Classic and Intel Fortran Compiler command on Linux platforms:
Type of File |
Commands |
---|---|
Fortran source |
ifort -qopenmp hello.f90 |
By default, the Intel Fortran Compiler Classic and Intel Fortran Compiler performs a dynamic link of the OpenMP libraries. To perform a static link (not recommended), add the option -qopenmp-link=static. The option -qopenmp-link controls whether the linker uses static or dynamic OpenMP libraries on Linux and macOS* systems (default is -qopenmp-link=dynamic).
You can also use the icx/icpx compilers with the gcc/g++ compilers to compile parts of the application and create object files (object-level interoperability).
In this example, gcc compiles the C file foo.c (the gcc option -fopenmp enables OpenMP support), and the Intel Fortran Compiler Classic and Intel Fortran Compiler links the application using the Intel OpenMP library:
Type of File |
Commands |
---|---|
C source |
gcc -fopenmp -c foo.c ifort -qopenmp foo.o |
When using gcc or the g++ compiler to link the application with the Intel Fortran Compiler Classic and Intel Fortran Compiler OpenMP compatibility library, you need to explicitly pass the Intel OpenMP library name using the -l option, the Linux pthread library using the -l option, and path to the Intel libraries where the is installed using the -L option:
Type of File |
Commands |
---|---|
C source |
gcc -fopenmp -c foo.c bar.c gcc foo.o bar.o -liomp5 -lpthread -L<icx_dir>/lib |
You can mix object files, but it is easier to use the Intel Fortran Compiler Classic and Intel Fortran Compiler to link the application so you do not need to specify the gcc-l option, -L option, and the -lpthread option:
Type of File |
Commands |
---|---|
C source |
gcc -fopenmp -c foo.c icx -qopenmp -c bar.c (Linux and macOS*) ifort -qopenmp foo.o bar.o (Linux and macOS*) |
You can mix OpenMP object files compiled with GCC, Intel Fortran Compiler Classic and Intel Fortran Compiler.
The table illustrates examples of using the Intel Fortran Compiler to link all the objects:
Type of File |
Commands |
---|---|
Mixed C and Fortran sources |
icx -qopenmp -c ibar.c gcc -fopenmp -c gbar.c ifort -qopenmp -c foo.f ifort -qopenmp foo.o ibar.o gbar.o |
When using the Intel Fortran Compiler Classic and Intel Fortran Compiler, if the main program does not exist in a Fortran object file that is compiled by either the Intel Fortran Compiler Classic and Intel Fortran Compiler, specify the -nofor-main option on the command line during linking.
Do not mix objects created by the Intel Fortran Compiler Classic and Intel Fortran Compiler with the GNU Fortran Compiler (gfortran); instead, recompile all Fortran sources with the Intel Fortran Compiler Classic and Intel Fortran Compiler, or recompile all Fortran sources with the GNU Fortran Compiler . The GNU Fortran Compiler is only available on Linux operating systems.
Similarly, you can mix object files compiled with the , the GNU C/C++ Compiler, and the GNU Fortran Compiler (gfortran), if you link with the GNU Fortran Compiler (gfortran). When using the GNU gfortran Compiler to link the application with the Intel Fortran Compiler Classic and Intel Fortran Compiler OpenMP compatibility library, you need to explicitly pass the Intel® OpenMP compatibility library name and the Intel® irc libraries using the -l options, the Linux pthread library using the -l option, and path to the Intel® libraries where the is installed using the -L option. You do not need to specify the -fopenmp option on the link line:
Type of File |
Commands |
---|---|
Mixed C and GNU Fortran sources |
icx -qopenmp -c ibar.c gcc -fopenmp -c gbar.c gfortran -fopenmp -c foo.f gfortran foo.o ibar.o gbar.o -lirc -liomp5 -lpthread -lc -L<icx_dir>/lib |
Alternatively, you could use the Intel Fortran Compiler Classic and Intel Fortran Compiler to link the application, but need to pass multiple gfortran libraries using the -l options on the link line:
Type of File |
Commands |
---|---|
Mixed C and Fortran sources |
gfortran -fopenmp -c foo.f icx -qopenmp -c ibar.c ifort -qopenmp foo.o ibar.o -lgfortranbegin -lgfortran |
macOS* is only supported for ifort.
To compile and link (build) the entire application with one command using the Intel OpenMP libraries, specify the following Intel Fortran Compiler Classic command on macOS* platforms:
Type of File |
Commands |
---|---|
Fortran source |
ifort -qopenmp hello.f90 |
By default, the Intel Fortran Compiler Classic performs a dynamic link of the OpenMP libraries. To perform a static link (not recommended), add the option -qopenmp-link=static. The option -qopenmp-link controls whether the linker uses static or dynamic OpenMP libraries on Linux and macOS* systems (default is -qopenmp-link=dynamic).
You can also use the icx/icpx with gcc/g++ compilers to compile parts of the application and create object files (object-level interoperability).
Mixed compiling using with GCC Compilers is possible only on older macOS* platforms. The latest macOS* v10.x platforms do not include the GCC Compiler, and the Clang Compiler included in the latest macOS* 10.x does not support OpenMP implementation. Future versions of Clang Compiler may support OpenMP implementation.
In this example, icx compiles the C file foo.c,icpx compiles the file ifoo.cpp, the option Qopenmp (Windows) or qopenmp (Linux or macOS*) enables OpenMP support, and the Intel Fortran Compiler Classic links the application using the Intel OpenMP library:
Type of File |
Commands |
---|---|
C source |
icx -qopenmp -c foo.c |
C++ source |
icpx -qopenmp -c ifoo.cpp |
Fortran source |
ifort -qopenmp foo.o ifoo.o |
GCC is absent on macOS* v10.9 and later. However, you may install GCC along with Intel Fortran Compiler Classic.
You can mix object files, but it is easier to use Intel Fortran Compiler Classic to link the application so you do not need to specify the gcc-l option, -L option, and the -lpthread option:
Type of File |
Commands |
---|---|
C source |
icx -qopenmp -c bar.c ifort -qopenmp -c foo.f90 ifort -qopenmp foo.o bar.o |
When using Intel® Fortran Compiler Classic, if the main program does not exist in a Fortran object file that is compiled by ifort, specify the -nofor-main option on the ifort command line during linking.
Alternatively, you could use Intel Fortran Compiler Classic to link the application, but need to pass multiple gfortran libraries using -l options on the link line:
Type of File |
Commands |
---|---|
Mixed C and Fortran sources |
gfortran -fopenmp -c foo.f icx -qopenmp -c ibar.c ifort -qopenmp foo.o ibar.o -lgfortranbegin -lgfortran |
To compile and link (build) the entire application with one command using the Compatibility libraries, specify the following command:
Type of File |
Commands |
---|---|
Fortran source, dynamic link |
ifort /MD /Qopenmp hello.f90 |
When using the Microsoft Visual C++ Compiler, you should link with the Intel® OpenMP compatibility library. You need to avoid linking the Microsoft OpenMP run-time library (vcomp) and explicitly pass the name of the Intel® OpenMP compatibility library as linker options (following /link):
Type of File |
Commands |
---|---|
C source, dynamic link |
cl /MD /openmp hello.c /link /nodefaultlib:vcomp libiomp5md.lib |
You can also use the Intel® Fortran Compiler Classic and Intel® Fortran Compiler with the Visual C++ Compiler to compile parts of the application and create object files (object-level interoperability). In this example, the Intel Fortran Compiler Classic and Intel Fortran Compiler compiles and links the entire application:
Type of File |
Commands |
---|---|
Mixed C and Fortran sources, dynamic link |
cl /MD /openmp /c f1.c f2.c ifort /MD /Qopenmp /c f3.f f4.f ifort /MD /Qopenmp f1.obj f2.obj f3.obj f4.obj /Feapp /link /nodefaultlib:vcomp |
The first command produces two object files compiled by Visual C++ Compiler, and the second command produces two more object files compiled by the Intel Fortran Compiler Classic and Intel Fortran Compiler. The final command links all four object files into an application.
Alternatively, the third line below uses the Visual C++ linker to link the application and specifies the Compatibility library libiomp5md.lib at the end of the third command:
Type of File |
Commands |
---|---|
Mixed C and Fortran sources, dynamic link |
cl /MD /openmp /c f1.c f2.c ifort /MD /Qopenmp /c f3.f f4.f link f1.obj f2.obj f3.obj f4.obj /out:app.exe /nodefaultlib:vcomp libiomp5md.lib |
The following example shows the use of interprocedural optimization by the Intel Fortran Compiler Classic and Intel Fortran Compiler on several files, the Visual C++ Compiler compiles several files, and the Visual C++ linker links the object files to create the executable:
Type of File |
Commands |
---|---|
Mixed C and Fortran sources, dynamic link |
ifort /MD /Qopenmp /O3 /Qipo /Qipo-c f1.f f2.f f3.f cl /MD /openmp /O2 /c f4.c f5.c cl /MD /openmp /O2 ipo_out.obj f4.obj f5.obj /Feapp /link /nodefaultlib:vcomp libiomp5md.lib |
The first command uses the Intel Fortran Compiler Classic and Intel Fortran Compiler to produce an optimized multi-file object file named ipo_out.obj by default (the /Fe option is not required). The second command uses the Visual C++ Compiler to produce two more object files. The third command uses the Visual C++ cl command to link all three object files using the Intel Fortran Compiler Classic and Intel Fortran Compiler OpenMP library.