Installing Packages

  • Installing a package with Spack is very simple. To install a package, you simply type:

    spack install <packaage_name>
  • For example, to install zlib software, you simply type:

    spack install zilb

    For more details on installing packages, please visit Spack Documentation.

Specifying Compilers

  • In Spack, you can request specific configurations of the package. For example, you can specify compilers using % symbol. For example, to install zlib package using gcc compiler, you type:

    spack install zilb %gcc

Specifying Versions of Compilers and Packages

  • Each package may have different versions. Spack allows users to specify which version of a package to install.

  • You can check for particular versions before requesting them. To show all available versions of a specific software, you type:

    spack versions <package_name>
  • For example, to list versions of zlib, you simply type:

    spack versions zlib
  • This will print all available versions of zlib as follows:

    ==> Safe versions (already checksummed):
      1.2.11  1.2.8  1.2.3
    ==> Remote versions (not yet checksummed):
      1.2.10   1.2.6  1.0.9  1.0.1    0.91
      1.2.9  1.2.0    1.0.8  1.0-pre  0.79
  • The output has two sections:

    • Safe versions (already checksummed): the versions that Spack knows about. In other words, the versions that were added to the package.

    • Remote versions: the versions that are available on the remote server that weren’t added to the Spack package.

  • The @ symbol is used to specify versions of packages and compilers. To install the version 1.2.11 of zlib, you type:

    spack install zlib@1.2.11
  • If you want to use the version 4.8.5 of the gcc compiler when installing the version 1.2.11 of zlib, you type:

    spack install zlib@1.2.11 %gcc@4.8.5

    If you don’t specify the version of a package, Spack will install the default version of that package.

Specifying Compiler Flags

  • Spack allows users to include compiler flags in the command line when installing a package. Spack accepts cppflags, cflags, cxxflags, fflags, ldflags, and ldlibs flags. The values of these flags must be quoted if they included spaces. These values are injected into the compile line automatically by the Spack compiler wrappers.

  • For example, to install an optimized version of zlib, you need to use -O3 flag. This can be accomplished by specifying the value of cppflags in the command line as follows:

    spack install zlib cppflags=-O3

Specifying Dependencies

  • Some packages may depend on other packages. This means that when a package is installed, all its dependencies are installed. Dependencies can be explicitly requested using the ^ symbol. Anything you could specify about the top-level package, you can also, specify about dependencies using ^.

  • For example, the tcl package depends on the zlib package. Suppose you want to use a specific version of zlib as a dependency, you can specify that in the command line as follows:

    spack install tcl ^zlib@1.2.8
  • This command installs the default version of tcl and its dependency zlib at the version 1.2.8.

Changing Build Options

  • Spack packages can also have build options, called variants. Some variants may be boolean where they can be True or False. They can be specified using the + for True and ~ or - for False. Variants (boolean or otherwise) can also be specified using the same syntax as compiler flags.

  • For example, the default version of the HDF5 package is installed with MPI support. Suppose you want to install its serial version, you need to disable the MPI support. This can be accomplished by making the mpi variant False as follows:

    spack install hdf5~mpi
  • There are other packages that provide the MPI interface such as openmpi, mpich, and mvapich. You might want to install a package with a different MPI implementation. Spack handles these through virtual dependencies. For instance, HDF5 can depend on the MPI interface.

  • If you would like to change the MPI support of HDF5 to openmi, you type:

    spack install hdf5+mpi ^openmpi

Reusing Installed Dependencies

  • By default, when you try to install a package using spack install, Spack tries to build that package along with its dependencies. If one of the dependencies is already installed with a different version that’s specified in the spec of the package, Spack won’t use the installed dependency. Instead, it builds the dependency with the appropriate version. This means that the dependency will be built twice. Spack allows you to try hard to reuse existing installations as dependencies by adding the --reuse option to the spack install command.

  • For example, the nano package depends on the ncurses@6.2 package. Suppose you have installed ncurses@6.1 before, and you want to install nano as follows:

    spack install nano
  • Spack will install ncurses@6.2 and all other dependencies of nano, and then it will install the package. This means that two versions of ncurses are installed.

  • Instead of installing ncurses@6.2 as a dependency, you can force Spack to use the already installed version of ncurses (ncurses@6.1). To do so you type:

    spack install --reuse nano
  • Spack tries to find if any of the dependencies of nano with the same or different version is already installed. In this example, Spack finds ncurses@6.1 already built. Therefore, it won’t install ncurses@6.2. It has reused ncurses@6.1