Sun Studio 12: C User's Guide

B.2.118 -xopenmp[=i]

Use the -xopenmp option to enable explicit parallelization with OpenMP directives. To run a parallelized program in a multithreaded environment, you must set the OMP_NUM_THREADS environment variable prior to execution.

To enable nested parallelism, you must set the OMP_NESTED environment variable to TRUE. Nested parallelism is disabled by default.

The following table lists the values for i:

Table B–33 The -xopenmp Flags

Value 

Meaning  

parallel

Enables recognition of OpenMP pragmas. The optimization level under -xopenmp=parallel is -x03. The compiler changes the optimization level to-x03 if necessary and issues a warning.

This flag also defines the preprocessor token _OPENMP.

noopt

Enables recognition of OpenMP pragmas. The compiler does not raise the optimization level if it is lower than -O3. 

If you explicitly set the optimization lower than -O3, as in cc -O2 -xopenmp=noopt, the compiler issues an error. If you do not specify an optimization level with -xopenmp=noopt, the OpenMP pragmas are recognized, the program is parallelized accordingly, but no optimization is done.

This flag also defines the preprocessor token _OPENMP.

none

This flag is the default and disables recognition of OpenMP pragmas, makes no change to the optimization level of your program, and does not predefine any preprocessor tokens. 

If you specify -xopenmp, but do not include a value, the compiler assumes -xopenmp=parallel. If you do not specify -xopenmp, the compiler assumes -xopenmp=none.

If you are debugging an OpenMP program with dbx, compile with -g and -xopenmp=noopt so you can breakpoint within parallel regions and display the contents of variables.


Note –

Do not specify -xopenmp, with either -xexplicitpar, or -xparallel.


The default for -xopenmp might change in future releases. You can avoid warning messages by explicitly specifying an appropriate optimization.

If you use -xopenmp while building any .so, you must use -xopenmp when linking the executable, and the compiler of the executable must not be any older than the compiler that built the .so with -xopenmp. This is especially important when you compile libraries that contain OpenMP directives. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A–2.

Make sure that the latest patch of the OpenMP runtime library, libmtsk.so, is installed on the system for best performance.

For more information that is specific to the C implementation of OpenMP, see 3.2 Parallelizing for OpenMP.

For information on OpenMP, see the Sun Studio 12: OpenMP API User’s Guide.