2013-12-19 53 views
4

我写了一个Fortran 90代码来从分子模拟数据中提取角度。 在这段代码中,我使用了一个名称为all_parameter的模块。在该模块I所定义的阵列,例如:CH_Angles`在Fortran中用大型阵列重新定位被截断以适合`错误

INTEGER,PARAMETER :: totalFrames = 32000 
INTEGER,PARAMETER :: AAA=75 
REAL,DIMENSION(45:AAA,1:256,1:totalFrames) :: CH_Angles 

如果我使用的AAA = 75值,我可以编译该代码而没有任何错误,我可以得到我想要的值。但是,如果我改变的AAA值是AAA=105,然后我得到一些错误信息,如下图所示:

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 
[email protected]:~/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是限制值。任何超过82的AAA值都会给出错误。

我找不出导致错误的原因。

无论如何找到这个问题的解决方案吗?

注意:我使用Ubuntu 11.10 64位gfortran编译器和16 GB RAM内存。

+4

你会发现问题的解决方案和对这个问题的答案的详细解释:http://stackoverflow.com/questions/12916176/gfortran-for-dummies-what-does-mcmodel-medium-do-exactly – milancurcic

+0

你能提供一个最小但完整的代码示例来重现错误吗? – agentp

+0

研究制作数组“ALOCATABLE”。 – ja72

回答

0

你的阵列CH_Angles是推在大小千兆字节,所以指数算术打算推32位的限制。 我希望事情在这个尺寸上有点棘手。

5

如果我记得正确地,gfortran,像目前大多数Fortran编译器,仍然默认为4字节的整数即使在64位硬件。这意味着,尤其是,最大阵列索引将是2^312^32。由于多秩数组仅仅是一个排序1数组的便利包装,所以我(或@MikeDunlavey)并不奇怪你的编译器在为你分配一个有很多元素的数组。

尝试使用64位整数进行数组索引。您可以通过显式设置为那种他们要么做到这一点,

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。

+1

亲爱的马克,我已经使用(-mcmodel = large)发布在http://forum.osdev.org/viewtopic.php?f=1&p=177541。这工作正常。谢谢你给我一些提示。顺便说一下,它会帮助完整我可以得到一些关于(mcmodel =大)的使用的解释。这实际上做了什么? – user669212

+0

互联网充斥着网站,解释什么* mcmodel *是关于什么以及如何使用它。由于我的答案没有提及* mcmodel *(尽管它可能应该),我不承担任何责任向你解释。我可以提供的任何解释都是不充分的,很可能是不正确的,让您最喜欢的搜索引擎帮助您。 –

+0

@ user669212你甚至可以按照我发表的评论中的链接发表你的问题吗?那里的答案提供了一个很好的解释'-mcmodel'的作用,为什么它在你的情况下是必要的。 – milancurcic

6

你得到的错误是由链接器,因为静态分配的块的大小超过了哪些可以由32位寻址指令,这是2 GB解决的范围内返回。这与使用32位还是64位整数索引数组无关 - 问题与静态分配数组的总大小有关。这是在这里详细解释说:

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

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

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

+0

谢谢你的解释。现在我可以理解使用“mcmodel”了。 – user669212