OpenMP在Fortran中 [英] OpenMP in Fortran

查看:421
本文介绍了OpenMP在Fortran中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少使用fortran,但是我的任务是将遗留代码重写为并行运行。我正在使用gfortran编译器选择。我在 https://computing.llnl.gov/tutorials/openMP/以及其他一些。



我的问题是,在我添加任何OpenMP指令之前,如果我简单地编译遗留程序:



gfortran Example1.F90 -o Example1



一切正常,但即使没有添加指令也可以打开openmp编译器选项:



gfortran -openmp Example1.F90 -o Example1



在运行旧程序时最终出现分段错误。使用我编写的较小的测试程序,我已经成功编译了其他程序,其中包含可在多个线程上运行的-openmp,但是我为什么单独启用此选项并且没有任何指令导致seg错误而感到茫然。



我很抱歉,如果我的问题很简单。我可以发布代码,但它相当长。我分配初始值时出错:

  REAL,DIMENSION(da,da):: uconsold 
REAL,DIMENSION (da,da,dr,dk):: uconsolde

...

uconsold = 0.0
uconsolde = 0.0

uconsold的第一项工作正常,第二项似乎是错误的来源,因为当我在接下来的几行中发表评论时

感谢您对此事的任何帮助。

解决方案

也许你正在运行堆栈空间?使用openmp变量将在堆栈中,以便每个线程都有自己的副本。也许你的数组很大,甚至有一个线程(没有openmp指令),他们正在使用堆栈。只是一个猜测...尝试你的操作系统的方法来增加堆栈空间的大小,看看分段错误是否消失。另一种方法是:指定数组应该放在堆上,你可以使它可分配。 OpenMP版本3.0允许Fortran可分配数组的更多用途 - 我不确定细节。


I very rarely use fortran, however I have been tasked with taking legacy code rewriting it to run in parallel. I'm using gfortran for my compiler choice. I found some excellent resources at https://computing.llnl.gov/tutorials/openMP/ as well as a few others.

My problem is this, before I add any OpenMP directives, if I simply compile the legacy program:

gfortran Example1.F90 -o Example1

everything works, but turning on the openmp compiler option even without adding directives:

gfortran -openmp Example1.F90 -o Example1

ends up with a Segmentation fault when I run the legacy program. Using smaller test programs that I wrote, I've successfully compiled other programs with -openmp that run on multiple threads, but I'm rather at a loss why enabling the option alone and no directives is resulting in a seg fault.

I apologize if my question is rather simple. I could post code but it is rather long. It faults as I assign initial values:

    REAL, DIMENSION(da,da) :: uconsold
    REAL, DIMENSION(da,da,dr,dk) :: uconsolde

    ...

    uconsold=0.0    
    uconsolde=0.0       

The first assignment to "uconsold" works fine, the second seems to be the source of the fault as when I comment the line out the next several lines execute merrily until "uconsolde" is used again.

Thank you for any help in this matter.

解决方案

Perhaps you are running of stack space? With openmp variables will be on the stack so that each thread has its own copy. Perhaps your arrays are large, and even with a single thread (no openmp directives) they are using up the stack. Just a guess... Trying your operating system's method to increase the size of the stack space and see if the segmentation fault goes away.

Another approach: to specify that the array should go on the heap, you could make it "allocatable". OpenMP version 3.0 allows more uses of Fortran allocatable arrays -- I'm not sure of the details.

这篇关于OpenMP在Fortran中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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