Hello, I am exploring a memory usage issue in a program. When I have a program like this:
module m_ptrsize
implicit none
public
type :: t1
integer :: i1
integer :: i2
end type
type :: t2
integer :: i1
integer :: i2
integer, pointer :: pi(:) => null()
end type
type :: t3
integer :: i1
integer :: i2
integer, pointer :: pi(:) => null()
real, pointer :: pr(:) => null()
end type
end module m_ptrsize
program ptrsize
use iso_c_binding
use m_ptrsize
implicit none
type(t1) :: arr1(5)
type(t2) :: arr2(5)
type(t3) :: arr3(5)
write(*,*) "arr1 elem size = ", int(storage_size(arr1(1))/8, kind=c_size_t)
write(*,*) "arr2 elem size = ", int(storage_size(arr2(1))/8, kind=c_size_t)
write(*,*) "arr3 elem size = ", int(storage_size(arr3(1))/8, kind=c_size_t)
end program ptrsize
Compiling this with nvfortran
produces this result:
$ nvfortran ptrsize.f90 -o ptrsize
$ ./ptrsize
arr1 elem size = 8
arr2 elem size = 152
arr3 elem size = 296
This suggests that nvfortran
’s internal representation of the pointer members are 144 bytes each.
The GNU gfortran
compiler does somewhat better, yielding these results indicating a 64-byte pointer size:
arr1 elem size = 8
arr2 elem size = 72
arr3 elem size = 136
I’m sure there is some metadata managed by the Fortran compiler to provide the appropriate array abstraction in the language, but we are working with very large arrays in our programs, and such overhead becomes a very serious issue for us.
Are there any compiler switches or other techniques I might use to reduce this pointer-size overhead?
Thanks in advance for any input you can provide.