Spack Environments

Purpose

This guide meant as an example for a user to setup a Spack environment for application development using the OLCF provided files as a template.

Warning

The OLCF uses an internal mirror of the Spack repo that is customized for use on OLCF systems. This results in the hash values generated by another version of Spack to not match. It is recommended to use the existing module as external packages instead of chaining at this time.

The provided spack.yaml files are templates for a user to use as an example.

This not intended as a guide for a new Spack user. Please see the Spack 101 tutorial if you need assistance starting out with Spack.

The provided Spack environment files are intended to assist OLCF users in setup their development environment at the OLCF. The base environment file includes the compilers and packages that are installed at the system level.

Traditionally, the user environment is modified by module files. For example, a user would add use module load cmake/3.18.2 to load CMake version 3.18.2 into their environment. Using a Spack environment, a user can add an OLCF provided package and build against it using Spack without having to load the module file separately.

The information presented here is a subset of what can be found at the Spack documentation site.

Note

Definitions

  • Spack environment - A set of Spack specs for the purpose of building, rebuilding and deploying in a coherent fashion.

  • External Packages - An externally-installed package used by Spack, rather than building its own package.

Getting Started

Clone the OLCF User Environment repo and the Spack repo, start a new Spack instance, and create and activate a new Spack environment:

## Using Summit as the example system

$ git clone https://github.com/olcf/spack-environments.git
$ cd spack-environments

$ git clone https://github.com/spack/spack.git
$ source spack/share/spack/setup-env.sh

## Make changes to the template environment module before continuing!!

$ spack env create my_env linux-rhel8-ppc64le/summit/spack.yaml
$ spack env activate my_env

The template file contains usable, but not advisable, settings for configuration items. Options marked with FIXME are specifically recommended to be changed, like the installation root directory. Items marked OPTIONAL indicate points that are not required, but are useful as noted.

Now a user can add and install their dependencies with Spack and proceed with developing their application.

Add Dependencies to the environment

Adding OLCF Modulefiles as External Packages

If an OLCF installed package is available, these can be added via the template spack.yaml file by adding to the packages section. For this example, CMake was found on Summit by finding a modulefile for the installed CMake package.

By marking the CMake package as buildable: false it will force Spack to use the externally installed CMake with the listed modulefile. If this is not indicated, Spack may build its own version of the package.

packages:
  # This example is included in the template file
  cmake:
    version: [3.23.2]
    buildable: false
    externals:
    - spec: cmake@3.23.2
      modules:
      - cmake/3.23.2

As a reminder, to find modules:

## Using cmake as an example again.

$ module -t av cmake
/sw/summit/spack-envs/base/modules/spack/linux-rhel8-ppc64le/Core:
cmake/3.18.4
cmake/3.20.2
cmake/3.21.3
cmake/3.22.2
cmake/3.23.1
cmake/3.23.2

Adding User-Defined Dependencies to the environment

A dependency that is not already installed will be built via Spack once the environment is concretized and installed. These can be added to the spack.yaml by adding to the specs section.

specs:
- cmake@3.18.2                            ## example from above
- my_apps_dependency1@version%compiler    ## other explicitly defined specs
- my_apps_dependency2@version%compiler

Installing the Environment

When in the Spack environment, any packages that are added to the environment file can be installed via:

$ spack concretize -f  ## The -f flag here forces a reconcretization of the entire environment
$ spack install

Alternatively, a user may install a package and its dependencies manually by:

$ spack install <my_app_dependencies@version%compiler>

## This may or may not add the spec to the spack.yaml depending on the Spack version being used.

More Details

For more information regarding Spack and its usage, please see the Spack documentation.

For an extensive tutorial concerning Spack, go to the Spack 101 tutorial.

For more information concerning external packages, please see here.

References