OpenMP Common Core

Making OpenMP simple again

The OpenMP Common Core

by Timothy G. Mattson, Yun (Helen) He, and Alice E. Koniges

This book resulted from 20+ years of teaching OpenMP with an active, programming-driven style. We focus on what we call the “Common Core” of OpenMP: the 21 OpenMP elements used in most OpenMP programs. For many OpenMP programmers, the Common Core is all they ever use.

This is not a book about OpenMP. This is a book for learning OpenMP. We take people with no experience in multithreading and turn them into capable parallel programmers. Once the common core is mastered, you can move into the more advanced corners of OpenMP with the book OpenMP: The Next Step.

Available now from MIT Press.

Code samples

We have created a github repository with code you can use as you work though our book. To create a copy of this repository, use the following command:

git clone

In addition to exercises and all the code that appears inside the book, this repository also includes a set of “challenge problems” that you can use to gain more experience with OpenMP.

Using Fortran?

For Fortran programmers, we’ve created a companion document, Fortran Supplement (ver. 1.2.1), which presents all the code from the Common Core book in Fortran instead of C. We hope this will let Fortran programmers extract maximum value from the book.


It is all but impossible to write a book free of errors. We know of only a few errors in our book. Most are insignificant … typos and maybe a race condition in one of the figures. Nothing that changes the actual content of the book. There is one error, however, that is serious enough to explain in detail. This occurs in section 6.4 pages 118 and 119. We state that you can use array sections


with the data environment clauses private, firstprivate, and reduction. The example provided on page 119 is

#pragma omp parallel firstprivate(vptr[0:1000:1])

This is incorrect. Array sections cannot be used with private and firstprivate. An array section can be used in a reduction clause, but only for a contiguous array section (i.e., not with a stride).


[:length] // assume lower-bound is zero

In the following example we point to an array and then designate a section of that array through the pointer in the reduction clause.

int C[4] = {0}; // create a block of memory and initialize it

int *vptr;

vptr = C; // set pointer to point to the block of memory,

#pragma omp parallel for reduction(+:vptr[1:2])

     // loop not shown

Referencing values outside the array section ([1:2]) inside the parallel loop is undefined. In the code above, we show use of an array section with a pointer. You can also use an array section with a static array (i.e., an array on the stack):

int C[4] = {0}; // create a block of memory and initialize it

#pragma omp parallel for reduction(+:C[1:2])

     // loop not shown