Hide Forgot
I ran into a weird problem today that I haven't been able to reproduce with a test program. The problem is that the construct #pragma omp parallel for schedule(dynamic) for(size_t i=0;i<N;i++) for(size_t j=0;j<=i;j++) { compiles just fine, but when I try to collapse the loops with #pragma omp parallel for schedule(dynamic) collapse(2) for(size_t i=0;i<N;i++) for(size_t j=0;j<=i;j++) { I get the cryptic error message In file included from /usr/lib/gcc/x86_64-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/basic_ios.h:39:0, from /usr/lib/gcc/x86_64-redhat-linux/4.6.0/../../../../include/c++/4.6.0/ios:45, from /usr/lib/gcc/x86_64-redhat-linux/4.6.0/../../../../include/c++/4.6.0/istream:40, from /usr/lib/gcc/x86_64-redhat-linux/4.6.0/../../../../include/c++/4.6.0/sstream:39, from /builddir/build/BUILD/erkale/src/basis.cpp:25: /builddir/build/BUILD/erkale/src/basis.cpp: In function '<built-in>': /builddir/build/BUILD/erkale/src/basis.cpp:1570:3: warning: 'i' is used uninitialized in this function [-Wuninitialized] /builddir/build/BUILD/erkale/src/basis.cpp:1570:14: note: 'i' was declared here /builddir/build/BUILD/erkale/src/basis.cpp: In function '<built-in>': /builddir/build/BUILD/erkale/src/basis.cpp:1517:3: warning: 'i' is used uninitialized in this function [-Wuninitialized] /builddir/build/BUILD/erkale/src/basis.cpp:1513:10: note: 'i' was declared here and the compiled code produces an incorrect result. What I find furthermore odd is that I can't reproduce the error with preprocessed source, so I won't attach the source files. The full source is at http://code.google.com/p/erkale/source/detail?r=226 and both loops cause the same error. However, to make things easier for you, I've supplied an SRPM which contains everything you need, including the %check phase which fails when the compiler produces odd things. http://theory.physics.helsinki.fi/~jzlehtol/collapse/erkale-0.1.0-5.20110921.226svn.fc15.src.rpm The same issue is present both with gcc-4.6.0-10.fc15.x86_64 and gcc-4.6.1-9.fc15.x86_64 .
The second snippet is not valid OpenMP 3.0+. E.g. in OpenMP 3.0, see 2.5.1, where test-expr is var relational-expr b or b relational-expr var and b must be loop invariant. In your case i isn't loop invariant.
Great, thanks!