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
zlibsoftware, you simply type:spack install zilbFor 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 installzlibpackage usinggcccompiler, 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
zlibas 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.2.4.3 1.2.3.6 1.2.2.3 1.2.0.8 1.2.0.1 1.0.9 1.0.1 0.91 1.2.9 1.2.5.3 1.2.4.2 1.2.3.5 1.2.2.2 1.2.0.7 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 version1.2.11ofzlib, you type:spack install zlib@1.2.11 -
If you want to use the version
4.8.5of thegcccompiler when installing the version1.2.11ofzlib, you type:spack install zlib@1.2.11 %gcc@4.8.5If 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, andldlibsflags. 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
-O3flag. This can be accomplished by specifying the value ofcppflagsin 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
tclpackage depends on thezlibpackage. Suppose you want to use a specific version ofzlibas 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
tcland its dependencyzlibat the version1.2.8.
Changing Build Options
-
Spack packages can also have build options, called variants. Some variants may be boolean where they can be
TrueorFalse. They can be specified using the+forTrueand~or-forFalse. Variants (boolean or otherwise) can also be specified using the same syntax as compiler flags. -
For example, the default version of the
HDF5package is installed withMPIsupport. Suppose you want to install its serial version, you need to disable theMPIsupport. This can be accomplished by making thempivariantFalseas follows:spack install hdf5~mpi -
There are other packages that provide the
MPIinterface such asopenmpi, mpich,andmvapich. You might want to install a package with a differentMPIimplementation. Spack handles these throughvirtual dependencies. For instance,HDF5can depend on theMPIinterface. -
If you would like to change the
MPIsupport ofHDF5toopenmi, 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 thespecof 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--reuseoption to thespack installcommand. -
For example, the
nanopackage depends on thencurses@6.2package. Suppose you have installedncurses@6.1before, and you want to installnanoas follows:spack install nano -
Spack will install
ncurses@6.2and all other dependencies ofnano, and then it will install the package. This means that two versions ofncursesare installed. -
Instead of installing
ncurses@6.2as a dependency, you can force Spack to use the already installed version ofncurses (ncurses@6.1). To do so you type:spack install --reuse nano -
Spack tries to find if any of the dependencies of
nanowith the same or different version is already installed. In this example, Spack findsncurses@6.1already built. Therefore, it won’t installncurses@6.2. It has reusedncurses@6.1