- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've found this baffling behavior with the ifx version 2024.0.2 when compiling with -O2 or higher:
! With `m = 0d0`, the matrix does not actually get zeroed when
! compiling with -O2! With `m(:,:) = 0d0`, it does.
m = 0.0D0
do i = 1, npnt
m(1, 1) = m(1, 1) + xyz1(1, i) * xyz2(1, i)
m(2, 1) = m(2, 1) + xyz1(2, i) * xyz2(1, i)
m(3, 1) = m(3, 1) + xyz1(3, i) * xyz2(1, i)
m(1, 2) = m(1, 2) + xyz1(1, i) * xyz2(2, i)
m(2, 2) = m(2, 2) + xyz1(2, i) * xyz2(2, i)
m(3, 2) = m(3, 2) + xyz1(3, i) * xyz2(2, i)
m(1, 3) = m(1, 3) + xyz1(1, i) * xyz2(3, i)
m(2, 3) = m(2, 3) + xyz1(2, i) * xyz2(3, i)
m(3, 3) = m(3, 3) + xyz1(3, i) * xyz2(3, i)
enddo
print *, m(2, 2)
I'm zeroing the matrix before adding to it, yet the output of the print at the bottom suggests that it wasn't actually initialized. The problem goes away if I say m(:,
The code above is just a snippet, and it takes some some additional code both before and after the snippet to make the issue visible. I simplified my function as much as I could (less than 50 lines), and set up this demo on the compiler explorer, where you can see two versions of the code side-by-side, only differing in how m gets initialized, and how they produce different results. In my example, where I call the function three times in a row with the same inputs, the print produces this output, which suggests that m is not getting zeroed, but instead is accumulating over different calls:
0.500000000000000
1.00000000000000
1.50000000000000
Using m(:,
Either I'm going crazy or this is a bug in the compiler; please let me know.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This issue is fixed in the next IFX release 2024.2

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