tags:

views:

201

answers:

1
+2  Q: 

OpenMP in Fortran

I very rarely use fortran, however I have been tasked with taking legacy code rewriting it to run in parallel. I'm using gfortran for my compiler choice. I found some excellent resources at https://computing.llnl.gov/tutorials/openMP/ as well as a few others.

My problem is this, before I add any OpenMP directives, if I simply compile the legacy program:

gfortran Example1.F90 -o Example1

everything works, but turning on the openmp compiler option even without adding directives:

gfortran -openmp Example1.F90 -o Example1

ends up with a Segmentation fault when I run the legacy program. Using smaller test programs that I wrote, I've successfully compiled other programs with -openmp that run on multiple threads, but I'm rather at a loss why enabling the option alone and no directives is resulting in a seg fault.

I apologize if my question is rather simple. I could post code but it is rather long. It faults as I assign initial values:

    REAL, DIMENSION(da,da) :: uconsold
    REAL, DIMENSION(da,da,dr,dk) :: uconsolde

    ...

    uconsold=0.0    
    uconsolde=0.0       

The first assignment to "uconsold" works fine, the second seems to be the source of the fault as when I comment the line out the next several lines execute merrily until "uconsolde" is used again.

Thank you for any help in this matter.

+3  A: 

Perhaps you are running of stack space? With openmp variables will be on the stack so that each thread has its own copy. Perhaps your arrays are large, and even with a single thread (no openmp directives) they are using up the stack. Just a guess... Trying your operating system's method to increase the size of the stack space and see if the segmentation fault goes away.

Another approach: to specify that the array should go on the heap, you could make it "allocatable". OpenMP version 3.0 allows more uses of Fortran allocatable arrays -- I'm not sure of the details.

M. S. B.
While I think that @MSB makes a reasonable suggestion, I flat out disagree with the statement that 'each thread has its own copy'. Unless you declare a variable to be private then all threads will share the variable. I have never encountered an OpenMP system which implements shared variables by copying them to all threads and managing consistency behind the scenes.
High Performance Mark
You're exactly right, on my linux box:ulimit -s unlimited./Example1 Worked like a charm. This might be out of scope (and the sad result of the fact that 95% of my time is spend in Java) but I somehow figured both normally compiled fortran and openmp would use stack space. As I'd much rather read a book than keep bugging you, do you happen to know a good resource I can check out to understand what I've gotten myself into a bit better?
Dio
M. S. B.
Thank you very much for all of your help.
Dio