2013-12-19 24 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