From 1cd03e0f36618188b1a11808df689c58ea8a1422 Mon Sep 17 00:00:00 2001
From: Brian Van Essen <vanessen1@llnl.gov>
Date: Fri, 26 Jan 2018 11:38:37 -0700
Subject: [PATCH] new package: essl (#6335)

Added support for the IBM ESSL math library.Updated Elemental to be
able to build with ESSL.
---
 .../builtin/packages/elemental/package.py     | 21 ++++-
 .../repos/builtin/packages/essl/package.py    | 87 +++++++++++++++++++
 2 files changed, 106 insertions(+), 2 deletions(-)
 create mode 100644 var/spack/repos/builtin/packages/essl/package.py

diff --git a/var/spack/repos/builtin/packages/elemental/package.py b/var/spack/repos/builtin/packages/elemental/package.py
index 19ab7583ab..c661e073cb 100644
--- a/var/spack/repos/builtin/packages/elemental/package.py
+++ b/var/spack/repos/builtin/packages/elemental/package.py
@@ -68,8 +68,8 @@ class Elemental(CMakePackage):
     variant('build_type', default='Release',
             description='The build type to build',
             values=('Debug', 'Release'))
-    variant('blas', default='openblas', values=('openblas', 'mkl'),
-            description='Enable the use of OpenBlas/MKL')
+    variant('blas', default='openblas', values=('openblas', 'mkl', 'essl'),
+            description='Enable the use of OpenBlas/MKL/ESSL')
     variant('mpfr', default=False,
             description='Support GNU MPFR\'s'
             'arbitrary-precision floating-point arithmetic')
@@ -84,8 +84,13 @@ class Elemental(CMakePackage):
     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')
 
+    depends_on('essl -cuda', when='blas=essl -openmp_blas ~int64_blas')
+    depends_on('essl threads=openmp', when='blas=essl +openmp_blas ~int64_blas')
+
     # Note that this forces us to use OpenBLAS until #1712 is fixed
     depends_on('lapack', when='blas=openblas ~openmp_blas')
+    depends_on('netlib-lapack +external-blas', when='blas=essl')
+
     depends_on('metis')
     depends_on('metis +int64', when='+int64')
     depends_on('mpi')
@@ -145,6 +150,15 @@ def cmake_args(self):
             libfortran = LibraryList(mpif77('--print-file-name',
                                             'libgfortran.%s' % dso_suffix,
                                             output=str))
+        elif self.spec.satisfies('%xl') or self.spec.satisfies('%xl_r'):
+            xl_fort = env['SPACK_F77']
+            xl_bin = os.path.dirname(xl_fort)
+            xl_root = os.path.dirname(xl_bin)
+            libfortran = LibraryList('{0}/lib/libxlf90_r.{1}.1'
+                                     .format(xl_root, dso_suffix))
+        else:
+            libfortran = None
+
         if libfortran:
             args.append('-DGFORTRAN_LIB=%s' % libfortran.libraries[0])
 
@@ -205,5 +219,8 @@ def cmake_args(self):
         elif 'blas=mkl' in spec:
             args.extend([
                 '-DHydrogen_USE_MKL:BOOL=%s' % ('blas=mkl' in spec)])
+        elif 'blas=essl' in spec:
+            args.extend([
+                '-DHydrogen_USE_ESSL:BOOL=%s' % ('blas=essl' in spec)])
 
         return args
diff --git a/var/spack/repos/builtin/packages/essl/package.py b/var/spack/repos/builtin/packages/essl/package.py
new file mode 100644
index 0000000000..946b93518b
--- /dev/null
+++ b/var/spack/repos/builtin/packages/essl/package.py
@@ -0,0 +1,87 @@
+##############################################################################
+# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/spack/spack
+# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+from spack import *
+
+
+class Essl(Package):
+    """IBM's Engineering and Scientific Subroutine Library (ESSL)."""
+
+    homepage = "https://www.ibm.com/systems/power/software/essl/"
+    url      = "ibm-essl"
+
+    version('5.5')
+
+    variant('ilp64', default=False, description='64 bit integers')
+    variant(
+        'threads', default='openmp',
+        description='Multithreading support',
+        values=('openmp', 'none'),
+        multi=False
+    )
+    variant('cuda', default=False, description='CUDA acceleration')
+
+    provides('blas')
+
+    conflicts('+cuda', when='+ilp64',
+              msg='ESSL+cuda+ilp64 cannot combine CUDA acceleration'
+              ' 64 bit integers')
+
+    conflicts('+cuda', when='threads=none',
+              msg='ESSL+cuda threads=none cannot combine CUDA acceleration'
+              ' without multithreading support')
+
+    @property
+    def blas_libs(self):
+        spec = self.spec
+        prefix = self.prefix
+
+        if '+ilp64' in spec:
+            essl_lib = ['libessl6464']
+        else:
+            essl_lib = ['libessl']
+
+        if spec.satisfies('threads=openmp'):
+            # ESSL SMP support requires XL or Clang OpenMP library
+            if '%xl' in spec or '%xl_r' in spec or '%clang' in spec:
+                if '+ilp64' in spec:
+                    essl_lib = ['libesslsmp6464']
+                else:
+                    if '+cuda' in spec:
+                        essl_lib = ['libesslsmpcuda']
+                    else:
+                        essl_lib = ['libesslsmp']
+
+        essl_root = prefix.lib64
+        essl_libs = find_libraries(
+            essl_lib,
+            root=essl_root,
+            shared=True
+        )
+
+        return essl_libs
+
+    def install(self, spec, prefix):
+        raise InstallError('IBM ESSL is not installable;'
+                           ' it is vendor supplied')
-- 
GitLab