c++ - How to use direct initialization of an object in OpenMP threadprivate directives? -
on this question 1 of answers cite following part of openmp standard:
a threadprivate variable class type must have:
- an accessible, unambiguous default constructor in case of default initialization without given initializer;
- an accessible, unambiguous constructor accepting given argument in case of direct initialization;
- an accessible, unambiguous copy constructor in case of copy initialization explicit initializer.
using (almost) same example on posted question, want is:
struct point2d{ int x; int y; point2d(){ x = 0; y = 0; } //copy constructor point2d(point2d& p){ x = p.x; y = p.y; } };
and declare 2 point
variables of type point2d
:
point2d global_point; point2d local_point(global_point); #pragma omp threadprivate(local_point)
i see on example used in question posted code failed due first item on cited part of openmp standard (as pointed in answer).
my question is, on case, how can use second point of openmp standard direct initialize private local_point
variables (all using global_point
)?
also, make sense or i've missed point in answer?
for reasons discussed in post linked, , compilers, can't either. guess whole point. missing feature, , compiler doesn't try hide it:
c3057: dynamic initialization of 'threadprivate' symbols not currently supported
what try achieve? trivial structure, can
const int gx = 3; const int gy = -2; point2d local_point = {gx, gx+gy}; #pragma omp threadprivate ( local_point )
but have stick const
fundamental types. if wanted initialize threadprivate
variable (must static
) inside function can use copyin
(it use third item, copy assignment, naturally)
void foo() { static point2d local_point; #pragma omp threadprivate( local_point ) local_point = global_point; #pragma omp parallel copyin( local_point ) { //
or better
{ point2d local_point( global_point ); #pragma omp parallel firstprivate( local_point ) { //
to break free restrictions.
Comments
Post a Comment