Repository: spack/spack

Issue:
Installation issue: NAMD with MPI
Hi,
I would like to build NAMD with MPI support.

### Steps to reproduce the issue
```console
$ git clone https://github.com/spack/spack.git

$ cat >spack/etc/spack/defaults/compilers.yaml <<EOL
compilers:
- compiler:
    spec: gcc@9.2.0
    target: x86_64
    operating_system: centos7
    modules: []
    environment: {}
    extra_rpaths: []
    flags: {}
    paths:
      cc:  /opt/gcc-9.2.0/bin/gcc
      cxx: /opt/gcc-9.2.0/bin/g++
      f77: /opt/gcc-9.2.0/bin/gfortran
      fc:  /opt/gcc-9.2.0/bin/gfortran
EOL

$ cat >>spack/etc/spack/defaults/packages.yaml <<EOL

  openmpi:
    externals:
    - spec: "openmpi @4.0.3 %gcc@9.2.0"
      prefix: /opt/openmpi-4.0.3/
    buildable: False

  intel-mpi:
    externals:
    - spec: "intel-mpi @2019.7.217"
      prefix: /opt/intel/compilers_and_libraries_2020.1.217/linux/mpi
    buildable: False

  intel-mkl:
    externals:
    - spec: "intel-mkl @2019.5.281 threads=openmp"
      prefix: /opt/intel/compilers_and_libraries_2019.5.281/linux/mkl
    buildable: False
EOL

$ source spack/share/spack/setup-env.sh
$ spack install namd ^charmpp backend=mpi ^openmpi
...
<built-in>: note: built-in 'strncmp' declared here
chmod: cannot access '/home/vasco/spack/opt/spack/linux-centos7-zen/gcc-9.2.0/charmpp-6.10.2-gq7vrz5ydfhg2oedstxyuvgjjqaj26dd/bin/../include/MPIOPTS': No such file or directory
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
make: *** [inc/ComputeMoaMgr.decl.h] Error 1
make: *** Waiting for unfinished jobs....
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
make: *** [inc/ComputeMgr.decl.h] Error 1
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
make: *** [inc/Node.decl.h] Error 1
make: *** [inc/PatchMgr.decl.h] Error 1
make: *** [inc/WorkDistrib.decl.h] Error 1
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
make: *** [inc/ComputeFmmSerialMgr.decl.h] Error 1
make: *** [inc/ComputeMsmSerialMgr.decl.h] Error 1
Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.
make: *** [inc/ComputeMsmMgr.decl.h] Error 1
```
[spack-build-out.txt](https://github.com/spack/spack/files/5182596/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/5182597/spack-build-env.txt)

Thanks



Discussion:
I would say that this is a possible configuration change/error in the charmpp package.

The following applies to charmpp version **6.10.2** and charmpp spack package for commit 0015dd0

## An educated guess based on some quick digging

`Error> charmc can not call AMPI's mpicxx/mpiCC wrapper! Please fix your PATH.`
That particular error occurs when `$MPICXX  -show ` returns `charmc` as the back end compiler.

`ampicxx -show` is hardcoded to return `charmc` so if `$MPICXX` points to that we will have an error.

When does this happen? 

1. `$MPICXX` is directly set to point to `ampicxx` in the environment
2.  `$MPICXX` is not set -> is read from `include/MPIOPTS` where `$MPICXX` and `$MPICC` are defined during
istallation of charmpp.

In the charmpp spack packge:
```
    def setup_dependent_build_environment(self, env, dependent_spec):
        env.set('MPICC',  self.prefix.bin.ampicc)
        env.set('MPICXX', self.prefix.bin.ampicxx)
        env.set('MPIF77', self.prefix.bin.ampif77)
        env.set('MPIF90', self.prefix.bin.ampif90)
```
So `$MPICXX` is forcefully set to `ampicxx` for dependent builds (I'm not familiar with charmpp so I don't know the reason for this.) so either this is an error or NAMD is doing something wrong in its build.

It's also possible that `$MPICXX` has also been set to `ampicxx` in the  `include/MPIOPTS` file during installation.

Looking at your `spack-build-env.txt` you have `MPICXX=/home/vasco/spack/opt/spack/linux-centos7-zen/gcc-9.2.0/charmpp-6.10.2-gq7vrz5ydfhg2oedstxyuvgjjqaj26dd/bin/ampicxx` which would explain the error. 

A quick fix would be remove that `setup_dependent_build_environment` or override the environment variables in the 
NAMD package. The it should at least compile, I have not tested the correctness otherwise.  



I'm also getting the same error with Intel MPI. Following for a fix. 
Following @Nortamo suggestion I have commented the lines:
```
    def setup_dependent_build_environment(self, env, dependent_spec):
        env.set('MPICC',  self.prefix.bin.ampicc)
        env.set('MPICXX', self.prefix.bin.ampicxx)
        env.set('MPIF77', self.prefix.bin.ampif77)
        env.set('MPIF90', self.prefix.bin.ampif90)
```
in the `charmpp` package.

I was able to install `namd` with:
```
spack install namd @2.15a1 ^charmpp backend=mpi ^intel-mpi
```
And I was able to run the `stmv` benchmark.
Thanks @yellowhat It worked for me as well.
I also encountered this issue, and the fixes suggesgted by @yellowhat appear to resolve
I have submitted a pull request with those suggestions

@matthiasdiener

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/charmpp/package.py b/var/spack/repos/builtin/packages/charmpp/package.py
--- a/var/spack/repos/builtin/packages/charmpp/package.py
+++ b/var/spack/repos/builtin/packages/charmpp/package.py
@@ -370,10 +370,11 @@ def check_build(self):
              'test', 'TESTOPTS=++local', parallel=False)
 
     def setup_dependent_build_environment(self, env, dependent_spec):
-        env.set('MPICC',  self.prefix.bin.ampicc)
-        env.set('MPICXX', self.prefix.bin.ampicxx)
-        env.set('MPIF77', self.prefix.bin.ampif77)
-        env.set('MPIF90', self.prefix.bin.ampif90)
+        if not self.spec.satisfies("backend=mpi"):
+            env.set('MPICC',  self.prefix.bin.ampicc)
+            env.set('MPICXX', self.prefix.bin.ampicxx)
+            env.set('MPIF77', self.prefix.bin.ampif77)
+            env.set('MPIF90', self.prefix.bin.ampif90)
 
     def setup_dependent_package(self, module, dependent_spec):
         self.spec.mpicc     = self.prefix.bin.ampicc


Test patch: