2009年5月24日星期日

段错误Segmentation fault with ifort -openmp

在运行使用ifort加openmp参数编译出来的程序时,有时候报segmentation fault段错误。比较烦,因为同样的代码用pfg90编译出来的就没事。所以怀疑不是程序的问题,在网上查到intel论坛里有人对这个问题找到了解决方法。
现在就使用最简单的在shell中设置“ulimit -s unlimited”的方法。下面是引自intel论坛的两段话段话。
---------Segmentation fault with ifort -openmp------------------

I am replying to my thread Since I found the solution

It was a stack overflow.

I could remedy it by using

ulimit -s 2048000 (you can choose an appropriarte) number ... then changing the same in /etc/security/limits.conf (to have it changed permanently).

then export KMP_STACKSIZE=2048000000 (i chose very high value, since it is only a limit)


A few notes to add to Micah's
1) if 'ulimit -s unlimited' fails it means that the kernel is configured with a hard limit to the size of the stack for user shell processes. This limit needs to be removed by a root user.
2) 32bit Linux distros have a static pthread library (libpthread.a) that will set the user stack to 2MB at runtime during the startup of your program linked statically with libpthread. Thus, anything you do to ulimit is ignored. Keep in mind, this only affects 32bit linux distros and only if you link statically. Unfortunately, if you use
ifort -fast .... or icc -fast
the -fast option includes -static which will do a static link
To avoid this issue, either don't use -fast and call out -O3 and -ax explicitly. See -fast for all the options included therein.
3) Some batch and runtime systems used on clusters often ignore your current limits for the remote processes. Thus, you'll need to put the unlimit command inside your .bashrc and/or your .profile
4) I've had to move around a LOT of systems over the years, so when I create my programs, in my startup I call a C function "unlimit_stack()" to bump my stack up as high as it'll go (unlimited in most cases). Here is that C code:

#include // perror

#include // exit

#include // setrlimit

#include // setrlimit

#include // setrlimit

void unlimit_stack_(void) {

struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY };

if ( setrlimit(RLIMIT_STACK, &rlim) == -1 ) {

perror("setrlimit error");

exit(1);

}

}

Yes, a Fortran programmer who can write C too. and here's how to call it from Fortran:

Program main

external unlimit_stack

call unlimit_stack()

...etc...

end

Hope this helps. If not, I have some code to determine at runtime the stacksize seen by your program.

-------------------------------------------------------------

另一个关于Segmentation fault的帖子

没有评论: