Non-OpenMP code compiled with OpenMP behaves differently

General OpenMP discussion

Non-OpenMP code compiled with OpenMP behaves differently

Postby sequence » Fri May 03, 2019 10:17 pm

Fortran code I'm working with compiles and runs as expected in sequential mode, but fails to run as expected with OpenMP directives added into the code (mostly loop parallelizations). In order to debug the code I decided to remove all OpenMP directives and then reintroduce them one by one to see where the problem is. However, having removed all the OpenMP code from my Fortran files, compilation with the -fopenmp or -qopenmp flags still provides the same results as if the OpenMP directives were still there.

I've tried to remove the .o files and any other traces the compiled program left, but that didn't change anything. I've tried both the gfortran and ifort compilers (running in Linux Ubuntu, as well as MacOS X).

I'm not sure if I need to show any code in this case as my question is about what happens with the -fopenmp or -qopenmp flags without any OpenMP directives in the code.

I would expect that code not containing any OpenMP directives but compiled with the -fopenmp or -qopenmp flags would run as if it weren't compiled with these flags, and would produce the same results. But this is apparently not true. What could the source of this behavior be?

I'm wondering if someone else has encountered a similar problem and has possibly found a solution.
Posts: 1
Joined: Fri May 03, 2019 7:44 pm

Re: Non-OpenMP code compiled with OpenMP behaves differently

Postby MarkB » Wed May 08, 2019 6:33 am

Compiling with OpenMP enabled forces all local variables to be stack allocated. This can cause your code to fail either because it runs out of stack space, or else you have a bug in your code where you are assuming that local variables without the SAVE attribute will persist from one subroutine call to the next. In the former case, you may need to both increase the stack space for the master thread in the usual way (compiler flags or ulimit for example), and also for the worker threads by setting the OMP_STACKSIZE environment variable. In the second case you need to use the SAVE attribute correctly.
Posts: 801
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 5 guests