Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
11 Views

Strange memory issue

Dear Intel forum users:

I've stumbled upon a very *strange* issue (don't know how else to describe it) where with certain optimizations an array gets filled with bogus data.

I have tried to produce a minimal example, but in the end the example is still pretty large because it only happens under quite specific circumstances. The issue does not occur with "-O1" or less, or with "-O2" and without openmp. The (unused!) threadprivate variable is important. It is also important that the module is in a separate file. It also matters that ndim is not hardcoded but passed as a variable.

testcase.f90:

program main
      use test
      implicit none

      double precision :: msq(10,-5:5,-5:5,5,2)
      msq = 0d0
      call fillmsq(10, msq)
end program

test.f90:

module test
      implicit none

      public

      contains

      subroutine fillmsq(ndim, msq)
          implicit none
          integer, save :: blub
!$omp threadprivate(blub)

          integer, intent(in) :: ndim
          double precision, intent(inout) :: msq(ndim,-5:5,-5:5,5,2)

          integer :: j,k,l,m,n


          do j=1,ndim; do k=-5,5; do l=-5,5; do m=1,5; do n=1,2
              if (msq(j,k,l,m,n) /= 0d0) then
                  write (*,*) "BEFORE", j,k,l,m,n, msq(j,k,l,m,n)
              endif
          enddo; enddo; enddo; enddo; enddo

          msq(1, 5, [1,2,3,4], 1, 1) = [1d0,1d0,1d0,1d0]

          do j=1,ndim; do k=-5,5; do l=-5,5; do m=1,5; do n=1,2
              if (msq(j,k,l,m,n) /= 0d0) then
                  write (*,*) "AFTER", j,k,l,m,n, msq(j,k,l,m,n)
              endif
          enddo; enddo; enddo; enddo; enddo

      end subroutine

end module

 

% ifort -O1 -fopenmp -o test test.f90 testcase.f90 && ./test
 AFTER           1           5          -4           1           1
   1.0000000000000

Sometimes other entries get filled with additional garbage.

Good output:

% ifort -O1 -fopenmp -o test test.f90 testcase.f90 && ./test
 AFTER           1           5           1           1           1
   1.00000000000000     
 AFTER           1           5           2           1           1
   1.00000000000000     
 AFTER           1           5           3           1           1
   1.00000000000000     
 AFTER           1           5           4           1           1
   1.00000000000000

If it matters, this was tested with Linux ifort 19.0.5.281 and 19.0.2.187

 

Thanks,

Tobias

0 Kudos
4 Replies
Highlighted
Beginner
11 Views

Sorry, but I'm bumping this from the second page to first! Could someone try to reproduce this, so this can be either reported as a bug or as some stupidity of mine?
0 Kudos
Highlighted
11 Views

IVF 2020, MS VS 2019, Win 7, x64 platform

Debug build no OpenMP

 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

Release build, no OpenMP

 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

Debug with OpenMP

 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

Release with OpenMP

 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

Release with OpenMP, custom optimization, /O1

 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

Using older version:

Intel® Parallel Studio XE 2019 Update 3 Composer Edition for Fortran Windows* Integration for Microsoft Visual Studio* 2013,
Version 19.0.0051.12, Copyright © 2002-2019 Intel Corporation. All rights reserved.

OpenMP, Release, Custom, /O1

 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

This appears to work as intended.

Not sure why Intel PS XE update 3 shows Version 19.0.0051.12

Jim Dempsey

0 Kudos
Highlighted
11 Views

Note, original code did not have a parallel region prior to test. IVF 19u3 Release with:

program main
        use omp_lib
      use test
      implicit none

      double precision :: msq(10,-5:5,-5:5,5,2)
      !$omp parallel
      !$omp master
      print *,"omp_get_num_threads()",omp_get_num_threads()
      !$omp end master
      !$omp end parallel
      msq = 0d0
      call fillmsq(10, msq)
end program

 omp_get_num_threads()           8
 AFTER           1           5           1           1           1
   1.00000000000000
 AFTER           1           5           2           1           1
   1.00000000000000
 AFTER           1           5           3           1           1
   1.00000000000000
 AFTER           1           5           4           1           1
   1.00000000000000
Press any key to continue . . .

Not sure what your problem is.

Jim Dempsey

0 Kudos
Highlighted
Beginner
11 Views

Neither am I, but this points more towards Linux systems now? (I have tested this on two Linux systems with the above mentioned ifort versions)
0 Kudos