Skip to content

Spack

changelog

install/uninstall

Spack can install software either from source or from a binary cache. Packages in the binary cache are signed with GPG for security.

By default this will install the binary cached version if it exists and fall back on installing from source if it does not.

The % sigil is used to specify compilers. The @ sigil is used to specify versions, both of packages and of compilers. Dependencies can be explicitly requested using the ^ sigil.

The spec syntax also includes compiler flags. Spack accepts cppflags, cflags, cxxflags, fflags, ldflags, and ldlibs parameters. The values of these fields must be quoted on the command line if they include spaces.

Spack generates a hash for each spec. This hash is a function of the full provenance of the package, so any change to the spec affects the hash. Spack uses this value to compare specs and to generate unique installation directories for every combinatorial version.

By default, Spack tries hard to reuse existing installations as dependencies, either from a local store or from configured remote buildcaches.

:star: Spack models the dependencies of packages as a directed acyclic graph (DAG).

We can use either -f (force) or -R (remove dependents as well) to remove packages that are required by another installed package.

``` bash=

add Spack to your path

. share/spack/setup-env.sh

spack install zlib spack install zlib %clang spack versions zlib spack install zlib@1.2.8 spack install zlib %gcc@6.5.0 spack install zlib@1.2.8 cppflags=-O3 spack install tcl spack install tcl ^zlib@1.2.8 %clang

query installed packages

spack find

The -l flag shows the hash of each package, and

the -f flag shows any non-empty compiler flags of those packages.

-d flag, which can show dependency information

spack find -ldf

spack uninstall -y zlib %gcc@6.5.0 spack uninstall zlib/2xc spack uninstall -y -R zlib/2xc

HDF5 is a good example of a more complicated package, with an MPI dependency.

If we install it “out of the box,” it will build with OpenMPI.

Spack packages can also have build options, called variants. Boolean variants can be specified using the + (enable) and ~ or - (disable) sigils.

We might also want to install HDF5 with a different MPI implementation. 
While MPI is not a package itself, packages can depend on abstract interfaces like MPI. 
Spack handles these through **virtual dependencies**. 
A package, such as HDF5, can depend on the MPI interface. Other packages (openmpi, mpich, mvapich2, etc.) provide the MPI interface. Any of these providers can be requested for an MPI dependency. 

For example, we can build HDF5 with MPI support provided by MPICH by specifying a dependency on mpich. 
Spack also supports versioning of virtual dependencies. 
A package can depend on the MPI interface at version 3, and provider packages specify what version of the interface they provide.

``` bash=
spack install hdf5
spack install hdf5~mpi
spack install hdf5+hl+mpi ^mpich
spack graph hdf5+hl+mpi ^mpich

let’s look at an even more complicated package, Trilinos.

Although we’ve done a binary installation for the tutorial, a source installation of Trilinos using Spack takes about 3 hours (depending on the system), but only 20 seconds of programmer time.

The ASCII output from spack graph can be difficult to parse for complicated packages. The output can be changed to the Graphviz .dot format using the --dot flag.

``` bash= spack install trilinos spack install trilinos +hdf5 ^hdf5+hl+mpi ^mpich spack graph --dot trilinos | dot -Tpdf > trilinos_graph.pdf

## Customizing Compilers

Spack manages a list of available compilers on the system, detected automatically from the user’s PATH variable.

The compilers are maintained in a YAML file.
~/.spack/linux/compilers.yaml

``` bash=
spack compiler list
spack compilers

spack install gcc@8.4.0
# We can add GCC to Spack as an available compiler using the spack compiler add command.
spack compiler add "$(spack location -i gcc@8.4.0)"
spack compiler remove gcc@8.4.0

find

``` bash=

return every installed package that depends on MPICH

spack find ^mpich

return every package which was built with cppflags="-O3"

spack find cppflags="-O3"

show which packages were installed explicitly (rather than pulled in as a dependency) using the lowercase -x flag.

The uppercase -X flag shows implicit installs only.

spack find -px

## Environment
- [Environments Tutorial — Spack Tutorial documentation](https://spack-tutorial.readthedocs.io/en/latest/tutorial_environments.html#environments-tutorial)
- [Stacks Tutorial — Spack Tutorial documentation](https://spack-tutorial.readthedocs.io/en/latest/tutorial_stacks.html)


An environment is like a virtualized Spack instance that you can use to aggregate package installations for a project or other purpose.

``` bash=
# add Spack to your path
. share/spack/setup-env.sh


spack env list
spack env create foo
# activate our environment
spack env activate -p foo
spack env status
spack env deactivate

:::info If you use the -p option for spack env activate, Spack will prepend the environment name to the prompt. This is a handy way to be reminded if and which environment you are in. :::

Environments are special in that you must add specs to them before installing.

``` bash=

spack.yaml
``` bash
ls -la var/spack/environments/foo/
# other way
spack cd -e foo
pwd && ls -la


spack config get
spack config edit

There are two key files tracking the contents of environments: spack.yaml and spack.lock.

The spack.yaml file holds the environment configuration that we previously edited through spack config edit. The spack.lock file is automatically generated during concretization.

``` bash= spack env create abstract-foo spack.yaml spack env create concrete-foo spack.lock

## Modules
- [Modules (modules.yaml) — Spack 0.20.0.dev0 documentation](https://spack.readthedocs.io/en/latest/module_file_support.html)


Spack integrates with Environment Modules and Lmod by providing post-install hooks that generate module files and commands to manipulate them.

Spack only generates modulefiles when a package is installed. If you attempt to install a package and it is already installed, Spack will not regenerate modulefiles for the package. 

there is a subsection on regenerating modules that will allow you to bring your modules to a consistent state.

``` bash=
module avail
# regenerating modules
spack module tcl refresh
module avail

spec

spack spec -N hdf5