Tutorials | Exercises | Abstracts | LC Workshops | Comments | Search | Privacy & Legal Notice


OpenMP

Table of Contents

  1. Abstract
  2. Introduction
    1. What is OpenMP?
    2. History
    3. Goals of OpenMP
  3. OpenMP Programming Model
  4. OpenMP Directives
    1. Fortran Directive Format
    2. C/C++ Directive Format
    3. Directive Scoping
    4. PARALLEL Construct
    5. Work-Sharing Constructs
      1. DO / for Directive
      2. SECTIONS Directive
      3. SINGLE Directive
    6. Combined Parallel Work-Sharing Constructs
      1. PARALLEL DO / parallel for Directive
      2. PARALLEL SECTIONS Directive
    7. Synchronization Constructs
      1. MASTER Directive
      2. CRITICAL Directive
      3. BARRIER Directive
      4. ATOMIC Directive
      5. FLUSH Directive
      6. ORDERED Directive
    8. THREADPRIVATE Directive
    9. Data Scope Attribute Clauses
      1. PRIVATE Clause
      2. SHARED Clause
      3. DEFAULT Clause
      4. FIRSTPRIVATE Clause
      5. LASTPRIVATE Clause
      6. COPYIN Clause
      7. REDUCTION Clause
    10. Clauses / Directives Summary
    11. Directive Binding and Nesting Rules
  5. Run-Time Library Routines
    1. OMP_SET_NUM_THREADS
    2. OMP_GET_NUM_THREADS
    3. OMP_GET_MAX_THREADS
    4. OMP_GET_THREAD_NUM
    5. OMP_GET_NUM_PROCS
    6. OMP_IN_PARALLEL
    7. OMP_SET_DYNAMIC
    8. OMP_GET_DYNAMIC
    9. OMP_SET_NESTED
    10. OMP_GET_NESTED
    11. OMP_INIT_LOCK
    12. OMP_DESTROY_LOCK
    13. OMP_SET_LOCK
    14. OMP_UNSET_LOCK
    15. OMP_TEST_LOCK
    16. OMP_GET_WTIME
    17. OMP_GET_WTICK
  6. Environment Variables
  7. Memory and Performance Issues
  8. LLNL Specific Information and Recommendations
  9. References and More Information
  10. Exercise


Abstract


OpenMP is an Application Program Interface (API), jointly defined by a group of major computer hardware and software vendors. OpenMP provides a portable, scalable model for developers of shared memory parallel applications. The API supports C/C++ and Fortran on multiple architectures, including UNIX & Windows NT. This tutorial covers most of the major features of OpenMP, including its various constructs and directives for specifying parallel regions, work sharing, synchronization and data environment. Runtime library functions and environment variables are also covered. This tutorial includes both C and Fortran example codes and a lab exercise.

Level/Prerequisites: Geared to those who are new to parallel programming with OpenMP. Basic understanding of parallel programming in C or Fortran assumed. For those who are unfamiliar with Parallel Programming in general, the material covered in EC3500: Introduction to Parallel Computing would be helpful.



Introduction

What is OpenMP?

OpenMP Is:

OpenMP Is Not:


History

Ancient History More Recent History

Documentation Release History


Goals of OpenMP

Standardization: Lean and Mean:

Ease of Use:

Portability:



OpenMP Programming Model


Shared Memory, Thread Based Parallelism:

Explicit Parallelism:

Fork - Join Model:

Compiler Directive Based:

Nested Parallelism Support:

Dynamic Threads:

I/O:

FLUSH Often?:



Example OpenMP Code Structure



OpenMP Directives

Fortran Directives Format

Format: (case insensitive)

Example:

Fixed Form Source:

Free Form Source:

General Rules:

OpenMP Directives

C / C++ Directives Format

Format:

Example:

General Rules:



OpenMP Directives

Directive Scoping

Do we do this now...or do it later? Oh well, let's get it over with early...

Static (Lexical) Extent:

Orphaned Directive:

Dynamic Extent:

Example:

Why Is This Important?



OpenMP Directives

PARALLEL Region Construct

Purpose:

Format:

Notes:

How Many Threads?

Dynamic Threads:

Nested Parallel Regions:

Clauses:

Restrictions:


Example: Parallel Region



OpenMP Directives

Work-Sharing Constructs

Types of Work-Sharing Constructs:

Restrictions:



OpenMP Directives

Work-Sharing Constructs
DO / for Directive

Purpose:

Format:

Clauses:

Restrictions:


