Hello,
I realize this is not the most recent version of the NVHPC Toolkit, but it is the latest version supported by the NERSC Perlmutter cluster.
I have this simple program that does a selection sort over 4 elements:
program main
implicit none
real(8) :: e(4), etmp
integer :: i, j, k
e(1) = 2.000000000000000
e(2) = 3.000000000000000
e(3) = 1.000000000000000
e(4) = 2.000000000000000
! Initial array is unsorted.
write(*,'(1x,a,2x,4(f16.13,1x))') 'e_before_sort=',e(1),e(2),e(3),e(4)
! Sort the 4-element array e.
do i=1, 3
k = i
do j=i+1, 4
if(e(k) > e(j)) then
k = j
end if
end do
if (i /= k) then
!switch e(i) and e(k)
etmp = e(i)
e(i) = e(k)
e(k) = etmp
end if
end do
! Are they sorted?
write(*,'(1x,a,2x,4(f16.13,1x))') 'e_after_sort=',e(1),e(2),e(3),e(4)
do i=2,4
if (e(i-1) > e(i)) then
write(*,*) 'FAIL: out of order at index ', i
end if
end do
end program main
If I compile the program like this, it behaves correctly (note: vectorization disabled):
$ nvfortran main.f90 -o main -fast -Mnovect
$ ./main
e_before_sort= 2.0000000000000 3.0000000000000 1.0000000000000 2.0000000000000
e_after_sort= 1.0000000000000 2.0000000000000 2.0000000000000 3.0000000000000
However, if I compile the program like this (vectorization enabled), it fails:
$ nvfortran main.f90 -o main -fast
$ ./main
e_before_sort= 2.0000000000000 3.0000000000000 1.0000000000000 2.0000000000000
e_after_sort= 2.0000000000000 1.0000000000000 2.0000000000000 3.0000000000000
FAIL: out of order at index 2
I am mainly reporting this as a potential bug, but also if you have any suggestions then I would be grateful to hear them.