0

I write a simple subroutine in fortran for a more complicated program. I need to read a file containing 3 columns of numbers (X_halo, Y_halo, Z_halo) and enter the 3 columns data into 3 arrays. In this subroutine I write the data in a file to see if I can actually read it. I have a file of 5000000 (5 millions) rows.

  SUBROUTINE halo_power

    INTEGER, PARAMETER :: ARRAYLEN=5000000
    CHARACTER(120) :: filename
    REAL*4, DIMENSION (ARRAYLEN) :: X_halo, Y_halo, Z_halo
    INTEGER :: i, istat

    filename = '/path_to/xyz.dat'

    OPEN (UNIT=10, FILE=filename, STATUS='old', ACTION='read')
    OPEN (UNIT=11, FILE='copia.dat', FORM='formatted')

      DO i=1,ARRAYLEN
       READ (10, *) X_halo(i), Y_halo(i), Z_halo(i)
       WRITE (11,*) X_halo(i), Y_halo(i), Z_halo(i)
      END DO

    CLOSE (10)
    CLOSE (11)

  END SUBROUTINE halo_power

The problem is that on my Mac it works, but I have to launch it on a server (a supercomputer) that gives me the error:

power.f90:(.text+0x2ea): relocation truncated to fit: R_X86_64_PC32 against ".bss"
power.f90:(.text+0x2f1): relocation truncated to fit: R_X86_64_PC32 against ".bss"
power.f90:(.text+0x2f8): relocation truncated to fit: R_X86_64_PC32 against ".bss"
power.f90:(.text+0x3e3): relocation truncated to fit: R_X86_64_PC32 against ".bss"

But if I reduce the rows to 5000 it works. How is it possible? Is there a way to create an array of 5 million rows that also works on this server?

# UPDATE:

With ALLOCATE the subroutine alone works (if used as a program), but if I insert it as subroutine within a program (which also works alone), I have the same problem again.

power.f90:(.text+0x2ea): relocation truncated to fit: R_X86_64_PC32 against ".bss"
power.f90:(.text+0x2f1): relocation truncated to fit: R_X86_64_PC32 against ".bss"
power.f90:(.text+0x2f8): relocation truncated to fit: R_X86_64_PC32 against ".bss"
power.f90:(.text+0x3e3): relocation truncated to fit: R_X86_64_PC32 against ".bss"

Is all the code too heavy? How can I fix it?

Alessandro Peca
  • 873
  • 1
  • 15
  • 40
  • 3
    As you target x86_64 you have 2GB limit on .bss at link. Allocatable arrays aren't subject to the limit. – tim18 Aug 12 '17 at 11:33
  • 4
    Try replacing the declaration of `X_halo, ...` by `real, allocatable, dimension(:) :: X_halo, Y_halo, Z_halo` and `allocate(X_halo(ARAAYLEN),Y_halo(ARRAYLEN),Z_halo(ARRAYLEN))`. Have a look art [this question](https://stackoverflow.com/questions/31433121/difference-between-local-allocatable-and-automatic-arrays) and its answers. Different array types in Fortran use different types of memory. Large arrays should be allocatables. – knia Aug 12 '17 at 13:23
  • 1
    It is always good to tell which conpiler produced the error and using which exact command. Allso the operating system. This is an implementation specific thing, not a standard Fortran problem. – Vladimir F Героям слава Aug 12 '17 at 15:19
  • 1
    thank you @A.Hennink now it works! – Alessandro Peca Aug 12 '17 at 15:52
  • 1
    @A.Hennink This helped me too and should be the selected answer, please post as an answer to the question rather than a comment – knw500 Dec 21 '18 at 17:28

0 Answers0