Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

How to raise my stack limit to solve "Segmentation fault"

Anonymous21
Beginner
4,905 Views

My code makes "Segmentation fault". I search this problem in website,so thereforeI have to raise the stack limit. Would you let me know how to increase it? or do you have someoption for compile command? I use the bash shell for RHEL4.0.

Thanks

Message Edited by hydrol88 on 05-23-200603:00 PM

0 Kudos
5 Replies
micahe
Beginner
4,903 Views

If you believe the SEGV is due to exceeding stack size limit, then you can increase it with bash's builtin ulimit. E.g.,

$ ulimit -s unlimited

OR

$ ulimit -s 
0 Kudos
Ron_Green
Moderator
4,903 Views
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.

0 Kudos
Anonymous21
Beginner
4,903 Views
I solved my problems using the command "ulimit -s unlimited" in ./bashrc
Thanks for your helps.
0 Kudos
Anonymous21
Beginner
4,903 Views
I solved my problems using the command "ulimit -s unlimited" in /.bashrc
Thanks for your helps
0 Kudos
Intel_C_Intel
Employee
4,904 Views
Ronald,

I read your stack size question with interest, since I am having
this problem with the Nasa Overflow 2.0 code (which uses alot of
automatic arrays) and SCALI MPI. I had been stumped about getting
the overflow program to run, since it seemed to die at an area where
is was allocating an automatic array. I found your code
unlimit_stack and added that to the overflow program. The program
now runs to completion without a segfault. I had ulimit -s
unlimited in my submital script (PBS PRO) and in my .bashrc. Any
ideas as to why it would now work using your assembler code and not
the ulimit -s script setting??

Thanx,

Bernie Borenstein
The Boeing Company
0 Kudos
Reply