1

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.

6
  • 1
    i686-posix-dwarf-rev0 is a 32-bit arch. So it's probably making 32-bit code by default. Check your output file type, e.g. with file foo.exe. If you were building 32-bit executables (where obviously array sizes are limited to 32-bit), try -m64 to build 64-bit code. Or if there's a native MinGW-w64 build of gfortran use that. Commented Jul 18, 2019 at 1:38
  • 2
    You will need to install the x86-64-posix-seh toolchain which has a 64-bit gfortran. The i686 one is strictly 32-bit. Commented Jul 18, 2019 at 2:10
  • Many thanks, gents. While persisting with a fix I forced the path to the install DIR and the damned thing worked just fine. Apparently I'm calling an old version (hidden who knows where) rather than the most recent install. Will provide an update when I pin down the cause. Commented Jul 18, 2019 at 2:11
  • 2
    I know it's not directly related to your question, but I strongly suggest you stop using the completely non-standard real*8 syntax and similar and start using the kind mechanism - we have had questions here where the former was not supported, while the later always will Commented Jul 18, 2019 at 7:50
  • 1
    Please do not put any Solved! [Solved] or anything similar to the question title. You can write an answer and later accept it. Everyone can see that the question has an answer or even an accepted answer. Commented Jul 18, 2019 at 8:03

1 Answer 1

1

The issue above was due to multiple instances of the gfortran.exe compiler being installed as parts of other packages, such as Strawberry Perl, and solved by calling the correct compiler directly to demonstrate the 64 bit compiler produced a working program.

Discovering the -v switch for the compiler allows the install path to be displayed along with other environment variable and version info. From here I could track down the unwanted EXEs and remove them and, if necessary, their outdated installed packages.

Validation of the resulting model, processed using the 64 bit compiler, confirmed that the program works as intended.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.