Fortran I / O:指定较大的记录大小 [英] Fortran I/O: Specifying large record sizes

查看:447
本文介绍了Fortran I / O:指定较大的记录大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这里, u 是一个数组,而 sizeof(u)是2730025920,它是〜2.5GB。
当我运行该程序时,出现错误 Fortran运行时错误:在OPEN语句中,RECL参数是非肯定的,我相信这意味着记录大小是太大了。



有没有办法解决这个问题?一种选择是在多次写入调用中写入数组,使得每次写入的记录大小小于2.5GB。但我想知道是否可以在一次调用中写入整个数组。

编辑:
u 已被声明为 double precision u(5 ,0:408,0:408,0:407)
程序编译为 gfortran -O3 -fopenmp -mcmodel = medium test.f
这个程序中有一些OpenMP代码,但文件I / O是顺序的。



gfortran v 4.5.0,操作系统:64位AMD Opteron上的Opensuse 11.3



感谢您的帮助。

解决方案

只要内存允许,您应该可以编写大数组。看起来你正在用 sizeof 函数获得整数溢出。 sizeof 不是Fortran标准,我不推荐使用它(编译器之间的实现可能会有所不同)。相反,使用 inquire 语句获取记录长度是一种更好的做法。我能够通过ifort重现您的问题,并且此解决方案适用于我。你可以通过声明一个更高类型的变量来避免整数溢出:

  integer(kind = 8):: reclen 

inquire(iolength = reclen)u

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

编辑:经过一番调查,这似乎是一个gfortran问题。为整数 reclen 设置一个更高的类型可以解决ifort和pgf90的问题,但不能解决gfortran的问题 - 我只是在4.6.2版本中试过。即使 reclen 具有正确的正值,看起来像 recl 是带有gfortran的32位有符号整数(谢谢@MSB指出了这一点)。 Fortran运行时错误提示了这一点,而不是该值大于最大值。我怀疑这是一个操作系统问题。如果可能,请尝试使用ifort(免费用于非商业用途):英特尔非商业软件下载


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.

解决方案

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.

这篇关于Fortran I / O:指定较大的记录大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