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 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

Question about array declarations in the examples

Postby xinwu » Tue Jan 12, 2010 7:54 am

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

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

Then the compiled executable will produce a segmentation fault.
But for small arrays, for example,
Code: Select all

It works fine.

So, I'm just confused about this weird phenomenon. Can anyone have a suggestion? Thank you in advance!
Posts: 7
Joined: Tue Jan 12, 2010 7:29 am

Re: Question about array declarations in the examples

Postby nathanweeks » Tue Jan 12, 2010 6:24 pm

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
Nathan Weeks
Iowa State University HPC Group
Posts: 41
Joined: Sun May 17, 2009 6:19 am
Location: Iowa State University

Re: Question about array declarations in the examples

Postby ruud » Sun Jan 17, 2010 9:59 pm

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.

Posts: 23
Joined: Mon Nov 26, 2007 2:13 am

Return to Using OpenMP - The Book and Examples

Who is online

Users browsing this forum: No registered users and 1 guest