From 3553c8b9e92f81e53c607c574b1b746e03039ac7 Mon Sep 17 00:00:00 2001
From: "Kelly (KT) Thompson" <kgt@lanl.gov>
Date: Mon, 10 Oct 2016 18:57:35 -0600
Subject: [PATCH] On Cray machines, use the Cray compile wrappers instead of
 MPI wrappers.

+ Cray compile wrappers are MPI wrappers.
+ Packages that need to be compiled with MPI compile wrappers normally use
  'mpicc', 'mpic++' and 'mpif90' provided by the MPI vendor. However, when using
  cray-mpich as the MPI vendor, the compile wrappers 'CC', 'cc' and 'ftn' must
  be used.
+ In this scenario, the mpich package is hijacked by specifying cray-mpich as an
  external package under the 'mpich:' section of packages.yaml. For example:

  packages:
    mpich:
      modules:
        mpich@7.4.2%intel@16.0.3 arch=cray-CNL-haswell: cray-mpich/7.4.2
      buildable: False
    all:
      providers:
        mpi: [mpich]

+ This change allows packages like parmetis to be built using the Cray compile
  wrappers. For example: 'spack install parmetis%intel@16.0.3 ^mpich@7.4.2 os=CNL'
+ This commit relies on the existence of the environment variable CRAYPE_VERSION
  to determine if the current machine is running a Cray environment. This check is
  insufficient, but I'm not sure how to improve this logic.
+ Fixes #1827
---
 .../repos/builtin/packages/mpich/package.py      | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/var/spack/repos/builtin/packages/mpich/package.py b/var/spack/repos/builtin/packages/mpich/package.py
index a36ab4206e..8f300d4ec7 100644
--- a/var/spack/repos/builtin/packages/mpich/package.py
+++ b/var/spack/repos/builtin/packages/mpich/package.py
@@ -62,10 +62,18 @@ def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
         spack_env.set('MPICH_FC', spack_fc)
 
     def setup_dependent_package(self, module, dep_spec):
-        self.spec.mpicc = join_path(self.prefix.bin, 'mpicc')
-        self.spec.mpicxx = join_path(self.prefix.bin, 'mpic++')
-        self.spec.mpifc = join_path(self.prefix.bin, 'mpif90')
-        self.spec.mpif77 = join_path(self.prefix.bin, 'mpif77')
+        # Is this a Cray machine? (TODO: We need a better test than this.)
+        if os.environ.get('CRAYPE_VERSION'):
+            self.spec.mpicc = spack_cc
+            self.spec.mpicxx = spack_cxx
+            self.spec.mpifc = spack_fc
+            self.spec.mpif77 = spack_f77
+        else:
+            self.spec.mpicc = join_path(self.prefix.bin, 'mpicc')
+            self.spec.mpicxx = join_path(self.prefix.bin, 'mpic++')
+            self.spec.mpifc = join_path(self.prefix.bin, 'mpif90')
+            self.spec.mpif77 = join_path(self.prefix.bin, 'mpif77')
+
         self.spec.mpicxx_shared_libs = [
             join_path(self.prefix.lib, 'libmpicxx.{0}'.format(dso_suffix)),
             join_path(self.prefix.lib, 'libmpi.{0}'.format(dso_suffix))
-- 
GitLab