segfault和-fopenmp一个简单的程序 [英] segfault with -fopenmp for a trivial program

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

问题描述

我正在刷新openmp,并陷入了这个奇怪的境地。剃掉了一堆,我创建了这个最小的小案例,显示问题

b integer,parameter :: n = 10000000
integer :: i
real :: x(n)

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

结束程序

不指定标志,gfortran 4.3.4在mac(10.6)上编译,程序正确执行。然而,如果我使用-fopenmp启用openmp,程序将终止并出现分段错误。显然,没有代码被执行,因为它立即崩溃。正如您所看到的,openmp在代码中不会用于并行化任何事情。我尝试修改堆栈大小,都使用ulimit -fmax-stack-var-size,并且无论如何,千万个实数不是我定义的一个大数组。



我做错了什么?

解决方案

是的,openmp通常会改变内存的分配方式。以前的讨论: Fortran中的OpenMP



<在网上搜索,我发现 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



解决了我Mac上的问题。


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

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

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.

What am I doing wrong ?

解决方案

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

Searching on the web, I found 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

fixed the problem on my Mac.

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

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