Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29064 Discussions

How to properly compile C/Fotran libraries (like NetCDF) for use with OpenMP

tniw
Beginner
1,291 Views

I have the following issue:

 

I'm trying to build complicated application where:

- target program is parallelized with OpenMP (and MPI but MPI seems to be irrelevant here),

- target program depends on few external libraries (like HDF, NetCDF) which depend on other libraries,

- compilers are called indirectly through configure (tests of features) and libtool.

 

I decided to use:

- Intel 2024.0.0

- ifort for Fotran and icx for C.

 

Hoping to get libraries that properly work with OpenMP I decided to use (among others):

- ifort with -threads ,

- icx with -pthread .

 

For "Fortran" libraries (libraries providing interface for Fotran programs, beeing mostly "interface" to library providing interface for C programs), building with settings as above causes libtool to place in respective *.la

inherited_linker_flags=' -pthread -threads'

 

Unfortunately, when I try to compile next library based on the libraries already compiled as above, libtool (most apparently) reads inherited_linker_flags from respective *.la file (available along with library) and attempts to use them in the current compilation.

 

This causes libtool to give -threads to icx and ends with

icx: error: unknown argument '-threads'; did you mean '-mthreads'?

 

In this context I'd like to ask the following quesions:

 

- What is the difference (at least roughly) between -threads and -pthreads, what is the reason that you name these switches different way (I expect they have some common set of features they provide, but most probably those sets are very different)? Or where can I read about it? Manuals for compilers are very concise and it is not possible to understand quickly what given switch does and how to apply it correctly in such complex application.

 

- Do I use the swithces cited above correctly (trying to get the libraries that work correctly with OpenMP programs (compiled with Intel))?

 

- What is Intel's recommended set of switches making a given library (providing C and F interfaces, say NetCDF, say not counting HDF threads issues) ready and safe for use with OpenMP?

Labels (2)
4 Replies
Shiquan_Su
Moderator
1,245 Views

Hi,

First of all, please use ifx compiler for Fortran (not ifort, we do not actively support ifort anymore, hence we could not answer any ifort technical support request), icx compiler for C. 

Then please see the answers inline:

Hoping to get libraries that properly work with OpenMP I decided to use (among others):

- ifort with -threads ,

- icx with -pthread .

answer: -threads and -pthread are not the right flags to enable OpenMP. Please use -fopenmp to enable OpenMP support. For more details, please check here: https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-2/fopenmp-qopenmp.html 

 

- What is the difference (at least roughly) between -threads and -pthreads, what is the reason that you name these switches different way (I expect they have some common set of features they provide, but most probably those sets are very different)? Or where can I read about it? Manuals for compilers are very concise and it is not possible to understand quickly what given switch does and how to apply it correctly in such complex application.

answer: -threads and -pthreads point to some old threading techniques, they are not relevant in the context of OpenMP. Sometimes if you use Intel® oneAPI Math Kernel Library Link Line Advisor,  you may be instructed to include the -pthreads. Usually, you don't actively add the -pthreads flag unless you are told to do so.

 

- Do I use the switches cited above correctly (trying to get the libraries that work correctly with OpenMP programs (compiled with Intel))?

answer: usually you just run the ./configure -help command to study the proper configuration options for you, then run the ./configure command to configure the external libraries to your cluster before you build them (make; make install), you don't set -fopenmp for your external libraries, also you don't set -pthreads and -threads.

 

- What is Intel's recommended set of switches making a given library (providing C and F interfaces, say NetCDF, say not counting HDF threads issues) ready and safe for use with OpenMP?

answer: you start by doing nothing, just replacing ifort with ifx, and the libraries should be built and run correctly. If you meet issues related to the library, study the ./configure -help first to make sure the library is configured properly for your machine environment.

tniw
Beginner
1,189 Views

Thank you for your comprehensive concrete answers. Let me now digest them in practice...

PS.

> [...] start by doing nothing

> [...] study the ./configure -help

FYI actions described in 1st post were undertaken already after applying the cited approach you propose. The reason is that binary I've got blows up at some stage, with stack corrupted. Hoping to spend less time on debugging application itself, I decided to take over control over what compiler does (and exploit diagnostics it provides), starting from application dependencies. Unfortunately this leads to "surprises" like the one described in 1st post.

0 Kudos
Shiquan_Su
Moderator
1,142 Views

Hi,

From my existing limited knowledge about external libraries, such as netcdf, the -threads and -pthreads usually are not the right help, unless you actually see a successful example of applying those flags to solving the issue on your cluster.

There is another approach you may consider. Do you know Spack (https://spack.io/) or Easybuild (https://easybuild.io/)? They are very robust HPC packages and dependency management systems. The best thing is that the solutions they provided are from the practice of the HPC community that may have hardware and HPC environments similar to yours. So it did save the world from reinventing the wheel in many cases.

And how to make the netcdf library work with multi-threading or OpenMP CPU threading or even OpenMP target offloading seems like the topic that is easier/better to work with netcdf developer. I assume if they provide the features of running their netcdf library calls faster with OpenMP support, they know how to test that after the library installation and could tell you how to do so.

0 Kudos
Shiquan_Su
Moderator
900 Views

Please work with the developers of the external libraries to make sure you implement the proper procedure to build the dependency with OpenMP support and using ifx compiler. Then you may compile and link those dependencies to your project code using ifx and openmp. The -threads and -pthreads usually are not relevant in these cases, unless you are instructed by the manual to do so. If you meet further issues, please attach a small reproducer here, so we can take a closer look. Please include the source code file and necessary build script, also the exact command leading to the crash and the screen output. Thanks.


0 Kudos
Reply