intel® openmp* compatibility libraries › ... › m › d › 4 › 1 › d › 8 ›...

22
Intel® OpenMP* Compatibility Libraries Usage Guide Copyright © 2007-2008 Intel® Corporation All Rights Reserved. World Wide Web: http://www.intel.com/

Upload: others

Post on 29-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

Usage Guide

Copyright © 2007-2008 Intel® Corporation

All Rights Reserved.

World Wide Web: http://www.intel.com/

Page 2: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

2

Disclaimer and Legal Information

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL(R) PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR INTENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITUATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined." Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or by visiting Intel's Web Site (http://www.intel.com/).

Intel processor numbers are not a measure of performance. Processor numbers differentiate features within each processor family, not across different processor families. See http://www.intel.com/products/processor_number/ for details.

BunnyPeople, Celeron, Celeron Inside, Centrino, Centrino Atom, Centrino Atom Inside, Centrino Inside, Centrino logo, Core Inside, FlashFile, i960, InstantIP, Intel, Intel logo, Intel386, Intel486, IntelDX2, IntelDX4, IntelSX2, Intel Atom, Intel Atom Inside, Intel Core, Intel Inside, Intel Inside logo, Intel. Leap ahead., Intel. Leap ahead. logo, Intel NetBurst, Intel NetMerge, Intel NetStructure, Intel SingleDriver, Intel SpeedStep, Intel StrataFlash, Intel Viiv, Intel vPro, Intel XScale, Itanium, Itanium Inside, MCS, MMX, Oplus, OverDrive, PDCharm, Pentium, Pentium Inside, skoool, Sound Mark, The Journey Inside, Viiv Inside, vPro Inside, VTune, Xeon, and Xeon Inside are trademarks of Intel Corporation in the U.S. and other countries.

* Other names and brands may be claimed as the property of others.

Copyright © 2007-2008, Intel Corporation. All rights reserved.

Page 3: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Windows* OS Compatibility

Usage Guide 3

Contents 1 Windows* OS Compatibility ................................................................................4

1.1 System Requirements .............................................................................4 1.2 Usage Model..........................................................................................4

1.2.1 Library Accessibility ...................................................................4 1.2.2 Using Microsoft Visual Studio ......................................................5 1.2.3 Simple Examples.......................................................................5 1.2.4 Complex Examples ....................................................................7 1.2.5 Usage Limitations......................................................................8

1.3 Intel Extension Routines..........................................................................9 1.4 Intel OpenMP Libraries ............................................................................9 1.5 Known Issues ......................................................................................10

1.5.1 Threadprivate Objects..............................................................10 1.5.2 Critical Constructs ...................................................................10

2 Linux* OS Compatibility...................................................................................12 2.1 System Requirements ...........................................................................12 2.2 Usage Model........................................................................................12

2.2.1 Library Accessibility .................................................................13 2.2.2 Simple Examples.....................................................................13 2.2.3 Complex Examples ..................................................................14 2.2.4 Usage Limitations....................................................................15

2.3 Intel Extension Routines........................................................................16 2.4 Intel OpenMP Libraries ..........................................................................16 2.5 Known Issues ......................................................................................17

2.5.1 Threadprivate Objects..............................................................17 2.5.2 Critical Constructs ...................................................................17

3 Mac OS* X Compatibility ..................................................................................18 3.1 System Requirements ...........................................................................18 3.2 Usage Model........................................................................................18

3.2.1 Library Accessibility .................................................................18 3.2.2 Simple Examples.....................................................................19 3.2.3 Complex Examples ..................................................................20 3.2.4 Usage Limitations....................................................................20

3.3 Intel Extension Routines........................................................................21 3.4 Intel OpenMP Libraries ..........................................................................21 3.5 Known Issues ......................................................................................22

3.5.1 Threadprivate Objects..............................................................22 3.5.2 Critical Constructs ...................................................................22

Page 4: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

4

1 Windows* OS Compatibility The Intel OpenMP* compatibility libraries for the Windows* operating system provide the ability to combine OpenMP object files compiled with the Microsoft* C/C++ compiler (cl) with OpenMP object files compiled with the Intel® C++ Compiler (icl) or the Intel® Fortran Compiler (ifort) on systems running the Microsoft Windows* operating systems. The linking phase results in a single, coherent copy of the run-time library.

