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

Segmentation fault -- memory problem?

diedro
Débutant
2 406 Visites
hi everyone,
I wrote the following code:
[bash]REAL   ,DIMENSION(nDOF,nVar,nElem)   :: QHAT 
REAL   ,DIMENSION(nDOF,nVar,nElem)   :: FHAT,FHATSTAR [/bash]
when nElem is greater than 10000 I get aSegmentation fault and the program stops
In the program now there are no more code so I think that is a memory program.
I am using the intel fortran compiler, are there any possibilities to check this? Can I extend the memory that I can use.
Thank you
0 Compliments
9 Réponses
mecej4
Contributeur émérite III
2 406 Visites
If these arrays are local variables, you may be running out of stack. Increase the stack limit, or compile with the -heap-arrays option, or modify your program to allocate the arrays.
0 Compliments
diedro
Débutant
2 406 Visites
hi,
how can I do it?
I mean the first option is:
[bash]REAL   ,ALLOCATABLE,DIMENSION(:,:,:)   :: QHAT,FHAT 

ALLOCATE(QHAT(nDOF,nVar,nElem))
ALLOCATE(FHAT(nDOF,nVar,nElem))[/bash]
How Can I apply the other two options?
thank you
0 Compliments
mecej4
Contributeur émérite III
2 406 Visites
For the -heap-arrays option, read the Intel Fortran documentation.

The method of setting the stack limit is OS-specific. Usually, the shell command

ulimit -s unlimited

is enough. See How to raise my stack limit to solve Segmentation fault .
0 Compliments
diedro
Débutant
2 406 Visites
hi,
thank you I'll check.
with allocate I have a strange problem
consider:
[bash]nElem = 40000[/bash]
when I allocate with:
[bash]ALLOCATE(QHAT     (nDOF,nVar,nElem))
         QHAT = 0.D0[/bash]
then I write to screen as:
[bash]WRITE(*,*) "QHAT"   ,QHAT(1,2,40001)[/bash]
I have no segmentation fault
why?
0 Compliments
mecej4
Contributeur émérite III
2 406 Visites
You cannot depend on seg-faults being forced whenever you overrun an array. Often, one variable follows another, as in

COMMON /ABC/A(10),B(10)

It can happen that a reference to A(11) uses B(1). From the Fortran point of view, this is an error, but the OS will not see this as an illegal memory reference.
0 Compliments
diedro
Débutant
2 406 Visites
hi,
so what Can I do?
I have to be more carefull in programming?
or to not use allocatable and increase the cache?
thank you very much
0 Compliments
TimP
Contributeur émérite III
2 406 Visites
No short recommendations can be given beyond what mecej4 said already. The heap-arrays option is reliable when you don't use threaded parallel, although it may hurt performance when unexpected temporary arrays are created.
When writing parallel code, you may need to be careful, as you say, to minimize the unintended use of private arrays and make those you do use work with stack settings.
0 Compliments
diedro
Débutant
2 406 Visites
hi,
so the best way seems to change the stack limits.
I am sorry but I am not very able with bash things.
It is correct if I open the bash file:
[bash]/etc/bash.bashrc[/bash]
and then a copy and paste:
[bash]ulimit -s unlimited[/bash]
Thank you
0 Compliments
Ron_Green
Modérateur
2 406 Visites
that should work, test it with

ulimit -a

next time you login
0 Compliments
Répondre