计算要分配的内存量时发生整数溢出 [英] Integer overflow when calculating the amount of memory to allocate

查看:404
本文介绍了计算要分配的内存量时发生整数溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理存储为常规X,Y和Z坐标网格的空间数据集,每个位置都有多个存储属性的字段.但是,在分配用于存储数据的数组时,它将引发错误.

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.

当前在Win10上使用gcc gfortran版本8.1.0(i686-posix-dwarf-rev0,由MinGW-W64项目构建).

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

很明显,我超出了32位整数限制,但是由于我使用的是x64系统,并且(据我所知)编译器是64位版本,所以我不明白为什么m达到了32位的限制.因此,我研究了编译器开关,将所有整数强制为INTEGER * 8都无效.

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!

在搜索各种安装DIR时,我遇到了另外三个都包含gfortran.exe版本的安装.不用说,这些文件优先于最近安装的MinGW编译器套件来调用.一旦删除了这些冗余版本,测试程序和生产工具就可以毫无问题地进行编译和执行(该特定型号的内存分配高达6.5 Gb).

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.

推荐答案

上述问题是由于gfortran.exe编译器的多个实例作为其他程序包(例如Strawberry Perl)的一部分安装的,并通过调用正确的程序来解决编译器直接演示了64位编译器产生的工作程序.

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.

为编译器发现-v开关,可以显示安装路径以及其他环境变量和版本信息.从这里,我可以找到不需要的EXE并删除它们,并在必要时删除它们已过时的已安装软件包.

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.

使用64位编译器处理的结果模型的验证确认程序可以按预期工作.

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

这篇关于计算要分配的内存量时发生整数溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