The legacy versions of the Intel OpenMP libraries do not support compatibility with compilers other than those released by Intel but are included to provide compatibility with previous versions of the Intel Compilers.

1.1 System Requirements The Intel OpenMP compatibility libraries are included with the Intel® C++ Compiler and Intel® Fortran Compiler, version 10.1. The Microsoft* compiler used must support OpenMP; the Intel OpenMP compatibility libraries are compatible with Microsoft Visual Studio 2005* for C/C++. Compatibility with future versions of Microsoft Visual Studio will be announced once new compilers are released.

1.2 Usage Model The 10.1 Intel compilers support a new option: /Qopenmp-lib. During the link phase, the /Qopenmp-lib:compat option causes the compiler to use one of the compatibility

OpenMP* run-time libraries that provide compatibility with object files created by the Microsoft C/C++ compiler. The default setting, /Qopenmp-lib:legacy, causes the compiler to use one of the legacy OpenMP* run-time libraries that do not provide compatibility with object files created by the Microsoft C/C++ compiler.

Most of the examples and sample commands included in this section illustrate usage of the Intel® C++ Compiler. In most cases, the Intel® Fortran Compiler usage is similar.

1.2.1 Library Accessibility The libiomp5md.lib (or libiomp5mt.lib) library must be accessible to the compiler or linker during the linking stage, and the libiomp5md.dll library must be accessible

to the application during execution. The simplest method to make these accessible is

Page 5: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Windows* OS Compatibility

Usage Guide 5

to run the batch files provided with the Intel compilers. The batch files set the environment to make these libraries accessible during the appropriate stages.

• Intel® C++ Compiler: iclvars.bat

• Intel® Fortran Compiler: ifortvars.bat

If only the Microsoft Visual C++ Compiler* is used then the library may be accessed by setting the appropriate environment variables manually; for example:

C:\> set LIB=%LIB%;<Intel_compiler_installation_path>\IA32\LIB C:\> set PATH=%PATH%;<Intel_compiler_installation_path>\IA32\BIN

The Microsoft C/C++ compiler enables OpenMP code by using the /openmp option; the Intel compilers enable OpenMP code with the /Qopenmp option. During C/C++ compilation, you must insure the Microsoft version of omp.h is used when compiling with the Microsoft C/C++ compiler, and that the Intel version of omp.h is used when

compiling with the Intel C/C++ compiler.

1.2.2 Using Microsoft Visual Studio You can also make the necessary settings in the Visual C++ 2005 Development Environment*; for example, setting the project Property Pages to indicate the Intel OpenMP Run-time Library (RTL) location. Open the project’s property pages in from the main menu: Project > Properties. Then select Configuration Properties > Linker > General > Additional Library Directories and enter something like the following:

<Intel_compiler_installation_path>\IA32\LIB

To make the Intel OpenMP dynamic RTL accessible at run-time, you must specify the corresponding path; for example, select Configuration Properties > Debugging > Environment, and enter something like the following:

PATH=%PATH%;<Intel_compiler_installation_path>\IA32\Bin

Finally, add the Intel OpenMP RTL name to the linker options and exclude the default Microsoft OpenMP RTL by selecting Configuration Properties > Linker > Command Line > Additional Options, and enter something like the following:

libiomp5md.lib /nodefaultlib:vcomp

1.2.3 Simple Examples The cl commands in all examples can be issued in separate environment with settings for the Microsoft Compiler (with the additions described in Library Accessibility when needed). The icl commands should use environment settings for the Intel Compilers.

Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler

Page 6: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

6

Documentation for more information about setting the environment: http://www.intel.com/software/products/compilers/.

While it is possible to use the Microsoft Compiler in the environment settings for Intel compilers to link with an Intel OpenMP compatibility library, you should avoid doing so because of possible name conflicts and other potential problems. For example, both compilers have an omp.h header file; by default the Intel Compiler will use the header provided in the Intel compiler.

Add the /I compiler option to use the native Microsoft header file from the Microsoft

Compiler if using the Intel compiler environment settings:

C:\> cl /MD /Qopenmp /I <VSINSTALLDIR>\VC\Include hello.c /link libiomp5md.lib /nodefaultlib:vcomp

Build using Intel® C++ Compiler

This example illustrates how to use the Intel OpenMP compatibility library with the Intel Compiler:

