首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Fortran中使用大型数组时出现‘`Relocation to fit`’错误

Fortran中使用大型数组时出现‘`Relocation to fit`’错误
EN

Stack Overflow用户
提问于 2013-12-20 00:45:17
回答 3查看 14.6K关注 0票数 7

我已经写了一个Fortran 90代码来从分子模拟数据中提取角度。在这段代码中,我使用了一个名为all_parameter的模块。在此模块中,我定义了一个数组,例如:CH_Angles

代码语言:javascript
复制
INTEGER,PARAMETER :: totalFrames = 32000  
INTEGER,PARAMETER :: AAA=75
REAL,DIMENSION(45:AAA,1:256,1:totalFrames) :: CH_Angles

如果我使用AAA = 75的值,我可以编译这段代码,没有任何错误,我可以得到我想要的值。但是,如果我将AAA的值更改为AAA=105,那么我会得到一些错误消息,如下所示:

代码语言:javascript
复制
gfortran lipid-Tilt-Magnitude-thermo-cello.f90
/tmp/ccXOhMqQ.o: In function `__all_parameter_MOD_find_angle_ch':
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x35): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_x' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x48): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_y' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x5b): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_z' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x6e): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_x' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x81): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_y' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x94): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_z' defined in .bss section in /tmp/ccXOhMqQ.o
/tmp/ccXOhMqQ.o: In function `__all_parameter_MOD_find_mid_point_vector':
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x126): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_x' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x139): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_y' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x14c): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_z' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x15f): relocation truncated to fit: R_X86_64_32S against symbol `__all_parameter_MOD_x' defined in .bss section in /tmp/ccXOhMqQ.o
lipid-Tilt-Magnitude-thermo-cello.f90:(.text+0x172): additional relocation overflows omitted from the output
collect2: ld returned 1 exit status
vijay@glycosim:~/Simulation-Folder-Feb2013/chapter5-thermo-paper2-Vj/thermo2-Analysis/analysis-bcm-/23_acf-tail-tilt-angle-bcm-thermo2/chain1/acf-chain1-CH-bcm-thermo-all-layers$ gfortran lipid-Tilt-Magnitude-thermo-cello.f90

我还尝试使用不同的AAA值编译此代码。值为80时,编译不会出错。但是,如果AAA为85,则编译将停止并显示错误消息。

我发现AAA=82是极限值。任何AAA的值大于82,它都会给出错误。

我找不出是什么导致了这个错误。

有没有办法找到解决这个问题的办法?

注意:我使用的gfortran编译器来自Ubuntu 11.10 64位,内存为16 GB。

EN

回答 3

Stack Overflow用户

发布于 2013-12-21 02:26:22

链接器返回的错误是因为静态分配的块的大小超出了32位寻址指令可以寻址的范围,即2 GB。这与使用32位或64位整数索引数组无关-问题与静态分配的数组的总大小有关。这里有详细的解释:

gfortran for dummies: What does mcmodel=medium do exactly?

正如您已经注意到的,为了解决这个问题,您可以使用-mcmodel=medium-mcmodel=large编译代码。然后,允许静态分配的数组大于2 GB。

处理这种情况的一种更好的方法是动态分配任何大型数组,但涉及更多的工作。

票数 13
EN

Stack Overflow用户

发布于 2013-12-20 01:50:41

如果我没记错的话,gfortran就像大多数当前的Fortran编译器一样,即使在64位硬件上也仍然默认为4字节整数。这意味着,最大的数组索引将是2^312^32。因为多级数组只是一级数组的一个方便的包装器,所以我(或@MikeDunlavey)一点也不奇怪,你的编译器在分配一个拥有你想要的元素的数组时迟迟不能行动。

尝试使用64位整数进行数组索引。您可以通过显式地为它们设置类型来做到这一点,例如

代码语言:javascript
复制
use, intrinsic :: iso_fortran_env, only : int64
...
INTEGER(int64),PARAMETER :: totalFrames = 32000  
INTEGER(int64),PARAMETER :: AAA=75
REAL,DIMENSION(45_int64:AAA,1_int64:256_int64,1_int64:totalFrames) :: CH_Angles

或者通过使用编译器标志将整数的默认大小设置为64位。对于gfortran,这将是-fdefault-integer-8

我不能保证这将适用于gfortran,这不是我经常使用的编译器,但它适用于英特尔Fortran。

票数 6
EN

Stack Overflow用户

发布于 2013-12-20 00:52:51

您的数组CH_Angles的大小为1 32,因此索引算法将突破32位的限制。我预计在这种规模下,事情会变得有点古怪。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20687170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档