Example: DO / for Directive



OpenMP Directives

Work-Sharing Constructs
SECTIONS Directive

Purpose:

Format:

Clauses:

Questions:

Restrictions:


Example: SECTIONS Directive



OpenMP Directives

Work-Sharing Constructs
SINGLE Directive

Purpose:

Format:

Clauses:

Restrictions:



OpenMP Directives

Combined Parallel Work-Sharing Constructs
PARALLEL DO / parallel for Directive



OpenMP Directives

Combined Parallel Work-Sharing Constructs
PARALLEL SECTIONS Directive

Purpose:

Format:

Clauses:



OpenMP Directives

Synchronization Constructs



OpenMP Directives

Synchronization Constructs
MASTER Directive

Purpose:

Format:

Restrictions:



OpenMP Directives

Synchronization Constructs
CRITICAL Directive

Purpose:

Format:

Notes:

Restrictions:


Example: CRITICAL Construct



OpenMP Directives

Synchronization Constructs
BARRIER Directive

Purpose:

Format:

Restrictions:



OpenMP Directives

Synchronization Constructs
ATOMIC Directive

Purpose:

Format:

Restrictions:



OpenMP Directives

Synchronization Constructs
FLUSH Directive

Purpose:

Format:

Notes:



OpenMP Directives

Synchronization Constructs
ORDERED Directive

Purpose:

Format:

Restrictions:



OpenMP Directives

THREADPRIVATE Directive

Purpose:

Format:

Notes:

Restrictions:



OpenMP Directives

Data Scope Attribute Clauses


PRIVATE Clause

Purpose:

Format:

Notes:

Questions:


SHARED Clause

Purpose:

Format:

Notes:


DEFAULT Clause

Purpose:

Format:

Notes:

Restrictions:


FIRSTPRIVATE Clause

Purpose:

Format:

Notes:


LASTPRIVATE Clause

Purpose:

Format:

Notes:


COPYIN Clause

Purpose:

Format:

Notes:


REDUCTION Clause

Purpose:

Format:

Example: REDUCTION - Vector Dot Product:

Restrictions:



OpenMP Directives

Clauses / Directives Summary



OpenMP Directives

Directive Binding and Nesting Rules

Note This section is provided mainly as a quick reference on rules which govern OpenMP directives and binding. Users should consult their implementation documentation and the OpenMP standard for other rules and restrictions.

Directive Binding:

Directive Nesting:



Run-Time Library Routines


Overview:


OMP_SET_NUM_THREADS

Purpose:

Format:

Notes & Restrictions:


OMP_GET_NUM_THREADS

Purpose:

Format:

Notes & Restrictions:


OMP_GET_MAX_THREADS

Purpose:

Notes & Restrictions:


OMP_GET_THREAD_NUM

Purpose:

Format:

Notes & Restrictions:

Examples:


OMP_GET_NUM_PROCS

Purpose:

Format:


OMP_IN_PARALLEL

Purpose:

Format:

Notes & Restrictions:


OMP_SET_DYNAMIC

Purpose:

Format:

Notes & Restrictions:


OMP_GET_DYNAMIC

Purpose:

Format:

Notes & Restrictions:


OMP_SET_NESTED

Purpose:

Format:

Notes & Restrictions:


OMP_GET_NESTED

Purpose:

Format:

Notes & Restrictions:


OMP_INIT_LOCK

Purpose:

Format:

Notes & Restrictions:


OMP_DESTROY_LOCK

Purpose:

Format:

Notes & Restrictions:


OMP_SET_LOCK

Purpose:

Format:

Notes & Restrictions:


OMP_UNSET_LOCK

Purpose:

Format:

Notes & Restrictions:


OMP_TEST_LOCK

Purpose:

Format:

Notes & Restrictions:


OMP_GET_WTIME

Purpose:

Format:

Notes & Restrictions:


OMP_GET_WTICK

Purpose:

Format:

Notes & Restrictions:



Environment Variables



Memory and Performance Issues


Thread Stack Size:



LLNL Specific Information and Recommendations


LC OpenMP Implementations:

Compiling:

OpenMP 2.0 Compliant:

Documentation:


This completes the tutorial.

Evaluation Form       Please complete the online evaluation form - unless you are doing the exercise, in which case please complete it at the end of the exercise.

Where would you like to go now?



 
References and More Information


http://www.llnl.gov/computing/tutorials/openMP/
Last Modified: 08/16/2006 10:23:35 [email protected]
UCRL-MI-133316