Parallel Programming in OpenMP

Multiple threads within an OpenMP parallel program execute within the same shared address space and can share access to variables within this address space. Sharing variables between threads makes interthread communication very simple: threads send data to other threads by assigning values to shared variables and receive data by reading values from them.
In addition to sharing access to variables, OpenMP also allows a variable to be designated as private to each thread rather than shared among all threads. Each thread then gets a private copy of this variable for the duration of the parallel construct. Private variables are used to facilitate computations whose results are different for different threads.
In this section we describe the data scope clauses in OpenMP that may be used to control the sharing behavior of individual program variables inside a parallel construct. Within an OpenMP construct, every variable that is used has a scope that is either shared or private (the other scope clauses are usually simple variations of these two basic scopes). This kind of "scope" is different from the "scope" of accessibility of variable names in serial programming languages (such as local, file-level, and global in C, or local and common in Fortran). For clarity, we will consistently use the term "lexical scope" when we intend the latter, serial programming language sense, and plain "scope" when referring to whether a variable is shared between OpenMP threads. In addition, "scope" is both a noun and a verb: every...