The following self-contained reproducer code generates a Subscript out of range error that I believe is spurious, but that is also the likely cause of a segmentation violation in the full code from which this reproducer was reduced.
I am providing this in the form of a session log captured on a Linux (Sandybridge) workstation running Centos 7. The session first shows a listing of the code, then the output of two compiles and executions. First time is a success. Second time, compiled with -DBREAK, shows the out of range error. Note that the out of range error actually occurs prior to the loop that’s affected by #defining BREAK in the compile.
I have tested with another compiler and this reproducer code (and the code from which it’s reduced) both work correctly whether or not the second loop is $!omp parallel.
Thank you,
John
Script started on Tue 25 Feb 2020 01:41:07 PM MST
$ pgf90 -V
pgf90 19.10-0 LLVM 64-bit target on x86-64 Linux -tp sandybridge
PGI Compilers and Tools
Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
$ cat visckernel.F90
program visckernel
implicit none
! from mod_types
integer, parameter :: r8 = SELECTED_REAL_KIND(12)
integer ib, neblk
real(kind=r8), dimension(6,423440) :: rhs_visc_cgc
integer :: ngl, nglx, ngly, nglz, npts, nvar
! for epx
real(kind=r8),allocatable,dimension(:,:,:,:) :: erhs_visc_new ! (leblk, npts,nvar, neblk)
ngl = 4
nglx = 4
ngly = 4
nglz = 4
npts = 64
nvar = 6
neblk = 15288
allocate(erhs_visc_new (1,npts,nvar,neblk) )
write(0,*)__FILE__,__LINE__,size(erhs_visc_new)*8
write(0,*)__FILE__,__LINE__,shape(erhs_visc_new)
!$omp parallel do private(ib)
do ib = 1,1
call create_laplacian_ep3( erhs_visc_new(:,:,:,ib) )
enddo
#ifdef BREAK
!$omp parallel do
#endif
do ib = 1,1
call create_global_epx(erhs_visc_new)
enddo
contains
subroutine create_laplacian_ep3(rhs_visc )
implicit none
real(kind=r8) :: rhs_visc (:,:,:)
end subroutine create_laplacian_ep3
subroutine create_global_epx(rhs)
implicit none
real(kind=r8) :: rhs(:,:,:,:) ! (1,npts,nvar,neblk)
end subroutine create_global_epx
end program visckernel
$ pgf90 -mp -c -C -O0 -g -traceback visckernel.F90 -o visckernel.o
$ pgf90 -mp -traceback -C -O0 -g visckernel.o -o ./visckernel
$ ./visckernel
visckernel.F90 24 46964736
visckernel.F90 25 1 64 6
15288
$ pgf90 -mp -c -C -O0 -g -traceback -DBREAK visckernel.F90 -o visckernel.o
$ pgf90 -mp -traceback -C -O0 -g visckernel.o -o ./visckernel
$ ./visckernel
visckernel.F90 24 46964736
visckernel.F90 25 1 64 6
15288
0: Subscript out of range for array erhs_visc_new (visckernel.F90: 29)
subscript=1, lower bound=15288, upper bound=30575, dimension=1
$ exit
exit
Script done on Tue 25 Feb 2020 01:42:14 PM MST