Spack

DISCLAIMER: This documentation is not meant to give you a full picture of the spack options and capabilities, but instead, a fast introduction to spack. If you have any further questions about spack after reading this documentation, please have a look at the package documentation: https://spack.readthedocs.io/en/latest/

Spack is a package manager written in python, designed for super computers, clusters and other environments. It allows the users to install multiple versions of the same software and load them one at a time without them conflicting with each other. It also prevents installing dependencies that are already available in the system, making package installations minimal.

To use Spack, we first have to load Spack using module load spack/0.20.1

$ module load spack/0.20.1
Module for spack version 0.20.1 loaded

Note: We recommend using spack/0.20.1.

After loading Spack (with the chosen version), we can list all <span class="note">installed</span> packages using

$ spack find

1. Loading a package

If you want to use an installed package (for example hdf5), you can load it using

$ spack load hdf5

However, the following command, will result in an error because there are too many versions of hdf5.

$ spack load hdf5
  Matching packages:
==> Error: hdf5 matches multiple packages.
  Matching packages:
    hk4xrnb hdf5@1.12.2%oneapi@=2022.1.0 arch=linux-rocky8-zen2
    di2zs64 hdf5@1.12.2%nvhpc@=22.3 arch=linux-rocky8-zen2
    kukzqzz hdf5@1.12.2%gcc@=12.1.0 arch=linux-rocky8-zen2
    ...

We can use /<hash>, to load a given version of hdf5.

$ spack load /di2zs64

We can list all the loaded packages with

$ spack find ---loaded

To unload a given package, spack unload <package-name>. To unload all of them spack unload -a.

2. Installing a package

There are two ways to install a package:

  • Global package installation:

    It is done by the HPC admins and available for everyone with access to Albedo. You can request the HPC Admins via hpc@awi.de to install a software. This way, the package is available for more users and we reduce the number of files in the system (which is good for the overall preformance of Albedo). Note: We recommend using the global installation, as it is "safe" and the user cannot accidentally uninstall them.

  • User-specific package installation:

    It is done by the users and only accessible by them (packages will be installed under $HOME/.spack directory). The use case for this type of installation is when you as a user want to try a package. If you find yourself using it often, our your group is using it often, we recommend requesting a global installation to the HPC Admins.

If you want to use a package that is not pre-installed by the HPC admins, you can install it using spack install <package-name>. For example, we see that node-js is not installed by running

$ spack find node-js
==> No package matches the query: node-js

However, you can install that package using

$ spack install node-js

Similarly, we can uninstall a package using spack uninstall <package-name>.

3. Finding packages already available

Before installing a package, it is recommended to run spack find <package-name>.

$ spack find hdf5
-- linux-rocky8-zen / gcc@8.5.0 ---------------------------------
hdf5@1.12.2  hdf5@1.12.2

-- linux-rocky8-zen / intel@2021.6.0 ----------------------------
hdf5@1.12.2  hdf5@1.12.2

Note: find alone does not show variants!!!!! only different versions of a package.

To get a full picture use -lvp flags:

  • -l shows dependency hashes as well as versions
  • -v shows variants in output (can be long)
  • -p shows paths to package install directories For hdf5, we get
$ spack find -lvp hdf5
-- linux-rocky8-zen / gcc@8.5.0 ---------------------------------
xwuyi5j hdf5@1.12.2~cxx~fortran+hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_type=RelWithDebInfo  /albedo/soft/sw/spack-sw/hdf5/1.12.2-xwuyi5j
dhhubvv hdf5@1.12.2+cxx~fortran+hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_type=RelWithDebInfo  /albedo/soft/sw/spack-sw/hdf5/1.12.2-dhhubvv

-- linux-rocky8-zen / intel@2021.6.0 ----------------------------
ocqziln hdf5@1.12.2+cxx+fortran+hl~ipo~java+mpi+shared+szip~threadsafe+tools api=default build_type=RelWithDebInfo  /albedo/soft/sw/spack-sw/hdf5/1.12.2-ocqziln
mstdrjw hdf5@1.12.2+cxx+fortran+hl~ipo~java+mpi+shared+szip~threadsafe+tools api=default build_type=RelWithDebInfo  /albedo/soft/sw/spack-sw/hdf5/1.12.2-mstdrjw

4. Advanced building

When we load hdf5, we get

$ spack load hdf5
==> Error: hdf5 matches multiple packages.
  Matching packages:
    6mbxanq hdf5@1.12.2%gcc@=8.5.0 arch=linux-rocky8-zen
    hk4xrnb hdf5@1.12.2%oneapi@=2022.1.0 arch=linux-rocky8-zen2
    di2zs64 hdf5@1.12.2%nvhpc@=22.3 arch=linux-rocky8-zen2
    ...

