- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page