Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26739 Discussions

Building OpenMP-compatible sequential libraries

Richard_F_1
Beginner
96 Views
Hi, I have code that consists of a non-parallelized (statically linked) library that I reuse across various projects, and some user code that calls this library from OpenMP-parallelized loops. After observing numerous data races in the library routines, which I though I had written in a thread-safe way, I realized that the sequential library itself has to be compiled with -qopenmp, even though it does not use OpenMP at all. I was wondering what the best practice is when creating a sequential library that can be used both with OpenMP and sequential user code. Are there any problems when linking against a library compiled with -qopenmp if the user code itself is compiled without -qopenmp? Thanks, Richard
0 Kudos
2 Replies
TimP
Black Belt
96 Views

It should be sufficient to set -auto (implied by -qopenmp) or to declare all procedures RECURSIVE.  The difference, with ifort, is in the default storage for local arrays.

If you have SAVE or DATA usage, that may still be incompatible with threading.

Richard_F_1
Beginner
96 Views
Thank you very much, -auto seems to fix the issue as well.
Reply