Zombie thread…REACTIVATE!
I seem to have re-encountered this bug. To wit, if you make a simple program:
program test
use, intrinsic :: iso_c_binding
implicit none
real, pointer :: ptr(:,:) => NULL()
real, pointer :: uin(:,:,:) => NULL()
integer, parameter :: nx = 4
integer, parameter :: ny = 5
integer :: i, j
allocate(ptr(nx,ny))
forall (i=1:nx,j=1:ny) ptr(i,j) = 10*i+j
write (*,*) 'shape(ptr): ', shape(ptr)
write (*,'(a,x,z32)') ' loc(ptr(1,1)): ', loc(ptr(1,1))
write (*,*) 'ptr: ', ptr
call c_f_pointer(c_loc(ptr(1,1)),uin,[nx,ny,1])
write (*,*) 'shape(uin): ', shape(uin)
write (*,'(a,x,z32)') ' loc(uin(1,1,1)): ', loc(uin(1,1,1))
write (*,*) 'uin: ', uin
deallocate(ptr)
end program test
Now we can run in Intel:
(1450) $ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.181 Build 20160204
Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
(1451) $ ifort test.F90
(1452) $ ./a.out
shape(ptr): 4 5
loc(ptr(1,1)): 6DE060
ptr: 11.00000 21.00000 31.00000 41.00000
12.00000 22.00000 32.00000 42.00000 13.00000
23.00000 33.00000 43.00000 14.00000 24.00000
34.00000 44.00000 15.00000 25.00000 35.00000
45.00000
shape(uin): 4 5 1
loc(uin(1,1,1)): 6DE060
uin: 11.00000 21.00000 31.00000 41.00000
12.00000 22.00000 32.00000 42.00000 13.00000
23.00000 33.00000 43.00000 14.00000 24.00000
34.00000 44.00000 15.00000 25.00000 35.00000
45.00000
In gfortran:
(1461) $ gfortran --version
GNU Fortran (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
(1462) $ gfortran test.F90
(1463) $ ./a.out
shape(ptr): 4 5
loc(ptr(1,1)): 605F80
ptr: 11.0000000 21.0000000 31.0000000 41.0000000 12.0000000 22.0000000 32.0000000 42.0000000 13.0000000 23.0000000 33.0000000 43.0000000 14.0000000 24.0000000 34.0000000 44.0000000 15.0000000 25.0000000 35.0000000 45.0000000
shape(uin): 4 5 1
loc(uin(1,1,1)): 605F80
uin: 11.0000000 21.0000000 31.0000000 41.0000000 12.0000000 22.0000000 32.0000000 42.0000000 13.0000000 23.0000000 33.0000000 43.0000000 14.0000000 24.0000000 34.0000000 44.0000000 15.0000000 25.0000000 35.0000000 45.0000000
And in good old nagfor (though I had to comment out the loc print):
(1470) $ nagfor -V
NAG Fortran Compiler Release 6.0(Hibiya) Build 1064
Product NPL6A60NA for x86-64 Linux
Copyright 1990-2015 The Numerical Algorithms Group Ltd., Oxford, U.K.
(1471) $ nagfor test.F90
NAG Fortran Compiler Release 6.0(Hibiya) Build 1064
[NAG Fortran Compiler normal termination]
(1472) $ ./a.out
shape(ptr): 4 5
ptr: 11.0000000 21.0000000 31.0000000 41.0000000 12.0000000 22.0000000 32.0000000 42.0000000 13.0000000 23.0000000 33.0000000 43.0000000 14.0000000 24.0000000 34.0000000 44.0000000 15.0000000 25.0000000 35.0000000 45.0000000
shape(uin): 4 5 1
uin: 11.0000000 21.0000000 31.0000000 41.0000000 12.0000000 22.0000000 32.0000000 42.0000000 13.0000000 23.0000000 33.0000000 43.0000000 14.0000000 24.0000000 34.0000000 44.0000000 15.0000000 25.0000000 35.0000000 45.0000000
But PGI:
(1480) $ pgfortran -V
pgfortran 16.3-0 64-bit target on x86-64 Linux -tp haswell
The Portland Group - PGI Compilers and Tools
Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
(1481) $ pgfortran test.F90
(1482) $ ./a.out
shape(ptr): 4 5
loc(ptr(1,1)): 606E60
ptr: 11.00000 21.00000 31.00000 41.00000
12.00000 22.00000 32.00000 42.00000
13.00000 23.00000 33.00000 43.00000
14.00000 24.00000 34.00000 44.00000
15.00000 25.00000 35.00000 45.00000
shape(uin): 4 5 1
loc(uin(1,1,1)): 41A8000041300000
Segmentation fault (core dumped)
So TPR#16064 has been regressed. I have access to some old compilers and PGI 11.10 likes it, as does 12.10, but PGI 13.10 does not. So somewhen in 2013, it got undone.
Note, that if you do the suggestion of doing:
cptr = c_loc(ptr(1,1))
call c_f_pointer(cptr,uin,[nx,ny,1])
then all works as expected. Huzzah!