Introduction to OpenMP

Professor Norm Matloff
University of California, Davis


What it is:

OpenMP is a set of C/C++ pragmas (or FORTRAN equivalents) which provide the programmer a high-level front-end interface which get translated as calls to threads (or other similar entities). The key phrase here is "higher-level"; the goal is to better enable the programmer to "think parallel," alleviating him/her of the burden and distraction of dealing with setting up and coordinating threads. For example, the OpenMP directive

#pragma omp critical

makes the C/C++ block which follows (as defined by a pair of braces) a critical section. Only one thread will be allowed into this block at a time, but without the programmer having to insert lock/unlock operations. As another example, the directive

#pragma omp for

result in the iterations of the C/C++ for loop which follows being automatically assigned out to the various threads, again without the programmer having to assign the threads directly.

A preprocessor translates the pragmas, after which an ordinary C/C++ compiler does the actual compilation.

Various language constructs for shared-memory programming have been developed in the past. Most have been vendor-specific. OpenMP is a cross-platform standard which has become quite popular.

OpenMP examples, tutorials and specs:

How to obtain it:

Various compilers, both open-source and commercial, are available.

I have been using the open-source Omni, which you can get at the Omni home page. I have brief tutorial on Omni. Another nice one is OMPi; see my brief tutorial.

Another open-source OpenMP compiler is OdinMP.