Fortran 语言中的 OpenMP

发布于 2024-09-02 07:08:29 字数 818 浏览 3 评论 0原文

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

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

gfortran Example1.F90 -o Example1

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

gfortran -openmp Example1.F90 -o 当我运行旧程序时, Example1

最终出现分段错误。使用我编写的较小的测试程序,我已经成功地使用 -openmp 编译了在多个线程上运行的其他程序,但我很不明白为什么单独启用该选项并且没有指令会导致段错误。

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

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

    ...

    uconsold=0.0    
    uconsolde=0.0       

对“uconsold”的第一个分配工作正常,第二个似乎是错误的根源,因为当我注释掉该行时,接下来的几行会愉快地执行,直到再次使用“uconsolde”。

感谢您在此事上提供的任何帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

碍人泪离人颜 2024-09-09 07:08:31

我遇到了这个问题。令人毛骨悚然:我仅仅因为声明没有 OpenMP 指令的 33x33 数组或 11x11x11 数组而出现段错误;这些段错误发生在具有 4 GB RAM 的 Intel Mac 上。使它们“可分配”而不是静态分配解决了这个问题。

I had this problem. It's spooky: I get segfaults just for declaring 33x33 arrays or 11x11x11 arrays with no OpenMP directives; these segfaults occur on an Intel Mac with 4 GB RAM. Making them "allocatable" rather than statically allocated fixed this problem.

一紙繁鸢 2024-09-09 07:08:30

也许你正在运行堆栈空间?使用 openmp 变量将位于堆栈上,以便每个线程都有自己的副本。也许您的数组很大,即使使用单个线程(没有 openmp 指令),它们也会耗尽堆栈。只是猜测...尝试操作系统的方法来增加堆栈空间的大小,看看分段错误是否消失。

另一种方法:要指定数组应该放在堆上,您可以使其“可分配”。 OpenMP 3.0 版允许更多地使用 Fortran 可分配数组——我不确定细节。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文