summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Cohn <robert.s.cohn@intel.com>2024-02-16 02:48:42 -0500
committerGitHub <noreply@github.com>2024-02-16 08:48:42 +0100
commit5c3df6e8cadd68e54f17f2dca56bf4fc5f1f8127 (patch)
tree1677c955a48a4c1ee2fdd447995435d829f854ba /lib
parent79087d08d96b71f373525ffc8f9b6cf9a4acd38b (diff)
downloadspack-5c3df6e8cadd68e54f17f2dca56bf4fc5f1f8127.tar.gz
spack-5c3df6e8cadd68e54f17f2dca56bf4fc5f1f8127.tar.bz2
spack-5c3df6e8cadd68e54f17f2dca56bf4fc5f1f8127.tar.xz
spack-5c3df6e8cadd68e54f17f2dca56bf4fc5f1f8127.zip
[intel-oneapi-mkl] provide omp lib for threads=openmp (#42653)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/build_systems/oneapi.py45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/spack/spack/build_systems/oneapi.py b/lib/spack/spack/build_systems/oneapi.py
index 857f712ee2..e8dc4c61f8 100644
--- a/lib/spack/spack/build_systems/oneapi.py
+++ b/lib/spack/spack/build_systems/oneapi.py
@@ -9,16 +9,26 @@ import platform
import shutil
from os.path import basename, isdir
-from llnl.util.filesystem import HeaderList, find_libraries, join_path, mkdirp
+from llnl.util import tty
+from llnl.util.filesystem import HeaderList, LibraryList, find_libraries, join_path, mkdirp
from llnl.util.link_tree import LinkTree
+from spack.build_environment import dso_suffix
from spack.directives import conflicts, variant
+from spack.package_base import InstallError
from spack.util.environment import EnvironmentModifications
from spack.util.executable import Executable
from .generic import Package
+def raise_lib_error(*args):
+ """Bails out with an error message. Shows args after the first as one per
+ line, tab-indented, useful for long paths to line up and stand out.
+ """
+ raise InstallError("\n\t".join(str(i) for i in args))
+
+
class IntelOneApiPackage(Package):
"""Base class for Intel oneAPI packages."""
@@ -179,6 +189,39 @@ class IntelOneApiLibraryPackage(IntelOneApiPackage):
"""
+ def openmp_libs(self):
+ """Supply LibraryList for linking OpenMP"""
+
+ # NB: Hunting down explicit library files may be the Spack way of
+ # doing things, but it is better to add the compiler defined option
+ # e.g. -fopenmp
+
+ # If other packages use openmp, then all the packages need to
+ # support the same ABI. Spack usually uses the same compiler
+ # for all the packages, but you can force it if necessary:
+ #
+ # e.g. spack install blaspp%oneapi@2024 ^intel-oneapi-mkl%oneapi@2024
+ #
+ if self.spec.satisfies("%intel") or self.spec.satisfies("%oneapi"):
+ libname = "libiomp5"
+ elif self.spec.satisfies("%gcc"):
+ libname = "libgomp"
+ else:
+ raise_lib_error("MKL OMP requires one of %gcc, %oneapi,or %intel")
+
+ # query the compiler for the library path
+ with self.compiler.compiler_environment():
+ omp_lib_path = Executable(self.compiler.cc)(
+ "--print-file-name", f"{libname}.{dso_suffix}", output=str
+ ).strip()
+ # if the compiler cannot find the file, it returns the input path
+ if not os.path.exists(omp_lib_path):
+ raise_lib_error(f"Cannot locate OpenMP library: {omp_lib_path}")
+
+ omp_libs = LibraryList(omp_lib_path)
+ tty.info(f"mkl requires openmp library: {omp_libs}")
+ return omp_libs
+
# find_headers uses heuristics to determine the include directory
# that does not work for oneapi packages. Use explicit directories
# instead.