5.6 OpenMP Support

The gcc and Oracle Solaris Studio compilers can look for OpenMP pragma directives in the source code in order to build a parallel version of the application. Similar to automatic parallelization, the compiler does the additional work so that you do not have to manage the threads. OpenMP represents an incremental approach to parallelization with potentially fine granularity. OpenMP allows you to set directives around specific loops to be optimized through threading while leaving other loops untouched. The advantage of this approach is that you can derive a serial version and a parallel version of the application from the same code, which can be helpful for debugging.

To instruct the gcc compiler to recognize OpenMP directives, specify the -fopenmp flag.

Several compiler flags are available in Oracle Solaris Studio to support OpenMP. To instruct the compiler to recognize OpenMP directives, specify the -xopenmp flag. You can also set the -xvpara flag to report potential parallelization issues, and the -loopinfo flag to display information about which loops are parallelized.

At run time, set the OMP_NUM_THREADS environment variable to specify the number of processors that are available to the program.