As can be seen from the steps on section 2. Installing a package, our $ spack install hdf5 installed a new version of hdf5; shown under the new hash 6mbxanq. Our new installed version took a default version of hdf5 (1.12.2). In the following subsections we see how we can install packages deviating from the version defaults, variants, compilers and dependencies.

Building a specific version

<package>@<version> allows us to specify the version of hdf5 we want to install

$ spack install hdf5@1.12.0

Building with Variants

spack also offers a way to install "variants" of a particular package, which allow you to enable or disable certain extra features. If you were building "by hand", this would be the equivalent of setting certain compiler options.

Variants allow you to customize the build of a package. Possible variants are listed in the output of spack info:

$ spack info hdf5
...
Variants:
    Name [Default]          When                              Allowed values          Description
    ====================    ==============================    ====================    ============================================

    api [default]           --                                default, v114, v112,    Choose api compatibility for earlier version
                                                              v110, v18, v16
    build_system [cmake]    --                                cmake                   Build systems supported by the package
    build_type [Release]    [build_system=cmake]              Debug, Release,         CMake build type
                                                              RelWithDebInfo,
                                                              MinSizeRel
    cxx [off]               --                                on, off                 Enable C++ support
    fortran [off]           --                                on, off                 Enable Fortran support
    generator [make]        [build_system=cmake]              ninja,make              the build system generator to use
    hl [off]                --                                on, off                 Enable the high-level library
    ipo [off]               [build_system=cmake               on, off                 CMake interprocedural optimization
                            ^cmake@3.9:]
    java [off]              --                                on, off                 Enable Java support
    mpi [on]                --                                on, off                 Enable MPI support
    ...

For example, hdf5 can be built with MPI support. We can use:

spack install hdf5 +mpi

Note: + is used to turn on an otion, ~ to turn off an option and for options which values are not on or off but an item of a list one can specified them as <option>=<my_choice>.

Building with Specific Compilers

We can build using a specified compiler too. spack compilers lists all the available compilers:

$ spack compilers
==> Available compilers
-- aocc rocky8-x86_64 -------------------------------------------
aocc@3.2.0

-- dpcpp rocky8-x86_64 ------------------------------------------
dpcpp@2022.1.0  dpcpp@2022.0.0

-- gcc rocky8-x86_64 --------------------------------------------
gcc@8.5.0  gcc@12.1.0

-- intel rocky8-x86_64 ------------------------------------------
intel@2021.6.0  intel@2021.5.0

-- nvhpc rocky8-x86_64 ------------------------------------------
nvhpc@22.3

-- oneapi rocky8-x86_64 -----------------------------------------
oneapi@2022.1.0  oneapi@2022.0.0  oneapi@2021.4.0

Then we choose by %<compiler>@<version>. For example, choosing intel@2021.5.0:

spack install hdf5 %intel@2021.5.0

We can see the installed package when we use spack find -lv hdf5 %intel@2021.5.0:

$ spack find -lv hdf5 %intel@2021.5.0
-- linux-rocky8-zen2 / intel@2021.5.0 ---------------------------
ilm2ppb hdf5@1.14.1-2~cxx+fortran+hl~ipo~java~map+mpi+shared~szip~threadsafe+tools api=default build_system=cmake build_type=Release generator=make

Build using Dependencies

We can use:

$ spack find -d hdf5

to list all the dependencies of that package. To install with a specific dependency, we use ^.

We can also specify which specific dependencies need to be used during installation, for example for hdf5 with MPI option using the default OpenMPI distribution as a dependency, we use:

$ spack install hdf5 +mpi ^openmpi

After installing a package, we can check the dependencies from the hash of the parent package, in this case dfpzd6b (a variant of hdf5):

$ spack find -d /dfpzs6b

-- linux-rocky8-zen / gcc@8.5.0 ---------------------------------
hdf5@1.12.2
    cmake@3.20.2
    gmake@4.2.1
    openmpi@4.1.3
        hwloc@2.2.0
        numactl@2.0.12
        openssh@8.0p1
        pmix@3.1.4
        slurm@22.05.2
        ucx@1.13.0
    pkgconf@1.4.2
    zlib@1.2.12

==> 1 installed package

5. Modules

Spack creates environment modules in the ~/.spack/modules folder for all the packages the user installs. You can use this modules instead of spack load by using:

$ module use ~/.spack/modules

and then searching for your modules and loading them as usual with the module avail <module> and module load <module>.

6. Recommendations

  • Keep using module load instead of spack load, unless you know why you need to use spack load (you are working on a package installation and testing things around)
  • To find an installed package use spack find -lvp <package> because it gives you all the info you need
  • To list packages that you could possible install use spack list <package>
  • Use hashes as much as possible in all of the spack commands and options, because it allows you to point at specific package variants in a very short way. For example, spack install hdf5 +mpi %/e6l7iew installs hdf5 with a given variant of openmpi with that has the hash e6l7iew


  • No labels