Developer Guide and Reference

Contents

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 list of the options and libraries used by the OpenMP* libraries, see OpenMP* Support Libraries.
Set up your environment for access to the Intel®
C++
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 (
compilervars
file).
During compilation, ensure that the version of
omp.h
used when compiling is the version provided by that compiler.
For example, use the
omp.h
provided with gcc when you compile on Linux* systems.
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.h
file, then source files that use those data structures should all be compiled with the same
omp.h
file.
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*
gcc
Intel:
icc
g++
Intel:
icpc
macOS*
[prior to v10.9]
gcc
Intel:
icc
g++
Intel:
icpc
macOS*
[v10.9 and later]
clang
Intel:
icc
clang++
Intel: or
icpc
Windows*
Visual C++*:
cl
Intel:
icl
Visual C++*:
cl
Intel:
icl
For information on the OpenMP* libraries and options used by the Intel®
C++
Compiler, see OpenMP* Support Libraries.

Command-Line Examples, Windows*

To compile and link (build) the entire application with one command using the Compatibility libraries, specify the following Intel®
C++
Compiler command:
Type of File
Commands
C source, dynamic link
icl /MD /Qopenmp hello.c
C++ source, dynamic link
icl /MD /Qopenmp hello.cpp
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
C++ source, dynamic link
cl /MD /openmp hello.cpp /link /nodefaultlib:vcomp libiomp5md.lib
You can also use the Intel®
C++
Compiler with the Visual C++* compiler to compile parts of the application and create object files (object-level interoperability). In this example, the Intel®
C++
Compiler compiles and links the entire application:
Type of File
Commands
C source, dynamic link
cl /MD /openmp /c f1.c f2.c
icl /MD /Qopenmp /c f3.c f4.c
icl /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®
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 /c f1.c f2.c
icl /MD /Qopenmp /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®
C++
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 /O3 /Qipo /Qipo-c f1.c f2.c f3.c
cl /MD /openmp /O2 /c f4.c f5.c