While OpenMP is a decade-old set of extensions supported by virtually every compiler, it has become quite timely as we move to multi-core processors. You can use it todayno need to wait another decade for a new proposal to be available everywhere.
Abstraction for parallelism is very important so we can avoid coding in the world of POSIX threads (p-threads) and Windows threads. Our first consideration should go to OpenMP, an abstraction available in most compilers, on most systems, for C++ and Fortran.
The OpenMP specification (learn more at openmp.org) is now in version 2.5, which tidied up the document to make these extensions documented for C++ and Fortran in one common specification.
The heart of OpenMP is a set of compiler directives that extend C++ and Fortran to take advantage of shared memory parallelism. You add these directives as pragmas in C++, or special comments in Fortran. This means that compilers without support for OpenMP will simply ignore the directives and your program will compile and run as if you had done nothing. This backward compatibility is very useful.
When a compiler does support OpenMP, it will use the directives as hints from the programmer on when and how to exploit parallelism in the code it generates.
The OpenMP standard was formed by a number of companies that were all supporting some form of directives for parallelism and desired a standard for themselves and their customers. It was generally the compiler-writers at these companies who wanted to get together and make a standardand so they did.
OpenMP is focused on loop-level parallelism in the current standard. Intel has implemented extensions on OpenMP to allow for task-level parallelism, but these are not in the current OpenMP standardso portable use is limited to loop-level parallelism for now.
OpenMP can be used with threading libraries in the same program. Since OpenMP is easy to use on existing loops, this is the logical place to start when thinking of adding parallelism to your program.
While OpenMP is clearly designed for shared-memory machines, Intel recently introduced Cluster OpenMP as an optional add-on for their compilers. This will use the same directives (with a few optional extensions) to create code for clusters of processors that do not share memory. While it is true that you can write code in OpenMP with such fine-grained parallelism that this 'Cluster OpenMP' will not work, initial results from the team at Intel indicate it works well on quite a few programs.
I encourage you to take a look at OpenMP. This is an easy way to move many programs to parallelism and see your application performance improve as it takes advantage of multi-core processors.
You can find a C and a Fortran "Hello World" program with OpenMP on Wikipedia, or try the sample code below:
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp paralllel
{
printf( "Hello world from thread %d\n", omp_get_num_thread() );
}
}
Go aheadwrite a parallel "Hello, World" app today!