I'm trying to process a spatial dataset which is stored as a regular X, Y and Z coordinate grid with each location having multiple fields storing the attributes. However, when allocating the array to store the data, it throws an error.
Currently working with gcc gfortran version 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project) on Win10.
I've tried different machines (in case I'm hitting hardware limits) and looked at various compiler options, but have no managed to affect the result.
This is a simplified example with real limits for the current dataset for processing:
program test_array
implicit none
real*8, allocatable :: test(:,:,:,:)
integer*4 x,y,z,vars
x=382
y=390
z=362
vars=15
print *, "Total bytes: ", x*y*z*vars*8
allocate(test(x,y,z,vars))
print *, "Allocated"
deallocate(test)
print *, "Deallocated"
end program test_array
The program compiles just fine, but upon execution returns the following error:
Total bytes: -2118243392
Fortran runtime error: Integer overflow when calculating the amount of memory to allocate
Error termination. Backtrace:
Could not print backtrace: libbacktrace could not find executable to open
#0 0x41ad93
#1 0x413fee
#2 0x411d50
#3 0x401807
#4 0x4019dd
#5 0x40138a
Clearly I'm exceeding the 32-bit integer limit, but as I'm on a x64 system and (as far as I can tell) the compiler is a 64-bit version, I don't understand why I'm hitting a 32-bit limit. Hence, I've investigated compiler switches to force all integers to INTEGER*8 to no avail.
Is it possible to get round this limit, and if so, how?
Problem solved!
Upon searching about on my various install DIRs I came across three other installs that all include a version of gfortran.exe. Needless to say, these were being called preferentially to the most recently installed MinGW compiler suite. Once these redundant versions were removed the test program and the production tool both compiled and executed without issue (memory allocation up to around 6.5 Gb for this particular model).
Many thanks to those who commented and helped to point me in the right direction.
i686-posix-dwarf-rev0is a 32-bit arch. So it's probably making 32-bit code by default. Check your output file type, e.g. withfile foo.exe. If you were building 32-bit executables (where obviously array sizes are limited to 32-bit), try-m64to build 64-bit code. Or if there's a native MinGW-w64 build of gfortran use that.