blas_lapack: add multithreading variant consistent in all implementations. (#5340)

* blas_lapack: add multithreading variant

* elemental: update

* intel-mkl: extend to macOS

* rename multithreading to threads

* intel-mkl: avoid long lines

* intel-mkl: make one install error a conflict

* openblas: fix a minor bug in the test
This commit is contained in:
Denis Davydov 2017-09-23 22:27:42 +02:00 committed by Todd Gamblin
parent bf2f96ce78
commit 7f84de52a0
5 changed files with 67 additions and 22 deletions

View file

@ -54,7 +54,13 @@ class Atlas(Package):
url='http://sourceforge.net/projects/math-atlas/files/Developer%20%28unstable%29/3.11.34/atlas3.11.34.tar.bz2')
variant('shared', default=True, description='Builds shared library')
variant('pthread', default=False, description='Use multithreaded libraries')
variant(
'threads', default='none',
description='Multithreading support',
values=('pthreads', 'none'),
multi=False
)
provides('blas')
provides('lapack')
@ -118,7 +124,7 @@ def libs(self):
# libsatlas.[so,dylib,dll ] contains all serial APIs (serial lapack,
# serial BLAS), and all ATLAS symbols needed to support them. Whereas
# libtatlas.[so,dylib,dll ] is parallel (multithreaded) version.
is_threaded = '+pthread' in self.spec
is_threaded = self.spec.satisfies('threads=pthreads')
if '+shared' in self.spec:
to_find = ['libtatlas'] if is_threaded else ['libsatlas']
shared = True

View file

@ -72,10 +72,10 @@ class Elemental(CMakePackage):
depends_on('blas', when='~openmp_blas ~int64_blas')
# Hack to forward variant to openblas package
# Allow Elemental to build internally when using 8-byte ints
depends_on('openblas +openmp', when='blas=openblas +openmp_blas ~int64_blas')
depends_on('openblas threads=openmp', when='blas=openblas +openmp_blas ~int64_blas')
depends_on('intel-mkl', when="blas=mkl ~openmp_blas ~int64_blas")
depends_on('intel-mkl +openmp', when='blas=mkl +openmp_blas ~int64_blas')
depends_on('intel-mkl threads=openmp', when='blas=mkl +openmp_blas ~int64_blas')
depends_on('intel-mkl@2017.1 +openmp +ilp64', when='blas=mkl +openmp_blas +int64_blas')
# Note that this forces us to use OpenBLAS until #1712 is fixed

View file

