Threadprivate Static Class Member for C++ in OpenMP 3.0In OpenMP 3.0, static class member variables may appear in a threadprivate directive. See Section 2.9.2 on p. 81 of the Specification. Example (C++): #include <omp.h>
#include <stdio.h>
class A
{
public :
static int tp;
#pragma omp threadprivate(tp)
A() { printf("constructor\n"); }
~A() { printf("destructor\n"); };
};
int A::tp;
void test()
{
#pragma omp parallel
{
A::tp = omp_get_thread_num();
printf("tp = %i\n", A::tp);
}
}
int main()
{
omp_set_dynamic(0);
omp_set_num_threads(4);
test();
return 0;
}
% CC -xopenmp -xO3 test.cc
% a.out
tp = 0
tp = 2
tp = 3
tp = 1
|
OpenMP 3.0 Features in Express 7.08
|