OpenMP in Fortran?

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.

Up vote 2 down vote favorite 1 share g+ share fb share tw.

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 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. Fortran openmp link|improve this question asked May 19 '10 at 16:56Dio1158 86% accept rate.

This is not legacy code, as far as I can see. This is modern way of declaering arrays. As far as openmp is concerned, with all due respect to the tutorial on the link, I humbly recommend "Using OpenMP" book.

It is very friendly to people who've never had to deal with it mitpress.mit.edu/catalog/item/default.as... ... there is another one, but I don't have it on my shelf right now, and cannot remmember the author. If you're interested drop me a comment, and I'll look it up when I get home. – ldigas May 19 '10 at 21:25.

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.

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 May 19 '10 at 18:19 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 May 19 '10 at 18:39 @High Performance Mark is correct that the default is that variables are shared. However, it is common for compilers, when openmp is enabled, to switch to placing local arrays on the stack.

This is useful for subroutines that might be called from parallel regions. A book recommendation: "Using OpenMP" by Chapman, Jost, van der Pas & Kuck. My recommendation – M.

S. B. May 19 '10 at 18:54 Thank you very much for all of your help.

– Dio May 19 '10 at 19:13.

I had this problem. It's spooky: I get segfaults just for declaring 33x33 arrays or 11x11x11 arrays with no OpenMP directives; these segfaults occur on an Intel Mac with 4 GB RAM. Making them "allocatable" rather than statically allocated fixed this problem.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions