- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This simple program gives a wrong result if compiled with ifx (version 2025.3, but also with previous versions):
program cx
implicit none
complex, allocatable, dimension(:,:) :: a
integer :: i,n
n=2
allocate (a(-1:1,n))
a(0,:)=Cmplx(0,1)
a(-1,:)=Cmplx(4,5)
a(1,:)=Cmplx(2,3)
do i=1,n
write(*,*)i,a(0,i)
end do
end program cx$ ./cx
1 (4.000000,5.000000)
2 (4.000000,5.000000)instead of the expected result (0,1), obtained with ifort and gfortran.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Running the code in debug mode leads to correct results. The problem occurs in release mode, probably due to the code optimization...
I'm using version 2025.3.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good catch! As @MarcGrodent noted it is optimization related: the bug shows up at /O2 and /O3 but not /O1.
Dumping the whole array shows that a(0,:) is treated as a(-1,:), both in the assignment and the elementwise write: the contents of a(0,:) when printing the whole array can contain (0,0) or uninitialized garbage values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This loop optimizer bug is still in the latest compiler builds. I have escalated it to be fixed.
LLVM bisect tool points to the hir-post-vec-complete-unroll optimization pass, causing the problem. Note that with O1 results are correct. Looks like a full unrolling has a bug. I also tried to disable it, but then values are set to zero, which is also not correct.
$ ifx -O2 -fno-unroll-loops test.f90
$ ./a.out
1 (0.0000000E+00,0.0000000E+00)
2 (0.0000000E+00,0.0000000E+00)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page