C:\> icl /MD /Qopenmp /Qopenmp-lib:compat hello.c

Build using Microsoft Compiler

When using Microsoft compiler, you should link with the Intel OpenMP compatibility library and avoid linking the Microsoft OpenMP run-time library (vcomp):

C:\> cl /MD /openmp hello.c /link /nodefaultlib:vcomp libiomp5md.lib

Build using Intel® C++ Compiler with Static Intel OpenMP Library

While it is not recommended, you can also use the static Intel OpenMP compatibility library:

C:\> icl /MT /Qopenmp /Qopenmp-lib:compat hello.c

Build using Microsoft Compiler with Static Intel OpenMP Library

Additionally, while it is not recommended, you can use the static Intel OpenMP compatibility library with the Microsoft compiler. You must redefine the _OMPIMP macro, which is used by the Microsoft compiler in the omp.h header file to declare

OpenMP run-time routines as imported from dynamic library. The following example illustrates how to add the static library:

C:\> cl /MT /openmp /D_OMPIMP= hello.c /link /nodefaultlib:vcomp libiomp5mt.lib

Page 7: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Windows* OS Compatibility

Usage Guide 7

1.2.4 Complex Examples Some applications can be linked using OpenMP object files even if they were compiled using different compilers; for example, the Microsoft Compiler (cl) and the Intel® C++ Compiler (icl).

Mix object files, Link using Intel® C++ Compiler

This example illustrates how to combine object files compiled by Intel compilers and Microsoft compilers and linked by the Intel® C++ Compiler with the OpenMP compatibility library:

C:\> cl /MD /openmp /c f1.c f2.c f3.c C:\> icl /MD /Qopenmp /Qopenmp-lib:compat /c f4.c f5.c f6.c C:\> icl /MD /Qopenmp /Qopenmp-lib:compat f1.obj f2.obj f3.obj f4.obj f5.obj f6.obj /Feapp /link /nodefaultlib:vcomp

The first command produces three object files compiled by Microsoft compiler. The second command produces three more object files compiled by Intel® C++ Compiler, The final command links all six object files into an application.

Mix object files, using Microsoft Linker

Alternately, you can use the linker instead of compiler at the linking stage:

C:\> link f1.obj f2.obj f3.obj f4.obj f5.obj f6.obj /out:app.exe /nodefaultlib:vcomp libiomp5md.lib

Mix object files, Link using Microsoft Compiler

This example illustrates how to combine object files compiled by the Intel compilers and Microsoft compilers and linked by the Microsoft Compiler with the dynamic Intel OpenMP compatibility library:

C:\> icl /MD /Qopenmp /Qopenmp-lib:compat /c f1.c f2.c f3.c C:\> cl /MD /openmp /c f4.c f5.c f6.c C:\> cl /MD /openmp f1.obj f2.obj f3.obj f4.obj f5.obj f6.obj /Feapp /link /nodefaultlib:vcomp libiomp5md.lib

The first command produces three object files compiled by the Intel® C++ Compiler. The second command produces three more object files compiled by Microsoft Compiler. The final command links all six object files into an application using the dynamic Intel OpenMP compatibility library.

Mix object files, Interprocedural Optimization, Link using Microsoft Compiler

This example illustrates how to combine object files compiled by Intel and Microsoft Compilers and linked by the Microsoft Compiler with the Intel OpenMP RTL while also using the Interprocedural Optimization (IPO) supported in the Intel compilers:

Page 8: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

8

C:\> icl /MD /Qopenmp /Qopenmp-lib:compat /O3 /Qipo /Qipo-c f1.c f2.c f3.c C:\> cl /MD /openmp /O2 /c f4.c f5.c f6.c C:\> cl /MD /openmp /O2 ipo_out.obj f4.obj f5.obj f6.obj /Feapp /link /nodefaultlib:vcomp libiomp5md.lib

The first command produces optimized multi-file object file compiled by Intel® C++ Compiler. (Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler Documentation to get more info about the /Qipo, /Qipo-c compiler options.) The second command produces three more object files compiled by Microsoft Compiler. The third command links all four object files into the application using the dynamic Intel OpenMP compatibility library.

Link using Microsoft Compiler with Intel static OpenMP run-time library

While it is not a recommended use case, the following example illustrates how to combine object files compiled by Intel compilers and Microsoft compilers and link them using the Microsoft Compiler with the static Intel OpenMP compatibility library:

