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

Tian, Xinmin xinmin.tian at intel.com
Tue Nov 1 14:15:22 PST 2005


If users have this type of code, the performance may not be a big
concern for users. In general, users can always use lower optimization
(O0 or Od), so the compiler can still generate threaded code for empty
parallel region by not being smart to remove it. 

Xinmin Tian (for OpenMP ARB)

-----Original Message-----
From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On Behalf
Of Diego Novillo
Sent: Tuesday, November 01, 2005 1:48 PM
To: omp at openmp.org
Subject: [Omp] CTOR/DTOR invocation for variables in empty
paralleldirectives?


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.

_______________________________________________
Omp mailing list
Omp at openmp.org
http://openmp.org/mailman/listinfo/omp_openmp.org




More information about the Omp mailing list