Skip to content

Creating and activating your Spack environment

To create and activate your Spack environment we suggest you request an interactive qlogin session with fairly decent resources:

qlogin -pe smp 8 -l h_rt=24:0:0 -l h_vmem=2G

Once on a compute node, load a Spack module (module load spack/<version>), and then activate the Spack environment.

Use the Spack modules

Please try to avoid cloning your own version of Spack from GitHub as per the official Spack documentation. Using a module instead means you will use a version we have tested extensively on Apocrita, which may not be the case when cloning via GitHub. Sometimes configuration options change between versions and adjustments would need to be made.

Avoid the spacktivate command

You should always try to use spack env activate rather than the alias spacktivate for activating your personal Spack environments. spacktivate is a bash alias and these won’t work in non-interactive bash environments (such as job scripts for example), so best to avoid using it.

To activate an environment, run the spack env activate command, pointing at the parent directory of your spack.yaml file:

spack env activate -p /data/scratch/${USER}/spack-environments/spack-only

The -p flag means "decorate the command line prompt when activating", which will prepend the name of the activated environment (which is the same as the directory it is stored in) to your prompt in square brackets in a similar fashion as when activating a Conda environment:

[spack-only] [abc123@ddy123 ~]$

If you do not see this prompt decoration, the Spack environment has probably not been correctly activated. Another way to confirm whether a Spack environment is activated is to check the value of the $SPACK_ENV environment variable using the printenv command:

[spack-only] [abc123@ddy123 ~]$ printenv SPACK_ENV
/data/scratch/abc123/spack-environments/spack-only