Repository: spack/spack

Issue:
Installation issue: quantum-espresso (intel-mkl + openmpi)
Spack builds Quantum Espresso with Open Mpi and the Intel MKL with no errors, but when running `pw.x` I immediately get a segfault:

```
$ module load quantum-espresso-6.5-intel-18.0.5-jpplsyv
$ pw.x
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
pw.x               0000000000DAEF6D  Unknown               Unknown  Unknown
libpthread-2.17.s  00002AF905210630  Unknown               Unknown  Unknown
libmpi.so.40.20.3  00002AF904A97291  PMPI_Comm_size        Unknown  Unknown
libmkl_blacs_inte  00002AF8FDC8EE29  MKLMPI_Comm_size      Unknown  Unknown
libmkl_blacs_inte  00002AF8FDC8CFF1  mkl_blacs_init        Unknown  Unknown
libmkl_blacs_inte  00002AF8FDC8CF38  Cblacs_pinfo          Unknown  Unknown
libmkl_blacs_inte  00002AF8FDC7D81F  blacs_gridmap_        Unknown  Unknown
libmkl_blacs_inte  00002AF8FDC7D1FE  blacs_gridinit_       Unknown  Unknown
pw.x               0000000000C30F7D  mp_diag_mp_mp_sta          89  mp_diag.f90
pw.x               000000000040E25D  MAIN__                     74  pwscf.f90
pw.x               000000000040E1EE  Unknown               Unknown  Unknown
libc-2.17.so       00002AF90543F555  __libc_start_main     Unknown  Unknown
pw.x               000000000040E0E9  Unknown               Unknown  Unknown

```
It would seem that Spack is linking against the wrong library, `libmkl_blacs_intelmpi_lp64` instead of `libmkl_blacs_openmpi_lp64`.

### Steps to reproduce the issue

```console
$ spack install quantum-espresso ^openmpi ^intel-mkl
```

### Information on your system

* **Spack:** 0.14.2-1483-6d9f026
* **Python:** 3.6.8
* **Platform:** linux-rhel7-haswell

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/4805105/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/4805106/spack-build-env.txt)

@naromero77

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [x] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:
try to change line 297 of quantum-espresso/package.py from
    ``scalapack_option = 'intel' if '^mkl' in spec else 'yes'``
to
   ``scalapack_option = 'intel' if '^intel-mpi' in spec else 'yes'``
or perhaps
   ``scalapack_option = 'intel' if ('^intel-mpi' in spec and  '^mkl' in spec) else 'yes'``
Thanks for reporting the issue. Let me take a look. There are many combinations that need to be supported and there were many that I didn't bother testing.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/quantum-espresso/package.py b/var/spack/repos/builtin/packages/quantum-espresso/package.py
--- a/var/spack/repos/builtin/packages/quantum-espresso/package.py
+++ b/var/spack/repos/builtin/packages/quantum-espresso/package.py
@@ -294,7 +294,13 @@ def install(self, spec, prefix):
             options.append('BLAS_LIBS={0}'.format(lapack_blas.ld_flags))
 
         if '+scalapack' in spec:
-            scalapack_option = 'intel' if '^mkl' in spec else 'yes'
+            if '^mkl' in spec:
+                if '^openmpi' in spec:
+                    scalapack_option = 'yes'
+                else:  # mpich, intel-mpi
+                    scalapack_option = 'intel'
+            else:
+                scalapack_option = 'yes'
             options.append('--with-scalapack={0}'.format(scalapack_option))
 
         if '+elpa' in spec:


Test patch: