Hi,
This small piece of code do not compiles with nvfortran:
program coll
use iso_c_binding
implicit none
integer(c_int), dimension(:,:), allocatable:: tab
integer :: nx,ny
integer(kind=8) ::tmax
integer :: lemax,lemin,i,j
nx=(huge(nx) -1) /2
ny=3
allocate(tab(nx,ny))
write(6,'(2(a,i0))') "tab is ",size(tab,1)," x ",size(-tab,2)
tmax=sizeof(tab)
write(6,'(a,i0)') 'sizeof(tab) is ',tmax
write(6,'(a,i0)') 'c_sizeof(tab) is ',c_sizeof(tab)
end program coll
The error is:
NVFORTRAN-S-0004-Illegal argument: must be interoperable with a C type (collapse.f90: 20)
- tested with nvhpc/24.3 and nvhpc/24.7
- works with gfortran 14 and Cray cce17
I know sizeof()
intrinsic works but it is not part of the fortran standart and I need to ensure some portability of my code. Moreover on Cray compilers the sizeof intrinsic returns only integer*4 values, so not working with large arrays (but again sizeof is not part of fortran standart so I do not intend to use it)
Thanks
Hi Patrick,
Thanks for the report. Assumed shape arrays should be allowed for c_sizeof, and if I change the code to pass “tab(:,:)” instead of “tab”, then nvfortran compiles it correctly. Though I think “tab” by itself should work as well so I added a problem report, TPR#36752, and sent it to engineering for intestigation.
The work around works with gfortran 14.2 as well, so might be a good temporary fix. For example:
% cat test.F90
program coll
use iso_c_binding
implicit none
integer(c_int), dimension(:,:), allocatable:: tab
integer :: nx,ny
integer(kind=8) ::tmax
integer :: lemax,lemin,i,j
nx=(huge(nx) -1) /2
ny=3
allocate(tab(nx,ny))
write(6,'(2(a,i0))') "tab is ",size(tab,1)," x ",size(-tab,2)
tmax=sizeof(tab)
write(6,'(a,i0)') 'sizeof(tab) is ',tmax
#ifdef WORKS
write(6,'(a,i0)') 'c_sizeof(tab) is ',c_sizeof(tab(:,:))
#else
write(6,'(a,i0)') 'c_sizeof(tab) is ',c_sizeof(tab)
#endif
end program coll
% nvfortran test.F90
NVFORTRAN-S-0004-Illegal argument: must be interoperable with a C type (test.F90: 21)
0 inform, 0 warnings, 1 severes, 0 fatal for coll
% nvfortran -DWORKS test.F90
% a.out
tab is 1073741823 x 3
sizeof(tab) is 12884901876
c_sizeof(tab) is 12884901876
% gfortran --version
GNU Fortran (GCC) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% gfortran test.F90
% a.out
tab is 1073741823 x 3
sizeof(tab) is 12884901876
c_sizeof(tab) is 12884901876
% gfortran -DWORKS test.F90
% a.out
tab is 1073741823 x 3
sizeof(tab) is 12884901876
c_sizeof(tab) is 12884901876
-Mat
1 Like