Use 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® oneAPI
to ensure that the appropriate OpenMP library is available during linking.
DPC++/C++
CompilerOn 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* systems, you can source the appropriate script file ( file).
setvars
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 with GCC.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:
icx | g++ Intel:
icpx |
Windows
| Visual C++:
cl Intel:
icx | Visual C++:
cl Intel:
icx |
For information on the OpenMP libraries and options used by the compiler, see
OpenMP* Support Libraries.
Command-Line Examples, Linux
To compile and link (build) the entire application with one command using the Intel OpenMP libraries, specify the following
Intel oneAPI
command on Linux platforms:
DPC++/C++
CompilerType of File
| Commands
|
---|---|
C source
| icx -qopenmp hello.c |
C++ source
| icpx -qopenmp hello.cpp |
By default, the
Intel oneAPI
performs a dynamic link of the OpenMP libraries. To perform a static link (not recommended), add the option
DPC++/C++
Compiler-qopenmp-link=static
. The option
-qopenmp-link
controls whether the linker uses static or dynamic OpenMP libraries on Linux systems (default is
-qopenmp-link=dynamic
).
You can also use the
compilers with the
icx
/icpx
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 oneAPI
links the application using the Intel OpenMP library:
DPC++/C++
CompilerType of File
| Commands
|
---|---|
C source
| gcc -fopenmp -c foo.c |
C++ source
| g++ -fopenmp -c foo.cpp |
When using
gcc
or the
g++
compiler to link the application with the
Intel oneAPI
OpenMP compatibility library, you need to explicitly pass the Intel OpenMP library name using the
DPC++/C++
Compiler-l
option, the Linux
pthread
library using the
-l
option, and path to the Intel libraries where the
Intel oneAPI
is installed using the
DPC++/C++
Compiler-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 oneAPI
to link the application so you do not need to specify the
DPC++/C++
Compilergcc
-l
option,
-L
option, and the
-lpthread
option:
Type of File
| Commands
|
---|---|
C source
| gcc -fopenmp -c foo.c icx -qopenmp -c bar.cicx -qopenmp foo.o bar.o |
You can mix OpenMP object files compiled with GCC,
or
.
Intel oneAPI
DPC++/C++
CompilerYou cannot mix object files compiled by the Intel® Fortran Compiler and the
gfortran
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.cgcc -fopenmp -c gbar.c ifort -qopenmp -c foo.f ifort -qopenmp foo.o ibar.o gbar.o |
Type of File
| Commands
|
---|---|
Mixed C and GNU Fortran sources
| icx -qopenmp -c ibar.cgcc -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 oneAPI
to link the application, but need to pass multiple
DPC++/C++
Compilergfortran
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.cicx -qopenmp foo.o bar.o -lgfortranbegin -lgfortran |
Command-Line Examples, Windows
To compile and link (build) the entire application with one command using the Compatibility libraries, specify the following command:
Type of File
| Commands
|
---|---|
C source, dynamic link
| icx /MD /Qopenmp hello.c |
C++ source, dynamic link
| icpx /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 oneAPI
with the Visual C++ Compiler to compile parts of the application and create object files (object-level interoperability). In this example, the
DPC++/C++
CompilerIntel oneAPI
compiles and links the entire application:
DPC++/C++
CompilerType of File
| Commands
|
---|---|
C source, dynamic link
| cl /MD /openmp /c f1.c f2.c icx /MD /Qopenmp /c f3.c f4.cicx /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 oneAPI
. The final command links all four object files into an application.
DPC++/C++
CompilerAlternatively, 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 icx /MD /Qopenmp /c f3.c f4.clink 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 oneAPI
on several files, the Visual C++ Compiler compiles several files, and the Visual C++ linker links the object files to create the executable:
DPC++/C++
CompilerType of File
| Commands
|
---|---|
C source, dynamic link
| icx /MD /Qopenmp /O3 /Qipo /Qipo-c f1.c f2.c f3.ccl /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 oneAPI
to produce an optimized multi-file object file named
DPC++/C++
Compileripo_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 oneAPI
OpenMP library.
DPC++/C++
CompilerUse Intel OpenMP Libraries from Visual Studio
When using systems running Windows, you can make certain changes in the Visual C++ Visual Studio* development environment to allow you to use the
Intel oneAPI
and Visual C++ to create applications that use the Intel OpenMP libraries.
DPC++/C++
CompilerMicrosoft Visual C++ must have the symbol
defined or it will include the manifest for the
_OPENMP_NOFORCE_MANIFEST
vcomp90
dlls. While this may not appear to cause a problem on the build system, it will cause a problem when the application is moved to another system that does not have this DLL installed.
Set the project
Property Pages
to indicate the Intel OpenMP run-time library location:
- Open the project's property pages in from the main menu:(or right click the Project name and selectProperties) .
- Select.
- Enter the path to the Intel®-provided compiler libraries. For example, for an IA-32 architecture system (C++ only), enter:<Intel_compiler_installation_path>\IA32\LIB
Make the Intel OpenMP dynamic run-time library accessible at run-time; you must specify the corresponding path:
- Open the project's property pages in from the main menu:Project>Properties(or right click the Project name and selectProperties).
- Select.
- Enter the path to the Intel®-provided compiler libraries. For example, for an IA-32 architecture system (C++ only), enter:PATH=%PATH%;<Intel_compiler_installation_path>\IA32\Bin
Add the Intel OpenMP run-time library name to the linker options and exclude the default Microsoft OpenMP run-time library:
- Open the project's property pages in from the main menu:(or right click the Project name and selectProperties).
- Select.
- Enter the OpenMP library name and the Visual C++ linker option,/nodefaultlib.