NERSCPowering Scientific Discovery Since 1974

OpenMP Resources

What is OpenMP

OpenMP is an industry standard API of C/C++ and Fortran for shared memory parallel programming.  OpenMP Architecture Review Board (ARB) consists of major compiler vendors and many research institutions.  Common architectures include shared memory architecture (multiple CPUs shared global memory, uniform memory access (UMA), with typical shared memory programming model of OpenMP, Pthreads), distributed memory architecture (each CPU has own memory, non-uniform memory access ((NUMA), with typical message passing programming model of MPI), and hybrid architecture (UMA within one node or socket, NUMA across nodes or sockets, with typical hybrid programming model of hybrid MPI/OpenMP).  Current architecture trend needs a hybrid programming model with three levels of parallelism: MPI between nodes or sockets, shared memory (such as OpenMP) on the nodes/sockets, and increased vectorization for lower level loop structures. 

OpenMP has three components: Compiler directives and clauses, runtime libraries and environment variables. The compiler directives are only interpreted when OpenMP compiler option is turned on. OpenMP uses the "fork and join" execution model: Master thread forks new threads at the beginning of parallel regions; Multiple threads share work in parallel; And threads join at the end of parallel regions.

 

 

 

 

 

In OpenMP, all threads have access to the same shared global memory. Each thread has access to its private local memory.  Threads synchronize implicitly by reading and writing shared variables. No explicit communication is needed between threads. 

 

 

 

 

 

Major features in OpenMP 3.1 include:  

  • Thread creation with shared and private memory
  • Loop parallelism and work sharing constructs
  • Dynamic work scheduling
  • Explicit and implicit synchronizations 
  • Simple reductions 
  • Nested parallelism
  • OpenMP tasking

New features in OpenMP 4.0 (released in July 2013) include: 

  • Device constructs for accelerators
  • SIMD constructs for vectorization
  • Task groups and dependencies 
  • Thread affinity control
  • User defined reductions
  • Cancellation construct
  • Initial support for Fortran 2003
  • OMP_DISPLAY_ENV for all internal variables
More details of using OpenMP can be found in the OpenMP training and resources sections below. 
 

Relevant NERSC Trainings on OpenMP:

Below are a collection of some useful OpenMP resources and tutorials: