gfortran二维数组分配报‘Not enough space’错误的解决咨询
问题场景
在64位gfortran 14.2(gcc 12也存在相同问题)环境下运行以下代码:
program test1 real, allocatable :: a(:), b(:,:) ! allocate( a(3870457856_8) ) allocate( b(8000, 2000000) ) end program test1
执行后报错:
In file 'test4.f90', around line 5: Error allocating 3870457856 bytes: Not enough space
相关测试现象:
- 注释第二个
allocate、取消第一个allocate注释时,程序可正常运行 - 使用编译选项
-mcmodel=large无效果 - 尝试
allocate( b(6000, 2000000) )时无错误,曾怀疑与integer(4)到integer(8)的寻址转换有关
问题结论
代码本身无问题,8000*2000000的real数组(每个real占8字节)需要64GB内存,当前运行环境内存不足导致分配失败。
内容的提问来源于stack exchange,提问作者Pavel Ruzankin
相关产品推荐
相关产品推荐

