- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I've tried to use collapse(2) with non-rectangular bounds, as follows:
program main
implicit none
integer :: a, b
integer, parameter :: maxind = 5
!$OMP PARALLEL DO DEFAULT(NONE) &
!$OMP PRIVATE(a,b) &
!$OMP collapse(2) schedule(guided,4)
do a = 1, maxind
do b = a, maxind
call echo(a,b)
end do
end do
!$OMP END PARALLEL DO
end program main
subroutine echo(a,b)
integer, intent(in) :: a, b
print *, a, b
end subroutine echo
That is gives me incorrect output:
1 0
2 0
3 0
4 0
5 0
Instead of expected like:
1 1
1 2
1 3
1 4
1 5
2 2
...
However, when I tried to understand, what is going wrong, I found that GFortran cannot compile this example with the message:
See an example with GFortran compiler here:
https://godbolt.org/z/vxeWY5Ys9
After removing `schedule` OpenMP-statement, I got a proper answer for GFortran, but not for ifx. See here:
https://godbolt.org/z/vdds9bdYE
The same results I got with 2024.1
Igor
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I took out the schedule clause also. I am going to have to consult the OMP Standard to see if the COLLAPSE clause is allowed in this non-retangular case. NAG fortran produces a different output compared to all others. This has me thinking this OMP usage may be invalid
nagfor -openmp test.f90
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203
[NAG Fortran Compiler normal termination]
[rwgreen@jfel-clx-652853 devshare]$ ./a.out | sort
1 1
1 2
1 3
1 4
1 5
1 6
2 2
2 3
2 4
2 5
2 6
2 7
3 3
3 4
3 5
3 6
3 7
3 8
4 4
4 5
4 6
4 7
4 8
4 9
5 10
5 5
5 6
5 7
5 8
5 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
According to OpenMP 5.0 specification:
If a collapse clause is specified with a parameter value greater than 1, then the iterations of the associated loops to which the clause applies are collapsed into one larger iteration space that is then divided according to the schedule clause.
Looks like GFortran has a check for safe OpenMP sections with mixed collapse/schedule statements, while both NAG and Intel Fortran Frontend do not.
It is on beginning of page 103
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Agreed. We also reviewed the Spec and came to the same conclusion.
There is a bug report on this CMPLRLLVM-38149. I escalated that and got it moving along.
Our C++ compiler ICX handles this collapse correctly. So I created a C version of the code. This way we can see the LLVM IR generated correctly and it'll speed up the fix.
#include <stdio.h>
int main()
{
int a, b;
#pragma omp parallel for default(none) \
private( a,b ) \
collapse(2)
for ( a = 1; a < 6; a++) {
for (b = a; b < 6; b++) {
printf("%d %d \n ", a, b);
}
}
return 0;
}
icx -V -fiopenmp collapse.c && ./a.out | sort
Intel(R) oneAPI DPC++/C++ Compiler for applications running on Intel(R) 64, Version dev.x.0 Mainline Build 20241022
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
1 1
1 2
1 3
1 4
1 5
2 2
2 3
2 4
2 5
3 3
3 4
3 5
4 4
4 5
5 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The behaviour between 2024.1 and 2025.1 was changes.
ifx 2024.1 gives the following output:
$ ./ifx-2024.1 collapse2.f90 -fopenmp
$ ./a.out
1 0
5 0
2 0
3 0
4 0
and ifx 2025.1 gives the following output:
./ifx-2025.1 collapse2.f90 -fopenmp
./a.out
# nothing here
It would be nice to have errors by default for such cases to avoid wrongly written code.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page