Question about array declarations in the examples

Use this forum to discuss the book: Using OpenMP - Portable Shared Memory Parallel Programming, by Barbara Chapman, Gabriele Jost and Ruud van der Pas Read the http://openmp.org/forum/viewtopic.php?f=8&t=465 for book info and to download the examples. Post your feedback about the book and examples to this forum
Post Reply
xinwu

Question about array declarations in the examples

Post by xinwu »

Hi, I'm just a beginner of Fortran 90 and OpenMP. I noticed the arrays in the Fortran code, e.g. in fig3.11-mxv-omp.f90, are declared as allocatable.
For example,

Code: Select all

real(kind=8),allocatable::a(:)
And then the sizes of the arrays are read from the standard input. This works for both small and large arrays, e.g. a(5) and a(5000).
However, if the size of the arrays are specified explicitly. For example,

Code: Select all

real(kind=8)::a(5000)
Then the compiled executable will produce a segmentation fault.
But for small arrays, for example,

Code: Select all

real(kind=8)::a(5)
It works fine.

So, I'm just confused about this weird phenomenon. Can anyone have a suggestion? Thank you in advance!

nathanweeks
Posts: 41
Joined: Sun May 17, 2009 6:19 am
Location: Iowa State University
Contact:

Re: Question about array declarations in the examples

Post by nathanweeks »

Depending on the compiler and where in the code an array appears, hard-coding the size of an array may cause it to be allocated on the stack instead of the heap, and stack space is sometimes limited. One thing you could to do verify if this is the case is set the OMP_STACKSIZE environment variable before running your program; e.g., if you're using bash/ksh/sh, and the executable is "fig3", and your array size per thread is a few hundred kb:

Code: Select all

OMP_STACKSIZE=1M ./fig3
--
Nathan Weeks
Iowa State University HPC Group
http://weeks.public.iastate.edu/

ruud

Re: Question about array declarations in the examples

Post by ruud »

Hi Xinwu, I agree with the previous post this is most likely a stacksize related problem. Please try it by setting OMP_STACKSIZE to an appropriate value. For example, for a double precision 5000x5000 array you'll need about 200MB of stack space.

You may also want to check the stacksize setting in the OS. This is for the master thread. In the bourne or bash shell you can use the ulimit command to find the setting and change it, if needed. In the csh or tcsh you can use the limit command.

Ruud

Post Reply