Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29228 Discussions

Unexpected behavior for OpenMP collapse clause

chrisdaley
Beginner
745 Views
Hi all,

Could someone please confirm whether I have found a compiler bug for
the OpenMP collapse clause?

I have attached two test programs that use the OpenMP collapse clause
to divide iterations from two loops. I find that the OpenMP collapse
clause works as I expect when the loop limits are hard-coded values
(see program value_limits.F90), but not when I use loop limits that
are determined from an array (see program array_limits.F90) -- the
array containing the loop limits is shared, but is not modified within
the nested loops. When I run the affected program array_limits.F90
the number of executed loop iterations is undefined -- sometimes it is
1 iteration and sometimes it seems to tend to infinity. A subset of
the code from the affected program array_limits.F90 is shown below:

limits(1) = 1
limits(2) = 3
!$omp parallel default(none) private(i,j) shared(limits)
!$omp do collapse(2) schedule(static)
do j = limits(1),limits(2)
do i = limits(1),limits(2)
print *, 'Thread', omp_get_thread_num(), " of", &
omp_get_num_threads(), " has i", i, " and j", j
end do
end do
!$omp end do
!$omp end parallel


I have been using an x86_64 version of Intel compiler version 12.0.2
with Linux Kernel 2.6.18-194.el5.

The attachments are: value_limits.F90, array_limits.F90, Makefile,
README.

Thanks for any feedback,
Chris

0 Kudos
2 Replies
TimP
Honored Contributor III
745 Views
My own experience agrees with yours, that the collapse is reliable only for the case where the outer loop count is known at compile time. Thanks for submitting a test case; maybe this can get some attention.
0 Kudos
rreis
New Contributor I
745 Views
It works fine with gfortran... I mean, it worked.
0 Kudos
Reply