FORTRAN 77 DIMENSION/SIZE PROBLEM

General OpenMP discussion

FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby livio » Wed Nov 13, 2013 9:47 am

Hi to the community!
I'm approaching a complex job, my objective is to parallelize an old code written in Fortran 77 over the years.
It uses a non sequential Monte Carlo method, with many subroutines.

I choosed openMP to parallelize it, and I don't know if I did the right choice.
INSIDE THE PARALLELIZATION CODE:
- I got rid of commons, i replaced them with arguments inside the call (huge job).
- I also deleted all the variables declarations and replace them with allocatable declarations (which sadly slow down a lot the code execution).

I work with parallel studio 2013 and when I turn on the flag to read the openMP syntax the program compile fine but crashes when it runs.
Is a memory problem because it crashes when try to declare the variables inside sub1(), example down.
It crashes if I try to pass a big array inside the parallel code, (but it doesn't even reach the paralleization code) otherwise it runs.

If I apply the same parallelization problem to a clean project it works fine.
Do you know if openMP has issues with many variable declarations (big arrays and matrix) before even getting to the parallelization syntax?
Do you have any suggestions?
Is there a way to debug the parallel code without writing to an output file with parallel studio 2013?

I tried to increase the stack size:
CALL KMP_SET_STACKSIZE_S()
but nothing has changed.

Thank you a lot,
Livio

the code looks like this:

main program
common/many commons/
call sub1()
end

subroutine sub1()
common/many commons/
parallel do
do mc=1,n
parallel code (without commons and just allocatable variables)
enddo
end parallel do
end
livio
 
Posts: 4
Joined: Tue Nov 12, 2013 8:56 am

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby ftinetti » Wed Nov 13, 2013 11:10 am

Hi Livio,

What's the actual error message?

Fernando.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby livio » Thu Nov 14, 2013 3:11 am

HI fernando,

running the memory analyzer I get this error (which doesn't tell anything):
ID Type Sources Modules Object Size State
P1 Unhandled application exception SUB1.FOR PROGRAM.exe New

during debug I get this error:
file: f:\dd\vctools\crt_bld\sef_x86\crt\src\winsig.c
line: 417
Expression: ("Invalid signal or error", 0)

thank you,
Livio
livio
 
Posts: 4
Joined: Tue Nov 12, 2013 8:56 am

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby MarkB » Thu Nov 14, 2013 3:14 am

KMP_SET_STACKSIZE only affects the stack size for threads other than the master. You may also need to set the master thread's stack size (e.g. using ulimit if you are on Linux).
MarkB
 
Posts: 452
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby ftinetti » Thu Nov 14, 2013 3:49 am

Hi Livio,

Follow Mark's suggestion about ulimit and stack size.

Please take a look at
http://stackoverflow.com/questions/1128 ... rogramming
maybe your problem is related to the point 2 (copied from that URL):
"Make sure you're not writing to pointers that have been declared as local variables and then returned from a function in other parts of your program."
iff you also have pointers to those allocatable variables... By the way, why did you
- I also deleted all the variables declarations and replace them with allocatable declarations (which sadly slow down a lot the code execution).

? I ask because besides the slowing down you found, local variables are not a problem a priori ... or at least not a problem that allocatable variables would solve, I think.

HTH,

Fernando.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby livio » Thu Nov 14, 2013 10:02 am

Thanks for the support,

I'm working on windows system right now.
I got rid of the local variables replacing them with allocating because I was having the same problem (and this operation at the begin solved the issue). Looks like to me that I'm working on the edge of a memory limit, any additional declaration that I do without using "allocate" the program is about to crash, this happens just with openMP falg turned on.

For instance, I use DEFAULT(PRIVATE) in the do loop, if I pass some variable as FIRSTPRIVATE the program quit working, if I use SHARED (for the same variables) the program executes fine. I don't even use the variables that I pass inside the parallel loop, the program crash at the declaration of the subroutine containing the parallel loop.

So I'm thinking to get rid of all the commons of the program, replacing them with the real size of the array and matrix (allocatable), even outside the parallel loop, but is a big job that I'm going to take, I want to make sure to go the right way.

Is there a way to measure the memory left?
How do I increase the master thread's stack size in windows?

Thanks in Advance,
Livio
livio
 
Posts: 4
Joined: Tue Nov 12, 2013 8:56 am

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby ftinetti » Thu Nov 14, 2013 11:07 am

Hi Livio,

I don't have much time right now to carefully read your post. About
Is there a way to measure the memory left?
How do I increase the master thread's stack size in windows?

take a look at:
http://software.intel.com/en-us/article ... ion-fault/
(there are specific comments for several OS, including Windows), take into account that increasing stack size in that page is synonym of increasing stack size for the master thread. Also, I would try the option "heap-arrays".

HTH,

Fernando.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby MarkB » Thu Nov 14, 2013 11:13 am

livio wrote:For instance, I use DEFAULT(PRIVATE) in the do loop, if I pass some variable as FIRSTPRIVATE the program quit working, if I use SHARED (for the same variables) the program executes fine. I don't even use the variables that I pass inside the parallel loop, the program crash at the declaration of the subroutine containing the parallel loop.


That does sound like you are hitting some memory limit: for variables declared FIRSTPRIVATE, a new copy will be allocated for each thread on entry to the parallel region, even if the variable is never used. If the variable is SHARED, the original storage is used and no allocation takes place. For read-only variables it is (almost always) better to use SHARED, as it avoid both the memory allocation and the overhead of copying the values.

livio wrote:How do I increase the master thread's stack size in windows?


For the Intel compiler, you can set it at link time with the /F flag.
MarkB
 
Posts: 452
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby livio » Fri Nov 15, 2013 8:56 am

Thank you a lot for the hints, increasing the stack size solved my problem for right now, I didn't try the option "heap-arrays" yet.
I found out that the same program being run without multiple threads might work fine, but as soon as multi-threading is enabled the program could crash. Looks like that a program with threads have less stack space per thread than a program with no threading support.

I was just wondering if I can Increase the stack without a problem or I run into performance issue?

Thank You !
livio
 
Posts: 4
Joined: Tue Nov 12, 2013 8:56 am

Re: FORTRAN 77 DIMENSION/SIZE PROBLEM

Postby MarkB » Fri Nov 15, 2013 6:17 pm

Compiling with OpenMP enabled (even if your code contains no directives) will typically increase the stack size required, since local variables in routines must be made private to each thread if the routine is called in parallel, and the natural way to implement this is to allocate them on the stack.

There should be no performance penalty for having a large stack.
MarkB
 
Posts: 452
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 12 guests