HOME
| OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"

5.2  threadprivate Directive

Name: threadprivate

Association: none

Category: declarative

Properties: default

Arguments

threadprivate(list)

Name

Type

Properties

list

list of variable list item type

default

Semantics

The threadprivate directive specifies that variables are replicated, with each thread having its own copy. Unless otherwise specified, each copy of a threadprivate variable is initialized once, in the manner specified by the program, but at an unspecified point in the program prior to the first reference to that copy. The storage of all copies of a threadprivate variable is freed according to how static variables are handled in the base language, but at an unspecified point in the program.

Each copy of a block-scope threadprivate variable that has a dynamic initializer is initialized the first time its thread encounters its definition; if its thread does not encounter its definition, its initialization is unspecified.

The content of a threadprivate variable can change across a task scheduling point if the executing thread switches to another task that modifies the variable. For more details on task scheduling, see Section 1.3 and Chapter 12.

In parallel regions, references by the primary thread are to the copy of the variable in the thread that encountered the parallel region.

During a sequential part, references are to the initial thread’s copy of the variable. The values of data in the initial thread’s copy of a threadprivate variable are guaranteed to persist between any two consecutive references to the variable in the program, provided that no teams construct that is not nested inside of a target construct is encountered between the references and that the initial thread is not executing code inside of a teams region. For initial threads that are executing code inside of a teams region, the values of data in the copies of a threadprivate variable of those initial threads are guaranteed to persist between any two consecutive references to the variable inside that teams region.

The values of data in the threadprivate variables of threads that are not initial threads are guaranteed to persist between two consecutive active parallel regions only if all of the following conditions hold:

If these conditions all hold, and if a threadprivate variable is referenced in both regions, then threads with the same thread number in their respective regions reference the same copy of that variable.

If the above conditions hold, the storage duration, lifetime, and value of a thread’s copy of a threadprivate variable that does not appear in any copyin clause on the corresponding construct of the second region spans the two consecutive active parallel regions. Otherwise, the storage duration, lifetime, and value of a thread’s copy of the variable in the second region is unspecified.
If the above conditions hold, the definition, association, or allocation status of a thread’s copy of a threadprivate variable or a variable in a threadprivate common block that is not affected by any copyin clause that appears on the corresponding construct of the second region (a variable is affected by a copyin clause if the variable appears in the copyin clause or it is in a common block that appears in the copyin clause) spans the two consecutive active parallel regions. Otherwise, the definition and association status of a thread’s copy of the variable in the second region are undefined, and the allocation status of an allocatable variable are implementation defined.

If a threadprivate variable or a variable in a threadprivate common block is not affected by any copyin clause that appears on the corresponding construct of the first parallel region in which it is referenced, the thread’s copy of the variable inherits the declared type parameter and the default parameter values from the original variable. The variable or any subobject of the variable is initially defined or undefined according to the following rules:

The order in which any constructors for different threadprivate variables of class type are called is unspecified. The order in which any destructors for different threadprivate variables of class type are called is unspecified.

Restrictions

Restrictions to the threadprivate directive are as follows:

Cross References