Parallel Programming with OpenMP
One of the most important tools in the HPC programmer’s toolbox is OpenMP, a standard for expressing shared memory parallelism that was published in 1997. The current release, version 4.0, came out last November.
In a recent video, Oracle’s OpenMP committee representative Nawal Copty explores some of the tool’s features and common pitfalls.
Copty explains OpenMP simply as a way to write parallel programs, stating: “you start with your C, C++ or Fortran program and then insert directives in the code to specify to the compiler which parts of the code you want to parallelize.”
There are several advantages over using POSIX threads, according to Copty, such as being easy to learn and use. You don’t need to rewrite your application, just insert directives, an approach called incremental parallelization, where parallelism is added bit by bit. There are several types of parallelism supported by OpenMP, including parallel regions, parallel loops and tasking.
The latest version of OpenMP includes several new features, which Copty highlights. One of these is called region cancellation. This is a mechanism for the programmer to be able to cleanly terminate or abort the execution of a region if certain conditions occur. Another feature involves task dependencies, where the programmer can specify dependent actions. Another important feature is thread affinity. This lets a programmer specify that an application must run on certain processors and not move around while the application is executed.
Copty makes a final note for users to be aware some common pitfalls, including data races and data locks, which can cause incorrect results, hangups and crashes. Oracle Solaris has a tool called thread analyzer that can help pinpoint these conditions.
For those that are interested in the history of OpenMP, Intel showcased the nearly two-decade long OpenMP timeline in its latest issue of Parallel Computing Forum.