Bug 34517 - INCOROUT: C++ OpenMP lastprivate
Summary: INCOROUT: C++ OpenMP lastprivate
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-18 06:06 UTC by Li-Juan.Hai
Modified: 2007-12-18 11:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
C++ OpenMP testcase (290 bytes, text/plain)
2007-12-18 06:07 UTC, Li-Juan.Hai
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Li-Juan.Hai 2007-12-18 06:06:26 UTC
testcase b.C attached to show the problem. "a.ai += addnum" refers to distinct objects therefore a.ai finally equals to 7 rather than 28 (now it is!) when reaching printf.

micro# g++ b.C -fopenmp
micro# ./a.out
constructor
constructor
constructor
constructor
constructor
ai: 28  exp: 7  af: 28.000000  exp: 7
micro# g++ -v
Using built-in specs.
Target: sparc-sun-solaris2.10
Configured with: /import/dr2/starlex/orig/trunk/configure --prefix=/import/dr3/s10/gcc-4.3/ --enable-languages=c,c++,fortran --disable-gnattools --with-mpfr=/ws/gccfss/tools --with-gmp=/ws/gccfss/tools
Thread model: posix
gcc version 4.3.0 20070912 (experimental) (GCC)
Comment 1 Li-Juan.Hai 2007-12-18 06:07:48 UTC
Created attachment 14789 [details]
C++ OpenMP testcase
Comment 2 Jakub Jelinek 2007-12-18 11:39:41 UTC
IMHO it can validly print 7, 14, 21 or 28.  See OpenMP 2.5, section 2.5.2:
"The method of scheduling the structured blocks among threads in the team is implementation defined."
Also, data sharing clause is sections construct clause rather than section
directive clause, so no matter how many section directives you have, the
constructor/destructor will be called as many times as there are threads in the team.  GCC schedules the first not yet processed #pragma omp section block
to the first available thread, doesn't do assign different blocks to different
threads no matter whether they are available or not.  So, if e.g. one (typically master) thread is available some time before all other threads and there isn't
really any significant work to do in the block, so it finishes almost instantly,
it might very well win the next section block as well, because other threads are
still being set up.