Pavel Ruzankin
Pavel Ruzankin

Reputation: 69

Array allocating problem in gfortran "Not enough space"

I try to run the following code on (a 64-bit) gfortran 14.2

program test1
   real, allocatable :: a(:), b(:,:)
   ! allocate( a(3870457856_8) )
   allocate( b(8000, 2000000) )
end program test1

and get the error: In file 'test4.f90', around line 5: Error allocating 3870457856 bytes: Not enough space. At the same time, if I uncomment the first allocate and comment the second one, the program runs with no errors. Using compiler option -mcmodel=large does not help.

I get the same issue with gcc 12. The problem seems somehow to deal with transition of addressing from integer(4) to integer(8), since allocate( b(6000, 2000000) ) causes no errors.

What can I do to allocate the 2-dimensional array?

Update: Everything is Ok with this code. It seems that 3870457856 is just a chunk size or something like that. 8000*2000000 real array needs 64Gb of RAM, which is not available at this moment.

Upvotes: 0

Views: 50

Answers (1)

Alfonso Sancho
Alfonso Sancho

Reputation: 136

I think the problem is there is not enough memory in the system for an array so big. Try with smaller values. If you need to manage so big array, you will need a new algorithm, or get more ram. According to the message, 4 GB are required just for this variable b. Integer(4) use less memory space, half than integer(8), so this could be the reason it works with integer(4).

Upvotes: 0

Related Questions