C:\> icl /MT /Qopenmp /Qopenmp-lib:compat /c f1.c f2.c f3.c C:\> cl /MT /openmp /D_OMPIMP= /c f4.c f5.c f6.c C:\> cl /MT f1.obj f2.obj f3.obj f4.obj f5.obj f6.obj /Feapp /link /nodefaultlib:vcomp libiomp5mt.lib

The first command produces three object files compiled by the Intel® C++ Compiler. The second command produces three more object files compiled by Microsoft Compiler. The final command links all six object files into the application using the static Intel OpenMP compatibility library.

1.2.5 Usage Limitations Use only one OpenMP run-time library in an application. You can use either the Microsoft* OpenMP library or the dynamic or static (not recommended) Intel OpenMP compatibility library, but use only one. Mixing libraries will produce undesirable results. For example, if an executable uses one DLL linked with the Microsoft OpenMP run-time library and another DLL linked with the dynamic Intel OpenMP compatibility library, the results may be unpredictable. Similar unpredictable results may occur if two versions of the Intel OpenMP compatibility library are linked into the application (both static and dynamic).

The Intel OpenMP compatibility libraries are not compatible with object files created by versions of the Intel compiler earlier than 10.0. The Intel OpenMP legacy libraries are not compatible with OpenMP object files compiled by the Microsoft compilers.

Page 9: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Windows* OS Compatibility

Usage Guide 9

1.3 Intel Extension Routines The Intel Compilers provide a number of extension routines for use with OpenMP which are not part of the OpenMP Specifications. These extension routines begin with the prefix kmp_ and are not intended to be used with other compilers.

Compile code using the Intel extension routines only with Intel compilers. Compiling code using Intel extension routines with compilers other than Intel might result in undefined program behavior. Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler Documentation for the complete list of the extensions and more details about using the extension routines.

1.4 Intel OpenMP Libraries The following OpenMP compatibility libraries support both the Intel OpenMP compiled objects and Microsoft OpenMP compiled objects:

Library Associated DLL Description Compiler Options

libiomp5mt.lib none, static link static performance library

/MT /Qopenmp /Qopenmp-lib:compat

libiomp5md.lib libiomp5md.dll dynamic performance library and DLL

/MD /Qopenmp

/Qopenmp-lib:compat

libiompprof5mt.lib none, static link static profiling library

/MT /Qopenmp-profile

/Qopenmp-lib:compat

libiompprof5md.lib libiompprof5md.dll dynamic profiling library and DLL

/MD /Qopenmp-profile /Qopenmp-lib:compat

libiompstubs5mt.lib none, static link static stubs library

/MT /Qopenmp-stubs /Qopenmp-lib:compat

libiompstubs5md.lib libiompstubs5md.dll dynamic stubs library and DLL

/MD /Qopenmp-stubs

/Qopenmp-lib:compat

Page 10: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

10

The following OpenMP legacy libraries support only Intel OpenMP compiled objects.

Library Associated DLL Description Compiler Options

libguide.lib None, static link static performance library

/MT /Qopenmp

libguide40.lib libguide40.dll dynamic performance library and DLL

/MD /Qopenmp

libguide_stats.lib None, static link static profiling library

/MT /Qopenmp-profile

libguide40_stats.lib libguide40_stats.dll dynamic profiling library and DLL

/MD /Qopenmp-profile

libompstub.lib None, static link static stubs library

/MT /Qopenmp-stubs

libompstub40.lib libompstub40.dll dynamic stubs library and DLL

/MD /Qopenmp-stubs

1.5 Known Issues

1.5.1 Threadprivate Objects The Microsoft compiler uses a different mechanism than the Intel compilers to reference threadprivate data. If you declare a variable as threadprivate in your code and you compile the code with both Intel compilers and Microsoft compilers, the code compiled by the Intel compiler and the code compiled by the Microsoft compiler will reference different locations for the variable even when referenced by the same thread.

1.5.2 Critical Constructs Both the Microsoft compiler and the Intel compilers use common symbols to designate lock objects used in the OpenMP critical construct implementation. This mechanism

Page 11: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Windows* OS Compatibility

Usage Guide 11

