OpenMP Fortran

I use fortran very rarely, but I have been instructed to translate the old code, rewriting it so that it works in parallel. I use gfortran for my choice of compiler. I found some great resources at https://computing.llnl.gov/tutorials/openMP/ , as well as several others.

My problem is that before adding any OpenMP directives, if I just 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 with a segmentation error when I run an outdated program. Using the small test programs that I wrote, I successfully compiled other programs with -openmp that run on multiple threads, but I don’t quite understand why including this option alone and no directives leads to a seg error.

Sorry if my question is pretty simple. I could send the code, but it's quite long. It causes errors when assigning initial values:

REAL, DIMENSION(da,da) :: uconsold REAL, DIMENSION(da,da,dr,dk) :: uconsolde ... uconsold=0.0 uconsolde=0.0 

The first assignment of “uconsold” works fine, the second seems to be the source of the error, because when I comment out a line, the next few lines are fun until “uconsolde” is used again.

Thanks for any help in this matter.

+4
source share
2 answers

Perhaps you are using stack space? With variables, openmp will be on the stack so that each thread has its own copy. Perhaps your arrays are large, and even with a single thread (without openmp directives) they use the stack. Just guess ... Try your operating system method to increase the size of the stack space and see if the segmentation error disappears.

Another approach: specify that the array should be on the heap, you can make it "allocatable". OpenMP version 3.0 allows more use of Fortran distributed arrays - I'm not sure about the details.

+7
source

I had this problem. This is creepy: I get segfaults only to declare 33x33 arrays or 11x11x11 arrays without OpenMP directives; These segfaults occur on an Intel Mac with 4 GB of RAM. Making them “distributed” rather than statically distributed fixed this problem.

+2
source

Source: https://habr.com/ru/post/1310267/


All Articles