带有 -fopenmp 的段错误,用于一个简单的程序 [英] segfault with -fopenmp for a trivial program

查看:15
本文介绍了带有 -fopenmp 的段错误,用于一个简单的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在刷新 openmp,并陷入了这种奇怪的情况.剃掉一堆,我创建了这个显示问题的最小的琐碎案例

I am refreshing openmp a bit, and got into this weird situation. Shaved off the bunch, I created this minimal trivial case that shows the issue

program ex2
    implicit none
    integer, parameter :: n=10000000
    integer :: i
    real :: x(n)

    do i=1,n
        x(i) = 0.0d0
    enddo

end program

没有指定标志,mac (10.6) 上的 gfortran 4.3.4 编译,程序正确执行.

with no flags specified, gfortran 4.3.4 on the mac (10.6) compiles, and the program executes correctly.

但是,如果我使用 -fopenmp 启用 openmp,程序会因分段错误而终止.显然,没有代码被执行,因为它立即崩溃.如您所见,openmp 从未在代码中用于并行化任何内容.我尝试修改堆栈大小,都使用ulimit -fmax-stack-var-size,无论如何,千万实数不是我定义的大数组.

However, if I enable openmp with -fopenmp, the program terminates with segmentation fault. No code get executed, apparently, as it crashes immediately. As you see, openmp is never used in the code to parallelize anything. I tried to modify the stack size, both with ulimit the -fmax-stack-var-size, and in any case, ten millions reals is not what I define a big array.

我做错了什么?

推荐答案

是的,openmp 通常会改变内存的分配方式.之前的讨论:OpenMP in Fortran

Yes, openmp typically changes how memory is allocated. A previous discussion: OpenMP in Fortran

在网上搜索,我发现 http://homepage.mac.com/eric.c/hpc/contents/documentation/How%20to%20increase%20the%20stack%20size%20on%20Mac%20OS%20X.pdf

gfortran-mp-4.3 -fopenmp ex2.f90 -Wl,-stack_size,0x40000000,-stack_addr,0xf0000000 -o ex2.exe

gfortran-mp-4.3 -fopenmp ex2.f90 -Wl,-stack_size,0x40000000,-stack_addr,0xf0000000 -o ex2.exe

修复了我的 Mac 上的问题.

fixed the problem on my Mac.

这篇关于带有 -fopenmp 的段错误,用于一个简单的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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