@ -23,6 +23,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import os
import sys
from spack import *
from spack.environment import EnvironmentModifications
@ -50,13 +51,22 @@ class IntelMkl(IntelPackage):
variant('shared', default=True, description='Builds shared library')
variant('ilp64', default=False, description='64 bit integers')
variant('openmp', default=False, description='OpenMP multithreading layer')
variant(
'threads', default='none',
description='Multithreading support',
values=('openmp', 'none'),
multi=False
)
provides('blas')
provides('lapack')
provides('scalapack')
provides('mkl')
if sys.platform == 'darwin':
# there is no libmkl_gnu_thread on macOS
conflicts('threads=openmp', when='%gcc')
@property
def license_required(self):
# The Intel libraries are provided without requiring a license as of
@ -82,12 +92,15 @@ def blas_libs(self):
omp_libs = LibraryList([])
if '+openmp' in spec:
if spec.satisfies('threads=openmp'):
if '%intel' in spec:
mkl_threading = ['libmkl_intel_thread']
omp_threading = ['libiomp5']
omp_root = prefix.compilers_and_libraries.linux.lib.intel64
if sys.platform != 'darwin':
omp_root = prefix.compilers_and_libraries.linux.lib.intel64
else:
omp_root = prefix.lib
omp_libs = find_libraries(
omp_threading, root=omp_root, shared=shared)
elif '%gcc' in spec:
@ -100,7 +113,10 @@ def blas_libs(self):
# TODO: TBB threading: ['libmkl_tbb_thread', 'libtbb', 'libstdc++']
mkl_root = prefix.compilers_and_libraries.linux.mkl.lib.intel64
if sys.platform != 'darwin':
mkl_root = prefix.compilers_and_libraries.linux.mkl.lib.intel64
else:
mkl_root = prefix.mkl.lib
mkl_libs = find_libraries(
mkl_integer + ['libmkl_core'] + mkl_threading,
@ -130,7 +146,10 @@ def scalapack_libs(self):
# inspect the root package which asked for Scalapack and check which
# MPI it depends on.
root = self.spec.root
if '^openmpi' in root:
if sys.platform == 'darwin' and '^mpich' in root:
# MKL 2018 supports only MPICH on darwin
libnames.append('libmkl_blacs_mpich')
elif '^openmpi' in root:
libnames.append('libmkl_blacs_openmpi')
elif '^mpich@1' in root:
libnames.append('libmkl_blacs')
@ -146,7 +165,9 @@ def scalapack_libs(self):
raise InstallError('No MPI found for scalapack')
integer = 'ilp64' if '+ilp64' in self.spec else 'lp64'
mkl_root = self.prefix.compilers_and_libraries.linux.mkl.lib.intel64
mkl_root = self.prefix.mkl.lib if sys.platform == 'darwin' else \
self.prefix.compilers_and_libraries.linux.mkl.lib.intel64
shared = True if '+shared' in self.spec else False
libs = find_libraries(
@ -159,7 +180,8 @@ def scalapack_libs(self):
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
# set up MKLROOT for everyone using MKL package
mkl_root = self.prefix.compilers_and_libraries.linux.mkl.lib.intel64
mkl_root = self.prefix.mkl.lib if sys.platform == 'darwin' else \
self.prefix.compilers_and_libraries.linux.mkl.lib.intel64
spack_env.set('MKLROOT', self.prefix)
spack_env.append_path('SPACK_COMPILER_EXTRA_RPATHS', mkl_root)

View file

@ -104,8 +104,12 @@ class IntelParallelStudio(IntelPackage):
description='Builds shared library')
variant('ilp64', default=False,
description='64 bit integers')
variant('openmp', default=False,
description='OpenMP multithreading layer')
variant(
'threads', default='none',
description='Multithreading support',
values=('openmp', 'none'),
multi=False
)
# Components available in all editions
variant('daal', default=True,
@ -168,7 +172,7 @@ def blas_libs(self):
omp_libs = LibraryList([])
if '+openmp' in spec:
if spec.satisfies('threads=openmp'):
if '%intel' in spec:
mkl_threading = ['libmkl_intel_thread']
omp_threading = ['libiomp5']

View file

@ -48,13 +48,19 @@ class Openblas(MakefilePackage):
description='Build shared libraries as well as static libs.'
)
variant('ilp64', default=False, description='64 bit integers')
variant('openmp', default=False, description="Enable OpenMP support.")
variant('pic', default=True, description='Build position independent code')
variant('cpu_target', default='',
description='Set CPU target architecture (leave empty for '
'autodetection; GENERIC, SSE_GENERIC, NEHALEM, ...)')
variant(
'threads', default='none',
description='Multithreading support',
values=('pthreads', 'openmp', 'none'),
multi=False
)
# virtual dependency
provides('blas')
provides('lapack')
@ -89,7 +95,8 @@ def check_compilers(self):
'OpenBLAS requires both C and Fortran compilers!'
)
# Add support for OpenMP
if (('+openmp' in self.spec) and self.spec.satisfies('%clang')):
if (self.spec.satisfies('threads=openmp') and
self.spec.satisfies('%clang')):
if str(self.spec.compiler.version).endswith('-apple'):
raise InstallError("Apple's clang does not support OpenMP")
if '@:0.2.19' in self.spec:
@ -134,9 +141,14 @@ def make_defs(self):
# fix missing _dggsvd_ and _sggsvd_
if self.spec.satisfies('@0.2.16'):
make_defs += ['BUILD_LAPACK_DEPRECATED=1']
# Add support for OpenMP
if '+openmp' in self.spec:
make_defs += ['USE_OPENMP=1']
# Add support for multithreading
if self.spec.satisfies('threads=openmp'):
make_defs += ['USE_OPENMP=1', 'USE_THREAD=1']
elif self.spec.satisfies('threads=pthreads'):
make_defs += ['USE_OPENMP=0', 'USE_THREAD=1']
else:
make_defs += ['USE_OPENMP=0', 'USE_THREAD=0']
# 64bit ints
if '+ilp64' in self.spec:
@ -183,9 +195,10 @@ def check_install(self):
link_flags = spec['openblas'].libs.ld_flags
if self.compiler.name == 'intel':
link_flags += ' -lifcore'
link_flags += ' -lpthread'
if '+openmp' in spec:
link_flags += ' ' + self.compiler.openmp_flag
if self.spec.satisfies('threads=pthreads'):
link_flags += ' -lpthread'
if spec.satisfies('threads=openmp'):
link_flags += ' -lpthread ' + self.compiler.openmp_flag
output = compile_c_and_execute(
source_file, [include_flags], link_flags.split()