provides mutual exclusion between different object files compiled by the Microsoft Compiler and the 10.1 version of the Intel compilers. On Windows, the same common symbol will indicate different objects in different compilation modules (for example, different DLLs, or in the executable and DLL it uses). Therefore, like-named (or unnamed) critical constructs will not provide mutual exclusion in different compilation modules, regardless of the compilers being used. This is the limitation of current implementation of OpenMP critical construct in both the Microsoft compilers and the Intel compilers.

Page 12: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

12

2 Linux* OS Compatibility The Intel OpenMP compatibility libraries for Linux operating systems provide the ability to combine OpenMP object files compiled with the GNU* C++ Compiler (gcc) or GNU* Fortran Compiler (gfortran) with OpenMP object files compiled with the Intel® C++ Compiler (icc/icpc) or the Intel® Fortran Compiler (ifort). The link stage

results in a single, coherent copy of the run-time library.

The legacy versions of the Intel OpenMP libraries do not support compatibility with compilers other than those released by Intel; they are included to provide compatibility with object files created using previous versions of the Intel Compilers.

Due to library dependencies, it is not possible to link objects compiled by the Intel® Fortran Compiler (ifort) with objects compiled by the GNU* Fortran compiler (gfortran); this is the case whether or not you use the –openmp option to compile the

application.

2.1 System Requirements The Intel OpenMP compatibility libraries are included with the Intel® C++ Compiler and Intel® Fortran Compiler, version 10.1. The GNU* compilers used must support OpenMP; the Intel OpenMP compatibility libraries are compatible with gcc and gfortran version 4.2. Compatibility with future versions of GNU* Compilers will be announced once those compilers are released.

2.2 Usage Model The 10.1 Intel compilers support a new option: -openmp-lib. During the link phase, the –openmp-lib compat option causes the compiler to use one of the compatibility

OpenMP* run-time libraries that provide compatibility with object files created by GNU* compilers. The default setting, –openmp-lib legacy, causes the compiler to use one of the legacy OpenMP* run-time libraries that do not provide compatibility with object files created by the GNU* compilers.

During the compilation phase, -openmp-lib legacy and –openmp-lib compat are equivalent.

Page 13: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Linux* OS Compatibility

Usage Guide 13

2.2.1 Library Accessibility Before using the Intel® C++ Compiler or the Intel® Fortran Compiler, you must configure the shell environment properly. The Intel compiler includes scripts to configure the environment correctly.

For the Intel® C++ Compiler, enter commands similar to the following:

$ . <icc_path>/iccvars.sh # sh, bash $ source <icc_path>/iccvars.csh # csh

For the Intel® Fortran Compiler, enter commands similar to the following:

$ . <ifort_path>/ifortvars.sh # sh, bash $ source <ifort_path>/ifortvars.csh # csh

Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler Documentation for more information.

The GNU* compilers enable OpenMP code by using the –fopenmp option; the Intel compilers enable OpenMP code with the –openmp option. During C/C++ compilation, you must insure the GNU* version of omp.h is used when compiling with the GNU* C/C++ compiler and that the Intel version of omp.h is used when compiling with the

Intel C/C++ compiler. During Fortran compilation, you must insure that the GNU* Fortran compiler uses the GNU* version of omp_lib.h or omp_lib.mod and that the Intel® Fortran Compiler uses the Intel version of omp_lib.h or omp_lib.mod.

GNU* compiler drivers do not look in the Intel compiler install locations. When using GNU* compilers you must also explicitly use the –L option to specify the path to the

OpenMP compatibility libraries (see examples below).

2.2.2 Simple Examples Build using Intel® Compiler

This example illustrates how to use the Intel OpenMP compatibility library with the Intel® C++ Compiler:

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

The following example shows the equivalent command for the Intel® Fortran Compiler:

$ ifort -openmp -openmp-lib compat hello.f

Compile using GNU* Compiler, Link using Intel® C++ Compiler

The simplest way to link OpenMP object files generated by the GNU* C compiler with the Intel OpenMP compatibility library is using the Intel® C++ Compiler as a linker:

Page 14: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

14

$ gcc –fopenmp –c foo.c $ icc –openmp –openmp–lib compat foo.o

C++ Build

When compiling C++ sources and linking C++ object files, use g++ and icpc instead of gcc and icc:

$ g++ –fopenmp –c foo.cpp $ icpc –openmp –openmp–lib compat foo.o

2.2.3 Complex Examples Build and link using GNU* Compiler

