Fortran语言的OpenMP Eclipse的大阵;程序崩溃 [英] Fortran Openmp large array on Eclipse; Program Crash

查看:150
本文介绍了Fortran语言的OpenMP Eclipse的大阵;程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse和GNU Fortran编译计算出一个大阵列来解决一个矩阵问题。然而,我看过的,我是无法读取我的所有数据将导致我project.exe阵列崩溃时,我援引-fopenmp到我的编译器设置的通知;否则,程序工作正常。

I am using Eclipse with GNU Fortran compiler to compute a large arrays to solve a matrix problem. However, I have read and notice that I am unable to read all my data into the array which causes my project.exe to crash when I invoke -fopenmp into my compiler settings; otherwise, the program works fine.

program Top_tier

integer, parameter:: n=145894, nz_num=4608168

integer ia(n+1), ja(nz_num)
double precision a(nz_num), rhs(n)

integer i

open (21, file='ia.dat')
do i=1, n+1
    read(21,*) ia(i)
enddo
close(21)

open (21, file='a.dat')
do i=1, nz_num
    read(21,*) a(i)
enddo
close(21)

open (21, file='ja.dat')
do i=1, nz_num
    read(21,*) ja(i)
enddo
close(21)

open (21, file='b.dat')
    do i=1, n
read(21,*) rhs(i)
enddo
close(21)

End

在我的追求找到解决它的解决方案,我已经找到了最可能的原因是可以通过的事实,如果我设置nz_num较轻的或等于26561时,程序将运行可以看到的堆栈大小的限制正常。一个可能的解决方案是设置环境变量来增加堆栈大小,但是当我键入SETENV或出口OMP_STACKSIZE进入程序的程序不能识别。难道我做错了什么?是否有关于如何解决这个问题的任何建议?

In my quest to find a solution around it, I have found the most probable cause is the limit of the stack size which can be seen by the fact that if I set nz_num to lesser or equal to 26561, the program will run properly. A possible solution is to set environment variable to increase stacksize but the program does not recognise when I type "setenv" or "export" OMP_STACKSIZE into the program. Am I doing something wrong? Is there any advise on how I can solve this problem?

谢谢!

推荐答案

您的分配 A RHS IA JA 堆栈,这就是为什么你在第一个位置运行的堆栈空间。我建议总是在堆中分配大的数组:

You are allocating a, rhs, ia ja on the stack, which is why you are running out of stack space in the first place. I would suggest to always allocate large arrays on the heap:

integer, parameter:: n=145894, nz_num=4608168

integer, dimension(:), allocatable :: ia, ja
double precision, dimension(:), allocatable ::  a, rhs

integer i

allocate(ia(n+1), ja(nz_num))
allocate(a(nz_num), rhs(n))

! rest of your code...

deallocate(ia, ja)
deallocate(a, rhs)

而不是直接声明你一定规模的四个阵列(导致它们被分配在堆栈上)你声明他们作为分配的,给阵列的形状。再往下则可以分配你的阵列到你想要的大小。这个大小可以在运行时选择。这意味着,如果你是从文件中读取你的阵列还可以存储数组的大小在文件的开头,并使用此为您分配的呼叫。
最后,总是与动态分配的内存,别忘了释放他们的时候,你不需要他们了。

Instead of directly declaring your four arrays of a certain size (causing them to be allocated on the stack) you declare them as allocatable and give the shape of the arrays. Further down you can then allocate your arrays to the size you want. This size can be chosen at runtime. That means, if you are reading your arrays from a file you could also store the size of the arrays at the beginning of the file and use this for your allocate call. Finally, as always with dynamically allocated memory, don't forget to deallocate them when you don't need them anymore.

编辑:
我忘了说,这并不能真正有什么使用OpenMP除外OpenMP的线程可能有很多小堆栈大小限制(在这种情况下,那也只能是OpenMP的主线程)。

And I forgot to say that this doesn't really have anything to do with openmp except for that openmp threads probably have much small stack size limits (in this case it would be only the openmp master thread).

这篇关于Fortran语言的OpenMP Eclipse的大阵;程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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