Repository: spack/spack

Issue:
can't install two versions of intel-mkl 2019.0.117
### Description

seems that intel installer is too clever and picks up the previous installation of `intel-mkl` using `spack`. Which is unfortunate as one can't have `intel-mkl threads=none` and `intel-mkl threads=openmp` installed at the same time ;-(

### Steps to reproduce

```
spack install intel-mkl
spack install intel-mkl threads=openmp
```

gives error during installation and prints the message:

```
The install directory path was changed to <previous-spack-installed-mkl> 
because at least one software product component was detected as having already been installed on the system

Please select at least one component before you continue
```

Not sure if there is anything Spack can do... ;-(


Discussion:
I noticed this as well. Quite frustrating.
You may have to remove the $HOME/intel/.pset directory and/or the $HOME/intel/intel_sdp_products.db file.
@lee218llnl 

> You may have to remove the $HOME/intel/.pset directory and/or the $HOME/intel/intel_sdp_products.db file.

thanks for the tip. I wonder if we should make it the default behavior  in `intel` packages so that Spack actually supports installation of multiple variants (or at least make it so for `intel-mkl`)? Or maybe at least mention it in each package description to guide users.
>  I wonder if we should make it the default behavior in intel packages so that Spack actually supports installation of multiple variants (or at least make it so for intel-mkl)?

@mgsternberg what do you think?
I encountered the same issue where I had an older version of `intel-mkl` which was used to install some packages, but when I tried to install a new version, I got this error :

Checking for older verions : 
```
[sajid@xrmlite ~]$ spack find intel-mkl                                                                                                                        
==> 2 installed packages                                                                                                                                       
-- linux-centos7-x86_64 / gcc@7.3.0 -----------------------------                                                                                              
intel-mkl@2018.3.222                                                                                                                                           
                                                                                                                                                               
-- linux-centos7-x86_64 / intel@18.0.3 --------------------------                                                                                              
intel-mkl@2018.3.222          
```

Trying to install a new version:
```                                                                                                                                 
[sajid@xrmlite ~]$ spack install intel-mkl@2019.0.117%intel@18.0.3                                                                                             
==> Installing intel-mkl                                                                                                                                       
==> Searching for binary cache of intel-mkl                                                                                                                    
==> Warning: No Spack mirrors are currently configured                                                                                                         
==> No binary for intel-mkl found: installing from source                                                                                                      
==> Using cached archive: /home/sajid/packages/spack/var/spack/cache/intel-mkl/intel-mkl-2019.0.117.tgz                                                        
==> Staging archive: /home/sajid/packages/spack/var/spack/stage/intel-mkl-2019.0.117-curhdvo35nifojtgv5riil6esclnjg6v/l_mkl_2019.0.117.tgz                     
==> Created stage in /home/sajid/packages/spack/var/spack/stage/intel-mkl-2019.0.117-curhdvo35nifojtgv5riil6esclnjg6v                                          
==> No patches needed for intel-mkl                                                                                                                            
==> Building intel-mkl [IntelPackage]                                                                                                                          
==> Executing phase: 'configure'                                                                                                                               
==> Executing phase: 'install'                                                                                                                                 
==> Error: ProcessError: Command exited with status 2:                                                                                                         
    './install.sh' '--silent' 'silent.cfg'                                                                                                                     
See build log for details:                                                                                                                                     
  /home/sajid/packages/spack/var/spack/stage/intel-mkl-2019.0.117-curhdvo35nifojtgv5riil6esclnjg6v/l_mkl_2019.0.117/spack-build.out                           
```

Reason for failure:
``` 
[sajid@xrmlite ~]$ cat /home/sajid/packages/spack/var/spack/stage/intel-mkl-2019.0.117-curhdvo35nifojtgv5riil6esclnjg6v/l_mkl_2019.0.117/spack-build.out       
==> Executing phase: 'configure'                                                                                                                               
==> Executing phase: 'install'                                                                                                                                 
==> './install.sh' '--silent' 'silent.cfg'                                                                                                                     
--------------------------------------------------------------------------------                                                                               
The install directory path was changed to                                                                                                                      
/home/sajid/packages/spack/opt/spack/linux-centos7-x86_64/intel-18.0.3/intel-mpi                                                                               
-2019.0.117-zukeu5d4z3f4rlnueiwzz2ts44odvawc                                                                                                                   
because at least one software product component was detected as having already                                                                                 
been installed on the system.                                                                                                                                  
--------------------------------------------------------------------------------                                                                               
Please select at least one component before you continue.                                                                                                      
--------------------------------------------------------------------------------                                                                               
                                                                                                                                                               
--------------------------------------------------------------------------------                                                                               
```
I can confirm that

> You may have to remove the $HOME/intel/.pset directory

resolves the problem. I still think there should be some hints for users to do this if such issue appears. 
I don't have a $HOME/intel directory
Ok figured this out. 

You need to go to the staging directory and run the interactive version of the installer. When prompted, you need to choose the uninstall option. Once the uninstall is finished, you should be able to reinstall the intel-mkl.

m
So this also means that there is no way of installing e.g. `intel-parallel-studio` with spack if another version is already manually installed on the system?

We are currently moving to spack and don't want to remove our manual intel installation yet with is located in `/software/intel` but this does not allow to install `intel-parallel-studio` in `/software/spack` due to the error reported above
> So this also means that there is no way of installing e.g. intel-parallel-studio with spack if another version is already manually installed on the system?

You can, comment above works for me https://github.com/spack/spack/issues/9713#issuecomment-436081356

Resolving patch:
diff --git a/lib/spack/spack/build_systems/intel.py b/lib/spack/spack/build_systems/intel.py
--- a/lib/spack/spack/build_systems/intel.py
+++ b/lib/spack/spack/build_systems/intel.py
@@ -964,7 +964,8 @@ def libs(self):
                 root=self.component_lib_dir('mpi'),
                 shared=True, recursive=True) + result
 
-        if '+mkl' in self.spec or self.provides('scalapack'):
+        if '^mpi' in self.spec.root and ('+mkl' in self.spec or
+                                         self.provides('scalapack')):
             result = self.scalapack_libs + result
 
         debug_print(result)
@@ -1199,6 +1200,9 @@ def install(self, spec, prefix):
         install_script = Executable('./install.sh')
         install_script.add_default_env('TMPDIR', tmpdir)
 
+        # Need to set HOME to avoid using ~/intel
+        install_script.add_default_env('HOME', prefix)
+
         # perform
         install_script('--silent', 'silent.cfg')
 


Test patch: