[Omp] CTOR/DTOR invocation for variables in empty parallel directives?

Diego Novillo dnovillo at redhat.com
Tue Nov 1 13:48:01 PST 2005


Suppose that I have the following program:

----------------------------------------------------------------------
int g1, g2;
struct A
{
  A() { x = 0; g1++; }
  ~A() { g2++; }
  int x;
};

int
main ()
{
  A a;
#pragma omp parallel private (a)
  {
  }
#ifdef _OPENMP
  return !(g1 == 2 && g2 == 1);
#else
  return !(g1 == 1 && g2 == 0);
#endif
}
----------------------------------------------------------------------

Since the parallel directive is completely empty, is the compiler allowed 
to elide it?  If so, this would mean that the destructor for 'a' would not 
be invoked before the return from main.

In 2.8.3.3, p74, l8, the standard says "... This allocation occurs once 
for each thread in the team that references the list item in any statement 
in the the construct.".

This seems to imply that the compiler is free to remove the empty parallel 
body.


Thanks.




More information about the Omp mailing list