HOME
| OPENMP API Specification: Version 5.0 November 2018

2.19.2  threadprivate Directive

SummaryThe threadprivate directive specifies that variables are replicated, with each thread having its own copy. The threadprivate directive is a declarative directive.

Syntax

SVG-Viewer needed.

The syntax of the threadprivate directive is as follows:  

 
#pragma omp threadprivate(list) new-line  

where list is a comma-separated list of file-scope, namespace-scope, or static block-scope variables that do not have incomplete types.

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the threadprivate directive is as follows:  

 
!$omp threadprivate(list)  

where list is a comma-separated list of named variables and named common blocks. Common block names must appear between slashes.

SVG-Viewer needed.

DescriptionEach 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.

A program in which a thread references another thread’s copy of a threadprivate variable is non-conforming.

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 on page 52 and Section 2.10 on page 384.

In parallel regions, references by the master thread will be to the copy of the variable in the thread that encountered the parallel region.

During a sequential part references will be 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 nested inside of a teams region. For initial threads nested 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 of 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 will reference the same copy of that variable.

SVG-Viewer needed.

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 second region will be retained. Otherwise, the storage duration, lifetime, and value of a thread’s copy of the variable in the second region is unspecified.

SVG-Viewer needed.

SVG-Viewer needed.

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 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) will be retained. 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 will be 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 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:

SVG-Viewer needed.

SVG-Viewer needed.

The address of a threadprivate variable is not an address constant.

SVG-Viewer needed.

SVG-Viewer needed.

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.

SVG-Viewer needed.

RestrictionsThe restrictions to the threadprivate directive are as follows:

SVG-Viewer needed.

SVG-Viewer needed.

Cross References