Fortran Coder

标题: 关于fortran处理大数组出现错误 [打印本页]

作者: 我是一头牛    时间: 2015-1-15 00:03
标题: 关于fortran处理大数组出现错误
本帖最后由 我是一头牛 于 2015-1-15 00:56 编辑

各位朋友, 我现在用如下的程序把一个含有1024*1280*100个数字的txt文档读入fortran并且赋值给数组a,在这个过程中编译和运行都没有问题。 但是当我读入另一个含有1024*1280*500个数据的txt文档的时候,编译出现了问题,无法运行。错误提示如下。请各位朋友帮忙看一下。谢谢。说明:我的电脑是64位的操作系统,内存是32G,用的是simplyfortran编译器,也是64位的.xyyn.txt数据在这个盘内http://pan.baidu.com/s/1zvXgU
[Fortran] 纯文本查看 复制代码
program main
implicit none
integer,parameter::fg=500
integer,dimension(1024*1280*fg)::a
open(12,file='xyyn.txt')
read(12,*)a
stop
end program

下面是错误提示
Generating Makefile... Okay
==============================================================================
Compiling ..\..\..\..\201501150049.f90
Generating C:\Users\Feng\201501150049.exe
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x207): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_Sleep' defined in .idata$5 section in c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib\libkernel32.a(dkxns01196.o)
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x2ce): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_SetUnhandledExceptionFilter' defined in .idata$5 section in c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib\libkernel32.a(dkxns01183.o)
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x2f2): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_GetProcAddress' defined in .idata$5 section in c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib\libkernel32.a(dkxns00598.o)
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x313): relocation truncated to fit: R_X86_64_PC32 against symbol `__mingw_winmain_hInstance' defined in COMMON section in c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x373): relocation truncated to fit: R_X86_64_PC32 against symbol `__mingw_winmain_lpCmdLine' defined in COMMON section in c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x485): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_GetStartupInfoA' defined in .idata$5 section in c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib\libkernel32.a(dkxns00627.o)
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o: bad reloc address 0x30 in section `.xdata'
c:/program files (x86)/simply fortran 2/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Error(E42): Last command making (C:\Users\Feng\201501150049.exe) returned a bad status
Error(E02): Make execution terminated

* Failed *



20150115010241.png (50.03 KB, 下载次数: 345)

20150115010241.png

作者: pasuka    时间: 2015-1-15 08:12
把变量a改成动态数组再试试看
作者: 楚香饭    时间: 2015-1-15 08:34
1024*1280*500*4 = 2G
这还是二进制的数,写成文本,至少有 4GB。

大量的数据,建议你用二进制存储,读写速度会快很多很多很多。而且文件也小巧。

你真的需要全部读入内存吗?可否分批次读入?
作者: 我是一头牛    时间: 2015-1-15 09:12
pasuka 发表于 2015-1-15 08:12
把变量a改成动态数组再试试看

将a改为动态数组 程序如下
[Fortran] 纯文本查看 复制代码
program main
implicit none
integer,parameter::fg=500
integer,allocatable :: a(:)
allocate(a(1024*1280*fg))
open(12,file='xyyn.txt')
read(12,*)a
write(*,*)a
stop
end program
  错误如下
作者: pasuka    时间: 2015-1-15 10:55
我是一头牛 发表于 2015-1-15 09:12
将a改为动态数组 程序如下[mw_shl_code=fortran,true]program main
implicit none
integer,parameter::fg ...

在64位的Linux下开辟数组空间没有问题,应该是read语句一次性没法读入那么大的数据
若是改成循环形式,逐个读入数组a的数据呢?
另外,这么大数据,一次性读入真的有必要吗?
作者: 楚香饭    时间: 2015-1-15 18:50
木有看到新的错误。

的确 read 读入有限制,具体多少看编译器说明。但肯定比 2G 小




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2