Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2241 Discussions

Static linkage of MKL + MPI + OpenMP fails with multiple definition

foxtran
New Contributor I
283 Views

Hello!

I have an MPI application which, unfortunately, I can not link. The minimal example (main.f90) which still fails:

 

program main
  use mpi
  implicit none
  integer :: ierr
  call mpi_init(ierr)
  call dgemm("I", "DO", "NOT", "CARE", "ABOUT", "ARGS")
  call mpi_finalize(ierr)
end program main

 

 I'm trying to link it statically with ifx as follows:

 

ifx -qopenmp-link=static -static-intel -qmkl=parallel -lm main.f90 -I/opt/intel/oneapi/2025.0/include/mpi -lmpifort -lmpi

And then I get:

ld: /opt/intel/oneapi/2025.0/lib/libiomp5.a(memattrs.o): in function `hwloc_internal_memattr_set_value':
(.text+0x1a80): multiple definition of `hwloc_internal_memattr_set_value'; /opt/intel/oneapi/mpi/2021.14/lib/libmpi.a(memattrs.o):/build/impi/_buildspace/release/src/hwloc/hwloc/../../../../../src/hwloc/hwloc/memattrs.c:926: first defined here

 

This command comes from mpiifx, which was called as follows:

 

mpiifx -qopenmp-link=static -static-intel -qmkl=parallel -lm main.f90

 


Looks like `hwloc_internal_memattr_set_value` is used both in MPI and OpenMP runtimes. I'm not sure that I can use `-Wl,--allow-multiple-definition` flag to avoid this error since these functions can be different.

show command gives me:

 

$ mpiifx -qopenmp-link=static -static-intel -qmkl=parallel -lm main.f90 -show
ifx '-qopenmp-link=static' '-static-intel' '-qmkl=parallel' '-lm' 'main.f90' -I"/opt/intel/oneapi/2025.0/include/mpi" -I"/opt/intel/oneapi/2025.0/include" -I"/opt/intel/oneapi/2025.0/include/mpi" -L"/opt/intel/oneapi/2025.0/lib" -L"/opt/intel/oneapi/2025.0/lib" -Xlinker --enable-new-dtags -Xlinker -rpath -Xlinker "/opt/intel/oneapi/2025.0/lib" -Xlinker -rpath -Xlinker "/opt/intel/oneapi/2025.0/lib" -lmpifort -lmpi -ldl -lrt -lpthread

 

that was simplified. 

Loading of Intel oneAPI stack:

source /opt/intel/oneapi/2025.0/oneapi-vars.sh
source /opt/intel/oneapi/mpi/2021.14/env/vars.sh

 

 

As I can see, the latest oneAPI is used. ifx (mpiifx, TBH) version is:

 

$ mpiifx --version
ifx (IFX) 2025.0.4 20241205
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

 


Moving `-lm` flag at the end of ifx command solves this issue. Unfortunately, I cannot do it because mpiifx has its own opinion about order of flags.

NOTE: ifx says warnings about -lm, but it is only for ifx call which is presented here, we use mpiifx.

Labels (2)
0 Kudos
1 Reply
dusktilldawn
New Contributor I
217 Views

The issue you're facing is related to conflicting symbols between the MPI and OpenMP runtimes.

 

Specifically, the function hwloc_internal_memattr_set_value is defined both in the OpenMP runtime library (libiomp5.a) and in the MPI library (libmpi.a).

 

This results in a "multiple definition" linker error.

 

The error is happening because libiomp5.a (OpenMP runtime) and libmpi.a (MPI runtime) both contain the same definition for hwloc_internal_memattr_set_value.


The OpenMP runtime (libiomp5.a) is linked statically, and it's conflicting with the MPI library (libmpi.a), leading to the multiple definitions error.


POSSIBLE SOLUTIONS:


Use Dynamic Linking for OpenMP:

 

Instead of linking OpenMP statically (-qopenmp-link=static), you can try linking OpenMP dynamically by removing the -qopenmp-link=static flag.

 

This will let the runtime choose the appropriate library without causing conflicts during static linking.

 

Try the following:

mpiifx -static-intel -qmkl=parallel -lm main.f90 -I/opt/intel/oneapi/2025.0/include/mpi -lmpifort -lmpi

This avoids the static OpenMP runtime and should prevent the symbol conflicts with the MPI library.

 

Link OpenMP Last:

 

Sometimes, specifying the order of linking can resolve conflicts. However, since mpiifx controls the flag order, this might not be directly controllable in your case.

 

However, you can try to explicitly add OpenMP to the end of the linking sequence (even though mpiifx orders it). You might want to experiment with manually adjusting the linker flags in your build script, if possible.

 

Use -Wl,--allow-multiple-definition:

 

While this isn't generally recommended because it may mask potential issues, you could try to use -Wl,--allow-multiple-definition if you are sure that the definitions are identical and do not cause runtime issues.

 

This would instruct the linker to ignore multiple definitions of the same symbol.

 

You can try appending the linker flag manually (depending on how you're invoking the compiler):

mpiifx -qopenmp-link=static -static-intel -qmkl=parallel -lm main.f90 -I/opt/intel/oneapi/2025.0/include/mpi -lmpifort -lmpi -Xlinker --allow-multiple-definition

This approach might be less ideal because it could lead to unexpected behavior if the two symbols are not truly identical.

 

Explicitly Link OpenMP After MPI:

 

Since mpiifx controls the order of flags, you may not be able to change the order directly, but in some cases, using -Xlinker to manually adjust the order of library links might help. Here's an example of how you could attempt that:

mpiifx -static-intel -qmkl=parallel -lm main.f90 -I/opt/intel/oneapi/2025.0/include/mpi -lmpifort -Xlinker -lmpi -Xlinker -lomp

Check for Updates or Known Issues:

 

Since you're using the latest versions of the Intel compiler (ifx 2025.0.4) and MPI stack, it might be helpful to check the release notes, known issues, or patches from Intel for any specific guidance regarding this type of symbol conflict.

 

This issue could be specific to your version of the Intel libraries.

 

The most straightforward and clean approach is to try dynamic linking for OpenMP by removing the -qopenmp-link=static flag.

 

Static linking of OpenMP and MPI can sometimes cause symbol conflicts like this.

 

If that doesn't work, experimenting with different linker flags or using the -Wl,--allow-multiple-definition flag could be temporary workarounds, but they might mask underlying issues.

 

Let me know if you need further clarification or if you encounter more errors!

0 Kudos
Reply