Bug 740396 - Problem with collapsing OpenMP loops
Summary: Problem with collapsing OpenMP loops
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 15
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2011-09-21 21:29 UTC by Susi Lehtola
Modified: 2011-09-22 06:34 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2011-09-21 21:45:28 UTC

Attachments (Terms of Use)

Description Susi Lehtola 2011-09-21 21:29:57 UTC
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
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.


The same issue is present both with gcc-4.6.0-10.fc15.x86_64 and gcc-4.6.1-9.fc15.x86_64 .

Comment 1 Jakub Jelinek 2011-09-21 21:45:28 UTC
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.

Comment 2 Susi Lehtola 2011-09-22 06:34:25 UTC
Great, thanks!

Note You need to log in before you can comment on or make changes to this bug.