You can link with the GNU* compiler driver as long as the OpenMP compatibility library (libiomp) and the POSIX threads* libraries are specified explicitly on the command line. Omit the –fopenmp option when linking, which will prevent accidentally linking with the GNU* OpenMP library (libgomp). Since the GNU* compiler drivers will

not look in the Intel compiler install locations, you must also explicitly specify the path to the OpenMP compatibility library:

$ gcc –fopenmp –c foo.c bar.c $ gcc foo.o bar.o –liomp5 –lpthread –L<icc_dir>/lib

Mix Intel C and GNU* object files

You should use the Intel® C++ Compiler for linking:

$ gcc –fopenmp –c foo.c $ icc –openmp –c bar.c $ icc –openmp –openmp compat foo.o bar.o

Otherwise, you might need to explicitly link with libirc (and other Intel libraries), which is located in the same directory as the OpenMP compatibility library (libiomp):

$ gcc –fopenmp –c foo.c $ icc –openmp –c bar.c $ gcc foo.o bar.o –lirc –liomp5 –lpthread –L<icc_dir>/lib

Mix C and Intel® Fortran

OpenMP object files compiled with either the GNU* C++ Compiler (gcc) or the Intel® C++ Compiler (icc) can be linked with the Intel® Fortran Compiler, along with

objects compiled by it:

$ 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

Page 15: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Linux* OS Compatibility

Usage Guide 15

The main program must exist in a Fortran object file that is compiled by ifort, or the -nofor-main option must be specified to ifort at link time.

Mix C and GNU* Fortran

Similarly, object files compiled with either the Intel® C++ Compiler (icc) or GNU* C++ Compiler can be linked with the GNU* Fortran Compiler (gfortran), along with

objects compiled by the compiler.

You must specifically include the C library and possibly libirc. Do not use the –fopenmp option on the link line:

$ 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

Alternately, you can use the Intel® C++ Compiler to link OpenMP object files compiled with icc along with objects compiled by gfortran; however, you must

explicitly specify the GNU* Fortran libraries:

$ gfortran –fopenmp –c foo.f $ icc –openmp –c bar.c $ icc –openmp –openmp–lib compat foo.o bar.o –lgfortranbegin –lgfortran

For these last two scenarios, it is not necessary for the main program to exist in a Fortran object file.

2.2.4 Usage Limitations Use only one OpenMP run-time library in an application. Use either the GNU* OpenMP library or the dynamic or static (not recommended) Intel OpenMP compatibility library, but use only one. Mixing libraries will produce undesirable results. For example, if an executable uses one dynamic library linked with the GNU* OpenMP run-time library and another dynamic library linked with the dynamic Intel OpenMP compatibility library, the results may be unpredictable. Similar unpredictable results may occur if two versions of the Intel OpenMP compatibility library are linked into the application (both static and dynamic).

The Intel OpenMP compatibility libraries are not compatible with object files created by versions of the Intel compiler earlier than 10.0. The Intel OpenMP legacy libraries are not compatible with OpenMP object files compiled by the GNU* compilers.

Page 16: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

16

2.3 Intel Extension Routines The Intel Compilers provide a number of extension routines for use with OpenMP which are not part of the OpenMP Specifications. These extension routines begin with the prefix kmp_ and are not designed to be used with other compilers.

Compile code using the Intel extension routines only with Intel compilers. Compiling code using Intel extension routines with compilers other than Intel might result in undefined program behavior. Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler Documentation for the complete list of the extensions and more details about using the extension routines.

2.4 Intel OpenMP Libraries The following OpenMP compatibility libraries support both the Intel OpenMP compiled objects and GNU* OpenMP compiled objects:

Dynamic Library Static Library Description Compiler Options

libiomp5.so libiomp5.a performance libraries

-openmp

-openmp-lib compat

libiompprof5.so libiompprof5.a profiling libraries

-openmp-profile -openmp-lib compat

libiompstubs5.so libiompstubs5.a stubs libraries -openmp-stubs

-openmp-lib compat

The following OpenMP legacy libraries support only Intel OpenMP complied objects.

Dynamic Library Static Library Description Compiler Options

libguide.so libguide.a performance library

-openmp

libguide_stats.so libguide_stats.a profiling library

-openmp-profile

libompstub.so libompstub.a stubs library -openmp-stubs

Page 17: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Linux* OS Compatibility

