Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran I/O: Specifying large record sizes

Tags:

fortran

I am trying to write an array to file, where I have opened the file this way:

open(unit=20, FILE="output.txt", form='unformatted', access='direct', recl=sizeof(u))

Here, u is an array and sizeof(u) is 2730025920, which is ~2.5GB. When I run the program, I get an error Fortran runtime error: RECL parameter is non-positive in OPEN statement, which I believe means that the record size is too large.

Is there a way to handle this? One option would be to write the array in more than one write call such that the record size in each write is smaller than 2.5GB. But I am wondering if I can write the entire array in a single call.

Edit: u has been declared as double precision u(5,0:408,0:408,0:407) The program was compiled as gfortran -O3 -fopenmp -mcmodel=medium test.f There is some OpenMP code in this program, but the file I/O is sequential.

gfortran v 4.5.0, OS: Opensuse 11.3 on 64 bit AMD Opteron

Thanks for your help.

like image 659
jitihsk Avatar asked Jan 26 '12 03:01

jitihsk


1 Answers

You should be able to write big arrays as long as it's memory permitting. It seems like you are getting integer overflow with the sizeof function. sizeof is not Fortran standard and I would not recommend using it (implementations may vary between compilers). Instead, it is a better practice to use the inquire statement to obtain record length. I was able to reproduce your problem with ifort and this solution works for me. You can avoid integer overflow by declaring a higher kind variable:

integer(kind=8) :: reclen

inquire(iolength=reclen)u 

open(unit=20,file='output.txt',form='unformatted',&
     access='direct',recl=reclen)

EDIT: After some investigation, this seems to be a gfortran problem. Setting a higher kind for integer reclen solves the problem for ifort and pgf90, but not for gfortran - I just tried this with version 4.6.2. Even though reclen has the correct positive value, it seems that recl is 32-bit signed integer internally with gfortran (Thanks @M.S.B. for pointing this out). The Fortran run-time error suggests this, and not that the value is larger than maximum. I doubt it is an OS issue. If possible, try using ifort (free for non-commercial use): Intel Non-Commercial Software Download.

like image 192
milancurcic Avatar answered Sep 30 '22 21:09

milancurcic