Intel® Fortran Compiler XE 13.1 User and Reference Guides

Using the OpenMP* Libraries

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 summary of the support provided by the libraries provided with Intel compilers, see OpenMP* Source Compatibility and Interoperability with Other Compilers.

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 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 Mac OS systems, you can source the appropriate script file (ifortvars file).

To use the gfortran compiler with the Intel OpenMP library along with the OpenMP API functions, do the following:

  1. Use the use omp_lib statement to compile the omp_lib.f90 source file, which is in the Intel compiler include directory.

  2. 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.

Caution

Be aware that when using the GNU*/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 the Intel® Fortran compiler is ifort on Linux, Mac OS X, and Windows operating systems.

For information on the OpenMP libraries and options used by the Intel compiler, see OpenMP* Support Libraries.

Command-Line Examples, Linux OS and Mac OS X

To compile and link (build) the entire application with one command using the Intel OpenMP libraries, specify the following Intel compiler command:

Type of File

Commands

Fortran source

ifort -openmp hello.f90

By default, the Intel compilers perform a dynamic link of the OpenMP libraries. To perform a static link (not recommended), add the option -openmp-link static. The Intel compiler option -openmp-link controls whether the linker uses static or dynamic OpenMP libraries on Linux OS and Mac OS X systems (default is -openmp-link dynamic).

You can also use both Intel C++ icc/icpc and GNU gcc/g++ compilers to compile parts of the application and create object files (object-level interoperability). In this example, the GNU compiler compiles the C file foo.c (the gcc option -fopenmp enables OpenMP support), and the Intel compiler links the application using the Intel OpenMP library:

Type of File

Commands

C source

gcc -fopenmp -c foo.c

icc -openmp foo.o

C++ source

g++ -fopenmp -c foo.cpp

icpc -openmp foo.o

When using GNU gcc or g++ compiler to link the application with the Intel 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 Intel C++ compiler 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<icc_dir>/lib

You can mix object files, but it is easier to use the Intel 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

icc -openmp -c bar.c

icc -openmp foo.o bar.o

You can mix OpenMP object files compiled with the GNU gcc compiler, the Intel® C++ Compiler, and the Intel® Fortran Compiler.

Note

You cannot mix object files compiled by the Intel Fortran compiler and the gfortran compiler.

The table illustrates examples of using the Intel Fortran compiler or the GNU Fortran compiler to link all the objects:

Type of File

Commands

Mixed C and Fortran sources

ifort -openmp -c foo.f

icc -openmp -c ibar.c

gcc -fopenmp -c gbar.c

ifort -openmp foo.o ibar.o gbar.o

When using the Intel Fortran compiler, if the main program does not exist in a Fortran object file that is compiled by the Intel Fortran Compiler ifort, specify the -nofor-main option on the ifort command line during linking.

Note

Do not mix objects created by the Intel Fortran Compiler (ifort) with the GNU Fortran Compiler (gfortran); instead, recompile all Fortran sources with the same Fortran compiler. The GNU Fortran Compiler is only available on Linux operating systems.

Similarly, you can mix object files compiled with the Intel® C++ Compiler, the GNU C/C++ compiler, and the GNU Fortran Compiler (gfortran), if you link with the GNU Fortran Compiler (gfortran). When using GNU gfortran compiler to link the application with the Intel 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 Intel C++ compiler 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

gfortran -fopenmp -c foo.f

icc -openmp -c ibar.c

gcc -fopenmp -c gbar.c

gfortran foo.o ibar.o gbar.o -lirc -liomp5 -lpthread -lc -L<icc_dir>/lib

Alternatively, you could use the Intel 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

icc -openmp -c ibar.c

icc -openmp foo.o bar.o -lgfortranbegin -lgfortran


Submit feedback on this help topic