Usage Guide 17

2.5 Known Issues

2.5.1 Threadprivate Objects The GNU* compilers use a different mechanism than the Intel compilers to reference threadprivate data. If you declare a variable as threadprivate in your code and you compile the code with both Intel compilers and GNU* compilers, the code compiled by the Intel compiler and the code compiled by the GNU* compiler will reference different locations for the variable even when referenced by the same thread.

2.5.2 Critical Constructs Critical construct names were changed, so like-named critical constructs do not provide mutual exclusion between objects compiled with the 10.1 versions of the Intel compilers and objects compiled with previous versions of the Intel® compilers. A limitation exists in the 9.1 and earlier Intel compilers, such that like-named critical constructs do not provide mutual exclusion between different object files. This limitation has been removed in the version 10.0 and 10.1 Intel compilers; therefore, like-named critical constructs provide mutual exclusion between different object files compiled by these Intel compilers and those compiled by GNU* compilers, under all scenarios.

Page 18: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

18

3 Mac OS* X Compatibility The Intel OpenMP* compatibility libraries for Mac OS* X operating systems provide the ability to combine OpenMP object files compiled with the GNU* C++ Compiler (gcc) with OpenMP object files compiled with the Intel® C++ Compiler (icc/icpc) or the Intel® Fortran Compiler (ifort). The link stage results in a single, coherent copy

of the run-time library.

The legacy versions of the Intel OpenMP libraries do not support compatibility with compilers other than those released by Intel but are included to provide compatibility with object files created using previous versions of the Intel Compilers.

3.1 System Requirements The Intel OpenMP compatibility libraries are included with the Intel® C++ Compiler and Intel® Fortran Compiler, version 10.1. The GNU* compiler used must support OpenMP; the Intel OpenMP compatibility libraries are compatible with gcc version 4.2. Compatibility with future versions of GNU* compilers will be announced once those compilers are released.

3.2 Usage Model The 10.1 Intel compilers support a new option: -openmp-lib. During the link phase, the –openmp-lib compat option causes the compiler to use one of the compatibility OpenMP* run-time libraries that provide compatibility with object files created by GNU* compiler. The default setting, –openmp-lib legacy, causes the compiler to use

one of the legacy OpenMP* run-time libraries that do not provide compatibility with object files created by the GNU* compiler.

During the compilation phase, -openmp-lib legacy and –openmp-lib compat are

equivalent.

3.2.1 Library Accessibility Before using the Intel® C++ Compiler or the Intel® Fortran Compiler, you must configure the shell environment properly. The Intel compiler includes scripts to configure the environment correctly.

Page 19: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Mac OS* X Compatibility

Usage Guide 19

For the Intel® C++ Compiler, enter commands similar to the following:

$ . <icc_path>/iccvars.sh # sh, bash $ source <icc_path>/iccvars.csh # csh

For the Intel® Fortran Compiler, enter commands similar to the following:

$ . <ifort_path>/ifortvars.sh # sh, bash $ source <ifort_path>/ifortvars.csh # csh

Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler Documentation for more information.

The GNU* compiler enables OpenMP code by using the –fopenmp option; the Intel compilers enable OpenMP code with the –openmp option. During C/C++ compilation, you must insure the GNU* version of omp.h is used when compiling with the GNU* C/C++ compiler, and that the Intel version of omp.h is used when compiling with the

Intel C/C++ compiler.

GNU* compiler drivers do not look in the Intel compiler install locations. When using GNU* compiler you must also explicitly use the –L option to specify the path to the

OpenMP compatibility libraries (see examples below).

3.2.2 Simple Examples Build using Intel® Compiler

This example illustrates how to use the Intel OpenMP compatibility library with the Intel C++ Compiler:

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

Compile using GNU* Compiler, link using Intel® C++ Compiler

The simplest way to link OpenMP object files generated by the GNU* C compiler (gcc) with the Intel OpenMP compatibility library is using the Intel® C++ Compiler (icc) as a linker:

$ gcc –fopenmp –c foo.c $ icc –openmp –openmp–lib compat foo.o

C++ Build

When compiling C++ sources and linking C++ object files, use g++ and icpc instead of gcc and icc:

$ g++ –fopenmp –c foo.cpp $ icpc –openmp –openmp–lib compat foo.o

Page 20: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

20

3.2.3 Complex Examples Build and link using GNU* Compiler

