Using the OpenMP Compatibility Libraries

This section describes the steps needed to set up and use the OpenMP Compatibility Libraries from the command line. On Windows* systems, you can also build applications compiled with the OpenMP Compatibility libraries in the Microsoft Visual Studio* development environment.

For a summary of the support provided by the Compatibility and Legacy 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.

 

During C/C++ compilation, ensure the version of omp.h used when compiling is the version provided by that compiler. For example, on Linux systems when compiling with the GNU C/C++ compiler, use the omp.h provided with the GNU C/C++ compiler. Similarly, during Fortran compilation, ensure that the  version of omp_lib.h or omp_lib.mod used when compiling is the version provided by that compiler.

The following table lists the commands used by the various command-line compilers for both C and C++ source files.:

Operating System

C Source Module

 C++ Source Module

Linux*

GNU: gcc
Intel: icc

GNU: g++
Intel: icpc

Mac OS* X

GNU: gcc
Intel: icc

GNU: g++
Intel: icpc

Windows*

Visual C++: cl
Intel: icl

Visual C++: cl
Intel: icl

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, Windows OS

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

Type of File

Commands

C  source, dynamic link

icl /MD /Qopenmp /Qopenmp-lib:compat hello.c

C++ source, dynamic link

icl /MD /Qopenmp /Qopenmp-lib:compat hello.cpp

Fortran source, dynamic link

ifort /MD /Qopenmp /Qopenmp-lib:compat hello.f90

By default, the Intel compilers perform a dynamic link of the OpenMP libraries. To perform a static link (not recommended), use the /MT option in place of the /MD option above and add the option /Qopenmp-link:static. The Intel compiler option /Qopenmp-link controls whether the linker uses static or dynamic OpenMP libraries on Windows OS systems (default is /Qopenmp-link:dynamic).

When using 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

C++ source, dynamic link

cl /MD /openmp hello.cpp /link /nodefaultlib:vcomp libiomp5md.lib

Performing a static link is not recommended, but would require use of the /MT option in place of the /MD option above.

You can also use both Intel C++ and Visual C++ compilers to compile parts of the application and create object files (object-level interoperability). In this example, the Intel compiler links the entire application:

Type of File

Commands

C source, dynamic link

cl /MD /openmp hello.cpp /c f1.c f2.c

icl /MD /Qopenmp /Qopenmp-lib:compat /c f3.c f4.c

icl /MD /Qopenmp /Qopenmp-lib:compat 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 Intel C++ 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

C source, dynamic link

cl /MD /openmp hello.cpp /c f1.c f2.c

icl /MD /Qopenmp /Qopenmp-lib:compat /c f3.c f4.c

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

C source, dynamic link

icl /MD /Qopenmp /Qopenmp-lib:compat /O3 /Qipo /Qipo-c f1.c f2.c f3.c

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® C++ Compiler to produce an optimized multi-file object file named ipo_out.obj by default (the /Fe option is not required; see Using IPO). 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 compiler OpenMP Compatibility library. Performing a static link (not recommended) requires use of the /MT option in place of the /MD option in each line above.

Command-Line Examples, Linux OS and Mac OS X

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

Type of File

Commands

C  source

icc -openmp -openmp-lib=compat hello.c

C++ source

icpc -openmp -openmp-lib=compat hello.cpp

Fortran source

ifort -openmp -openmp-lib=compat 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 OpenMP Compatibility library:

Type of File

Commands

C source

gcc -fopenmp -c foo.c

icc -openmp -openmp-lib=compat foo.o

C++ source

g++ -fopenmp -c foo.cpp

icpc -openmp -openmp-lib=compat 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 compatibility library name using the -l option, the GNU 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 -openmp=compat 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. This example uses use the Intel 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 -openmp-lib=compat 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 GNU 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 -openmp-lib=compat foo.o bar.o -lgfortranbegin -lgfortran