Hello everyone in Fortran-lang community. I met a problem allocating a large array and now ask for your help.
So I was testing a HPC node with 2TB memory, and I decided to use the following code memtest.f
to test its memory:
program memtest
integer(8) :: i, n, sizen, statt
real(8), allocatable:: array(:)
i=0_8
n=0_8
statt=0_8
write(*,*) "Memory testing started. status is ",statt
do while(statt .eq. 0_8)
i = i+10
n = i*1_8*1024_8**3_8/8_8
sizen = n*8_8/1024_8**3_8
allocate(array(n),stat=statt)
if(.not. allocated(array)) then
write(*,*)
&"Error! 1D Array of size ",sizen,"GB cannot be allocated."
exit
else
write(*,*)
&"Successfully allocated 1D array of size ",sizen ," GB"
deallocate(array, stat=statt)
end if
enddo
end program
and compile with
ifort memtest.f -o memtest.exe
execute memtest.exe
the output is:
...(truncated)
Successfully allocated 1D array of size 1930 GB
Successfully allocated 1D array of size 1940 GB
Successfully allocated 1D array of size 1950 GB
Successfully allocated 1D array of size 1960 GB
Error! 1D Array of size 1970 GB cannot be allocated.
so that’s expected.
However, with another compilation method, which is used in Makefiles,
ifort -c memtest.f
ifort memtest.o -o memtest.exe
I got
...(truncated)
Successfully allocated 1D array of size 930 GB
Successfully allocated 1D array of size 940 GB
Successfully allocated 1D array of size 950 GB
forrtl: severe (174): SIGSEGV, segmentation fault occurred
I’m new to Fortran and static compilation, so I really don’t know how to use Makefiles, etc. Does anybody know the difference between:
- directly compile a file,
- compile to objects and link them later
and how to avoid this pitfall?
EDIT:
After testing I found that both compilation methods is OK(Don’t know how did it not work).
But with -qopenmp
flag, the error occurs.