You can link with the GNU* compiler driver as long as the OpenMP compatibility library (libiomp) and the POSIX threads* libraries are specified explicitly on the command line. Omit the –fopenmp option when linking, which will prevent accidentally linking with the GNU* OpenMP library (libgomp). Since the GNU* compiler drivers will

not look in the Intel compiler install locations, you must also explicitly specify the path to the OpenMP compatibility library:

$ gcc –fopenmp –c foo.c bar.c $ gcc foo.o bar.o –liomp5 –lpthread –L<icc_dir>/lib

Mix Intel C and GNU* object files

You should use the Intel® C++ Compiler for linking:

$ gcc –fopenmp –c foo.c $ icc –openmp –c bar.c $ icc –openmp –openmp compat foo.o bar.o

Otherwise, you might need to explicitly link with libirc (and other Intel libraries), which is located in the same directory as the OpenMP compatibility library (libiomp):

$ gcc –fopenmp –c foo.c $ icc –openmp –c bar.c $ gcc foo.o bar.o –lirc –liomp5 –lpthread –L<icc_dir>/lib

3.2.4 Usage Limitations Use only one OpenMP run-time library in an application. Use either the GNU* OpenMP library or the dynamic or static (not recommended) Intel OpenMP compatibility library, but use only one. Mixing libraries will produce undesirable results. For example, if an executable uses one dynamic library linked with the GNU* OpenMP run-time library and another dynamic library linked with the dynamic Intel OpenMP compatibility library, the results may be unpredictable. Similar unpredictable results may occur if two versions of the Intel OpenMP compatibility library are linked into the application (both static and dynamic).

The Intel OpenMP compatibility libraries are not compatible with object files created by versions of the Intel compiler earlier than 10.0. The Intel OpenMP legacy libraries are not compatible with OpenMP object files compiled by the GNU* compilers.

Page 21: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Mac OS* X Compatibility

Usage Guide 21

3.3 Intel Extension Routines The Intel Compilers provide a number of extension routines for use with OpenMP which are not part of the OpenMP Specifications. These extension routines begin with the prefix kmp_ and are not designed to be used with other compilers.

Compile code using the Intel extension routines only with Intel compilers. Compiling code using Intel extension routines with compilers other than Intel might result in undefined program behavior. Refer to the Intel® C++ Compiler Documentation or the Intel® Fortran Compiler Documentation for the complete list of the extensions and more details about using the extension routines.

3.4 Intel OpenMP Libraries The following OpenMP compatibility libraries support both the Intel OpenMP compiled objects and GNU* OpenMP compiled objects:

Dynamic Library Static Library Description Compiler Options

libiomp5.dylib libiomp5.a performance libraries

-openmp -openmp-lib compat

libiompprof5.dylib libiompprof5.a profiling libraries

-openmp-profile

-openmp-lib compat

libiompstubs5.dylib libiompstubs5.a stubs libraries

-openmp-stubs

-openmp-lib compat

The following OpenMP legacy libraries support only Intel OpenMP complied objects.

Dynamic Library Static Library Description Compiler Options

libguide.dylib libguide.a performance library

-openmp

libguide_stats.dylib libguide_stats.a profiling library

-openmp-profile

libompstub.dylib libompstub.a stubs library -openmp-stubs

Page 22: Intel® OpenMP* Compatibility Libraries › ... › m › d › 4 › 1 › d › 8 › 345900_openmp_c… · The Microsoft C/C++ compiler enables OpenMP code by using the /openmp

Intel® OpenMP* Compatibility Libraries

22

3.5 Known Issues

3.5.1 Threadprivate Objects Currently available versions of gcc do not support the standard mechanism used to support threadprivate data. Threadprivate data objects will only be accessible by name from object files compiled by the Intel compilers.

3.5.2 Critical Constructs Critical construct names were changed, so like-named critical constructs do not provide mutual exclusion between objects compiled with the 10.1 versions of the Intel compilers and objects compiled with previous versions of the Intel® compilers. A limitation exists in the 9.1 and earlier Intel compilers, such that like-named critical constructs do not provide mutual exclusion between different object files. This limitation has been removed in the version 10.0 and 10.1 Intel compilers; therefore, like-named critical constructs provide mutual exclusion between different object files compiled by these Intel compilers and those compiled by GNU* compilers, under all scenarios.