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

Support for non-rectangular loop nest collapse

m_vdb
Novice
357 Views

Hi! One of the new features in OpenMP 5.0 is the collapse of non-rectangular loop nests (as e.g. mentioned in this OpenMP API examples book , page 35). Unless I've overlooked it, the "OpenMP 5.0/5.1" table in Intel's OpenMP feature overview page doesn't tell in which ifx version (if any) this has been implemented.

The example below suggests that indeed no ifx versions (or ifort versions for that matter) support this feature. To some extent this is not a problem in itself (assuming it will get implemented in the future?). What is a bit more problematic is that little to no warning or error is emitted at compile time, leading to wrong/unexpected runtime behavior. Only the memory sanitizer in ifx >= 2022.2.1 (when enabled with "-check all") hints that something might be off ("WARNING: MemorySanitizer: use-of-uninitialized-value").

program test
implicit none

integer :: i, j
integer, parameter :: n = 2
integer, dimension(n, n) :: mat

mat = 0

#ifdef _COLLAPSE
!$omp parallel do default(private), shared(mat), collapse(2)
#else
!$omp parallel do default(private), shared(mat)
#endif
do i = 1, n
#ifdef _NONRECTANGULAR
    do j = 1, i-1
        mat(j, i) = 1
    end do
#else
    do j = 1, n
        if (j < i) then
            mat(j, i) = 1
        end if
    end do
#endif
end do
!$omp end parallel do

! The output should be "0           0           1           0"
print *, mat

end program test

All ifort versions I tried (ranging from 2021.6.0 to the latest 2021.13.0) and all ifx versions I tried (ranging from 2022.1.0 to the latest 2024.2.0) compile the code with "-D_COLLAPSE -D_NONRECTANGULAR -qopenmp" options but the output of the resulting program is wrong("0 0 0 0" with ifort and "1 0 1 0" with ifx), also in the case of a single OpenMP thread. When dropping one or more of these options, the correct output is recovered.

Labels (1)
0 Kudos
0 Replies
Reply