Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29299 Discussions

OpenMP parallel loop incorrect iteration distribution?

samlor
Beginner
396 Views
G'day All,
The simple program enclosed seems to indicate a problem in ifort OpenMP compilation of parallel DO loop work-sharing directives that distributes increasing numbers of iterations instead of spreading them evenly amongst threads when the loop index variable 'I' is re-used in later loop statements inside a SINGLE directive. The problem does not occur when the program is modified to use a different variable 'J' instead for the 2nd loop. Nor does this problem occur in equivalent C code.
Am I doing something wrong or is this a bug? And, where/how should it be reported?
Regards,
Sam
Code:
$ cat incorrect.f
      PROGRAM MAIN
      INTEGER I, J, OMP_GET_THREAD_NUM, OMP_GET_NUM_THREADS
!$OMP PARALLEL PRIVATE(I)
!$OMP DO
      do I=1,OMP_GET_NUM_THREADS()
        PRINT *, 'TID =', OMP_GET_THREAD_NUM(), 'I =', I
      enddo
!$OMP END DO
!$OMP BARRIER
!$OMP SINGLE
      do I=1,OMP_GET_NUM_THREADS()
        PRINT *, 'TID =', OMP_GET_THREAD_NUM(), 'I =', I
      enddo
!$OMP END SINGLE
!$OMP END PARALLEL
      END
$ cat correct.f
      PROGRAM MAIN
      INTEGER I, J, OMP_GET_THREAD_NUM, OMP_GET_NUM_THREADS
!$OMP PARALLEL PRIVATE(I)
!$OMP DO
      do I=1,OMP_GET_NUM_THREADS()
        PRINT *, 'TID =', OMP_GET_THREAD_NUM(), 'I =', I
      enddo
!$OMP END DO
!$OMP BARRIER
!$OMP SINGLE
      do J=1,OMP_GET_NUM_THREADS()
        PRINT *, 'TID =', OMP_GET_THREAD_NUM(), 'J =', J
      enddo
!$OMP END SINGLE
!$OMP END PARALLEL
      END
$ uname -a
Linux swan.ac3.com.au 2.4.21-sgi303r2 #1 SMP Mon Nov 29 15:29:38 PST 2004 ia64 i
a64 ia64 GNU/Linux
$ ifort -v
Version 9.0
$ ifort -openmp incorrect.f -o incorrect
incorrect.f(10) : (col. 6) remark: OpenMP DEFINED LOOP WAS PARALLELIZED.
incorrect.f(9) : (col. 6) remark: OpenMP DEFINED REGION WAS PARALLELIZED.
$ echo $OMP_NUM_THREADS
8
$ ./incorrect
 TID =           0 I =           1
 TID =           2 I =           1
 TID =           2 I =           2
 TID =           2 I =           3
 TID =           1 I =           1
 TID =           1 I =           2
 TID =           7 I =           1
 TID =           7 I =           2
 TID =           7 I =           3
 TID =           7 I =           4
 TID =           7 I =           5
 TID =           7 I =           6
 TID =           7 I =           7
 TID =           7 I =           8
 TID =           3 I =           1
 TID =           3 I =           2
 TID =           3 I =           3
 TID =           3 I =           4
 TID =           4 I =           1
 TID =           4 I =           2
 TID =           4 I =           3
 TID =           4 I =           4
 TID =           4 I =           5
 TID =           5 I =           1
 TID =           5 I =           2
 TID =           5 I =           3
 TID =           5 I =           4
 TID =           5 I =           5
 TID =           5 I =           6
 TID =           6 I =           1
 TID =           6 I =           2
 TID =           6 I =           3
 TID =           6 I =           4
 TID =           6 I =           5
 TID =           6 I =           6
 TID =           6 I =           7
 TID =           4 I =           1
 TID =           4 I =           2
 TID =           4 I =           3
 TID =           4 I =           4

 TID =           4 I =           5
 TID =           4 I =           6
 TID =           4 I =           7
 TID =           4 I =           8
$ ifort -openmp correct.f -o correct
correct.f(7) : (col. 6) remark: OpenMP DEFINED LOOP WAS PARALLELIZED.
correct.f(6) : (col. 6) remark: OpenMP DEFINED REGION WAS PARALLELIZED.
$ ./correct
 TID =           1 I =           2
 TID =           0 I =           1
 TID =           2 I =           3
 TID =           6 I =           7
 TID =           3 I =           4
 TID =           7 I =           8
 TID =           4 I =           5
 TID =           5 I =           6
 TID =           4 J =           1
 TID =           4 J =           2
 TID =           4 J =           3
 TID =           4 J =           4
 TID =           4 J =           5
 TID =           4 J =           6
 TID =           4 J =           7
 TID =           4 J =           8
$ 
0 Kudos
1 Reply
Steven_L_Intel1
Employee
396 Views
I'm not familiar with the issues so can't comment on your code, but one reports issues through Intel Premier Support. See this page to get started.
0 Kudos
Reply