You can make named global-lifetime objects private to a thread, but global within the thread, by using the threadprivate directive.
Each thread gets its own copy of the object with the result that data written to the object by one thread is not directly visible to other threads. During serial portions and master sections of the program, accesses are to the master thread copy of the object.
You cannot use a thread private variable in any clause other than the following:
copyin
copyprivate
schedule
num_threads
if
In the following example the variable, counter, is specified as thread private:
Example |
---|
int counter = 0; #pragma omp threadprivate(counter); |
Copyright © 1996-2011, Intel Corporation. All rights reserved.