Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP in Fortran

Tags:

fortran

openmp

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.

like image 782
Dio Avatar asked Dec 29 '22 16:12

Dio


1 Answers

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.

like image 52
M. S. B. Avatar answered Jan 11 '23 03:01

M. S. B.