7

I have written a Fortran 90 code to extract angles from molecular simulation data. In this code I used a module with name all_parameter. In this module I defined an array such as: CH_Angles

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

If I use the value of AAA = 75, I can compile this code without any error and I can get the values I wanted. But if I change the value of AAA to be AAA=105, then I get some error messages as shown below:

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

I also tried compiling this code with different values for AAA. With a value 80, the compilation goes without error. But, if the AAA is 85, then the compilation stop with error messages.

I found the AAA=82 is the limiting value. Any value of AAA more than 82, it gives error.

I can not figure out what causes the error.

Is there anyway to find solution for this issue?

Note: I am using gfortran compiler from Ubuntu 11.10 64 bit with 16 GB RAM memory.

user669212
  • 145
  • 1
  • 4
  • 12
  • 7
    You will find the solution to your problem and detailed explanations in the answers to this question: http://stackoverflow.com/questions/12916176/gfortran-for-dummies-what-does-mcmodel-medium-do-exactly – milancurcic Dec 19 '13 at 21:44
  • can you provide a minimal but complete code example to reproduce the error? – agentp Dec 20 '13 at 04:30
  • 1
    Look into making the array `ALOCATABLE`. – John Alexiou Dec 20 '13 at 18:32

3 Answers3

14

The error you get is returned by the linker because the size of the statically-allocated block exceeds the range of what can be addressed by a 32-bit addressing instruction, which is 2 GB. This is irrelevant of whether you index your array using 32-bit or 64-bit integers - the problem is related to the total size of a statically-allocated array. This is explained in details here:

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

In order to work around this, as you have noticed, you can compile your code with -mcmodel=medium or -mcmodel=large. Statically-allocated arrays larger than 2 GB are then allowed.

A better way to deal with this, but involves more work, is to dynamically allocate any large arrays.

Community
  • 1
  • 1
milancurcic
  • 6,202
  • 2
  • 34
  • 47
6

If I remember aright, gfortran, like most current Fortran compilers, still defaults to 4-byte integers even on 64-bit hardware. This means, inter alia, that the largest array index will be 2^31 or 2^32. Since multi-rank arrays are just a convenient wrapper for rank-1 arrays it's no surprise to me (or to @MikeDunlavey) that your compiler baulks at allocating an array with so many elements as you want.

Try using 64-bit integers for array indexing. You could do this either by explicitly setting the kind for them, eg

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

or by using a compiler flag to set the default size of integers to 64 bits. For gfortran this would be -fdefault-integer-8.

I won't guarantee that this will work for gfortran, which is not a compiler I use regularly, but it does for Intel Fortran.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • 1
    Dear Mark, I have used (-mcmodel=large) as posted at http://forum.osdev.org/viewtopic.php?f=1&p=177541. This works fine. Thanks for give me some some hints on this. By the way it will be help full I could get some explanations on the use of (mcmodel=large). What this does actually? – user669212 Dec 20 '13 at 04:36
  • The Internet is awash with sites explaining what *mcmodel* is about, how and why to use it. Since my answer makes no reference to *mcmodel* (though it probably should) I bear no responsibility for explaining it to you. Any explanation I could provide would be inadequate and, most likely, incorrect, let your favourite search engine help you. – High Performance Mark Dec 20 '13 at 11:16
  • @user669212 Did you even follow the link I posted in a comment to your question above? The answers there provide a good explanation what `-mcmodel` does and why is it necessary in your case. – milancurcic Dec 20 '13 at 18:12
  • @HighPerformanceMark I have a similar problem 'failed to convert GOTPCREL relocation; relink with --no-relax'. I have tried --no-relax and -mcmodel=large but the error seems to persist. What could be a possible solution to this? Kindly help. – Neal Titus Thomas Dec 16 '21 at 06:38
0

Your array CH_Angles is pushing a gigabyte in size, so index arithmetic is going to push the 32-bit limit. I would expect things to get a bit screwy at that size.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135