|
| 1 | +# Important Spack Features |
| 2 | + |
| 3 | +## Spack Specs |
| 4 | + |
| 5 | +In Spack the idea of a _spec_ is very important. Specs are descriptors of particular aspects or configurations of a package or packages. |
| 6 | +Specs can completely general, merely denoted the name of a package, or they can very specific such as specifying the name of the package with a particular version, with a particular compiler and compiler version, with specific options called _variants_, as well as constraints on dependencies of the package. |
| 7 | +Spack's documentation has much more information on specs [here](https://spack.readthedocs.io/en/latest/basic_usage.html#specs-dependencies), but we summarize them here as it is important to utilizing Spack. |
| 8 | +Specs are a loose or general form of a configuration for a package. However, Spack is very exact it how it will build and satisfy your requested spec. |
| 9 | +It does this through the process of _concretization_. Concretization maps a spec, no matter how general or specific, into an _exact_ graph of |
| 10 | +how Spack will build and fulfill the spec. A command for understanding this process is the `spack spec` command. Using `spack spec` |
| 11 | +will report to the user how Spack will create a concrete graph or DAG of the package on its dependencies. For example: |
| 12 | + |
| 13 | +``` |
| 14 | +% spack spec zlib |
| 15 | +Input spec |
| 16 | +-------------------------------- |
| 17 | +zlib |
| 18 | +
|
| 19 | +Concretized |
| 20 | +-------------------------------- |
| 21 | +zlib@1.2.11%apple-clang@12.0.0+optimize+pic+shared arch=darwin-catalina-skylake |
| 22 | +``` |
| 23 | + |
| 24 | +Here we intend to install the zlib package which has no dependencies. If we specify nothing but `zlib`, this is the configuration Spack has solved |
| 25 | +in which it will fulfill the installation of zlib. We can be more specific about our request. Looking at what compilers are available for us in Spack |
| 26 | +we can use: |
| 27 | +``` |
| 28 | +% spack compilers |
| 29 | +==> Available compilers |
| 30 | +-- apple-clang catalina-x86_64 ---------------------------------- |
| 31 | +apple-clang@12.0.0 |
| 32 | +
|
| 33 | +-- gcc catalina-x86_64 ------------------------------------------ |
| 34 | +gcc@11.2.0 |
| 35 | +``` |
| 36 | + |
| 37 | +Here we are on a MacOS computer and we have two compilers available. If I prefer `zlib` be installed using gcc, one can use: |
| 38 | +``` |
| 39 | +% spack spec zlib%gcc |
| 40 | +Input spec |
| 41 | +-------------------------------- |
| 42 | +zlib%gcc |
| 43 | +
|
| 44 | +Concretized |
| 45 | +-------------------------------- |
| 46 | +zlib@1.2.11%gcc@11.2.0+optimize+pic+shared arch=darwin-catalina-skylake |
| 47 | +``` |
| 48 | + |
| 49 | +Notice Spack honored our compiler constraint request. Spack reports the concretized spec in a manner that continues to itself be a spec: |
| 50 | +``` |
| 51 | +% spack spec zlib@1.2.11%gcc@11.2.0+optimize+pic+shared arch=darwin-catalina-skylake |
| 52 | +Input spec |
| 53 | +-------------------------------- |
| 54 | +zlib@1.2.11%gcc@11.2.0+optimize+pic+shared arch=darwin-catalina-skylake |
| 55 | +
|
| 56 | +Concretized |
| 57 | +-------------------------------- |
| 58 | +zlib@1.2.11%gcc@11.2.0+optimize+pic+shared arch=darwin-catalina-skylake |
| 59 | +``` |
| 60 | + |
| 61 | +Therefore using the `spec` command helps us to understand specs and what Spack will do with a spec before we use them in other commands. |
| 62 | +Here is an example of a more complicated package: |
| 63 | +``` |
| 64 | +% spack spec amr-wind |
| 65 | +Input spec |
| 66 | +-------------------------------- |
| 67 | +amr-wind |
| 68 | +
|
| 69 | +Concretized |
| 70 | +-------------------------------- |
| 71 | +amr-wind@main%apple-clang@12.0.0~cuda~fortran+hypre+internal-amrex~ipo~masa+mpi+netcdf~openfast~openmp~rocm+shared+tests+unit build_type=Release arch=darwin-catalina-skylake |
| 72 | + ^cmake@3.22.2%apple-clang@12.0.0~doc+ncurses+openssl+ownlibs~qt build_type=Release arch=darwin-catalina-skylake |
| 73 | + ^ncurses@6.2%apple-clang@12.0.0~symlinks+termlib abi=none arch=darwin-catalina-skylake |
| 74 | + ^pkgconf@1.8.0%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 75 | + ^openssl@1.1.1m%apple-clang@12.0.0~docs certs=system arch=darwin-catalina-skylake |
| 76 | + ^perl@5.34.0%apple-clang@12.0.0+cpanm+shared+threads arch=darwin-catalina-skylake |
| 77 | + ^berkeley-db@18.1.40%apple-clang@12.0.0+cxx~docs+stl patches=b231fcc4d5cff05e5c3a4814f6a5af0e9a966428dc2176540d2c05aff41de522 arch=darwin-catalina-skylake |
| 78 | + ^bzip2@1.0.8%apple-clang@12.0.0~debug~pic+shared arch=darwin-catalina-skylake |
| 79 | + ^diffutils@3.8%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 80 | + ^libiconv@1.16%apple-clang@12.0.0 libs=shared,static arch=darwin-catalina-skylake |
| 81 | + ^gdbm@1.19%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 82 | + ^readline@8.1%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 83 | + ^zlib@1.2.11%apple-clang@12.0.0+optimize+pic+shared arch=darwin-catalina-skylake |
| 84 | + ^hypre@2.23.0%apple-clang@12.0.0~complex~cuda~debug+int64~internal-superlu~mixedint+mpi~openmp+shared~superlu-dist~unified-memory arch=darwin-catalina-skylake |
| 85 | + ^netlib-lapack@3.9.1%apple-clang@12.0.0~external-blas~ipo+lapacke+shared~xblas build_type=Release arch=darwin-catalina-skylake |
| 86 | + ^openmpi@4.1.2%apple-clang@12.0.0~atomics~cuda~cxx~cxx_exceptions+gpfs~internal-hwloc~java~legacylaunchers~lustre~memchecker~pmi~pmix+romio~singularity~sqlite3+static~thread_multiple+vt+wrapper-rpath fabrics=none schedulers=none arch=darwin-catalina-skylake |
| 87 | + ^hwloc@2.7.0%apple-clang@12.0.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~opencl~pci~rocm+shared arch=darwin-catalina-skylake |
| 88 | + ^libxml2@2.9.12%apple-clang@12.0.0~python arch=darwin-catalina-skylake |
| 89 | + ^xz@5.2.5%apple-clang@12.0.0~pic libs=shared,static arch=darwin-catalina-skylake |
| 90 | + ^libevent@2.1.12%apple-clang@12.0.0+openssl arch=darwin-catalina-skylake |
| 91 | + ^openssh@8.8p1%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 92 | + ^libedit@3.1-20210216%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 93 | + ^netcdf-c@4.7.4%apple-clang@12.0.0~dap~fsync~hdf4~jna+mpi+parallel-netcdf+pic+shared patches=2c88dfbd6d339a0336a43b14a65a1d1df995b853b645e4af612617612a642a53 arch=darwin-catalina-skylake |
| 94 | + ^hdf5@1.10.7%apple-clang@12.0.0+cxx~fortran+hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_type=RelWithDebInfo patches=2a1e3118d7d3d7411820e567b03530de96a46385304017f8e548408aa1cfbfc0 arch=darwin-catalina-skylake |
| 95 | + ^m4@1.4.19%apple-clang@12.0.0+sigsegv patches=9dc5fbd0d5cb1037ab1e6d0ecc74a30df218d0a94bdd5a02759a97f62daca573,bfdffa7c2eb01021d5849b36972c069693654ad826c1a20b53534009a4ec7a89 arch=darwin-catalina-skylake |
| 96 | + ^libsigsegv@2.13%apple-clang@12.0.0 arch=darwin-catalina-skylake |
| 97 | + ^parallel-netcdf@1.12.2%apple-clang@12.0.0~burstbuffer+cxx+fortran+pic+shared arch=darwin-catalina-skylake |
| 98 | +``` |
| 99 | + |
| 100 | +It is obvious concretized specs can get large quite quickly. However, Spack is very good at standing on it's own without requirements |
| 101 | +from the existing system. Therefore it can be quite straightforward to build complicated packages on many machines. However, it can also be argued |
| 102 | +that this situation involves many packages with Spack will build that may already exist on the machine. While this is fair, we typically solve |
| 103 | +this by specifying `externals` which make Spack aware of packages already existing on the system and utilizing them in its DAG. Spack-manager |
| 104 | +has machine-specific configurations provided by its contributors for this purpose. Obtaining a configuration for Spack for the specific machine |
| 105 | +and specific project will save the user of Spack a lot of time. |
| 106 | + |
| 107 | +In our previous concretized DAG, `amr-wind` has dependencies on packages. Dependencies in specs are denoted with `^`. We can use this to constrain dependencies we would like to request. |
| 108 | +For example here we put a constraint on the cmake version: |
| 109 | +``` |
| 110 | +% spack spec amr-wind ^cmake@3.17.0 |
| 111 | +Input spec |
| 112 | +-------------------------------- |
| 113 | +amr-wind |
| 114 | + ^cmake@3.17.0 |
| 115 | +
|
| 116 | +Concretized |
| 117 | +-------------------------------- |
| 118 | +amr-wind@main%apple-clang@12.0.0~cuda~fortran+hypre+internal-amrex~ipo~masa+mpi+netcdf~openfast~openmp~rocm+shared+tests+unit build_type=Release arch=darwin-catalina-skylake |
| 119 | + ^cmake@3.17.0%apple-clang@12.0.0~doc+ncurses+openssl+ownlibs~qt build_type=Release patches=1c540040c7e203dd8e27aa20345ecb07fe06570d56410a24a266ae570b1c4c39,bf695e3febb222da2ed94b3beea600650e4318975da90e4a71d6f31a6d5d8c3d,e51119dd387aa3eb2f21fee730d3aa8b5480301c5e2e3a33bd86f4f7d8903861 arch=darwin-catalina-skylake |
| 120 | + ^ncurses@6.2%apple-clang@12.0.0~symlinks+termlib abi=none arch=darwin-catalina-skylake |
| 121 | +... |
| 122 | +``` |
| 123 | +Concretization is an NP-hard problem, so solving the DAG is not instantaneous, and it is very much an active area of research. Spack has |
| 124 | +gone through one iteration thus far of updating its concretization strategy. This is the difference between the "original" concretizer and the newer clingo concretizer. |
| 125 | + |
| 126 | +Another important idea in Spack is describing the configuration of a particular package involving a complicated DAG into a succint string for the installation directory of the package for example. To do this, Spack collapses several properties of the DAG into a _hash_. Spack then uses this hash to provide a short form mapping for a particular package and its full description. Spack is a very powerful database of software installations and can be queried to understand the exact state of each package and pinpointing a specific package in which the user is interested. We leave these to the Spack documentation to continue. |
| 127 | + |
| 128 | + |
| 129 | +## Spack Commands |
| 130 | + |
| 131 | +Spack has many commands, many of which have great information when adding `-h` to them. Here we list a few of the most important commands for using within Spack-Manager. |
| 132 | + |
| 133 | + - `spack spec -I <spec> `: solve the DAG for the spec and show packages in the DAG that are already installed |
| 134 | + - `spack location -i <spec> `: used for finding the specific location of an installed package |
| 135 | + - `spack concretize -f `: force an activated environment to undergo concretization |
| 136 | + - `spack install `: install all packages listed in an environment's `spack.yaml` file |
| 137 | + - `spack uninstall <spec>`: uninstall specific spec |
| 138 | + - `spack uninstall --dependencies -a -y <spec>`: uninstall everything related to a general spec (`-a`) and all its dependencies without confirming |
| 139 | + - `spack cd -b <spec> `: change to build directory of package |
| 140 | + - `spack env activate -d <path> ` or `spacktivate -d <path>`: activate a Spack environment at specified path |
| 141 | + - `spack develop <spec> `: develop source code in a package locally |
| 142 | + - `spack help --all `: list all available Spack commands |
| 143 | + - `spack list <string>`: list all available Spack packages matching the string |
| 144 | + - `spack find <spec>`: query Spack's database of installed packages |
| 145 | + - `spack find -Lvd <spec>`: list the hashes, variants, and dependencies of the provided spec |
| 146 | + - `spack stage <spec> && spack cd <spec>`: download the package's source code and extract it for browsing |
| 147 | + - `spack docs`: open the online spack documentation in a browser |
| 148 | + - `spack -d <spack subcommand>`: get debug info on exactly what Spack is doing when it fails |
| 149 | + - `spack config blame packages`: show exactly where Spack is obtaining its preferences for things like concretization |
| 150 | + - `spack compilers`: list the compilers in which Spack is aware |
| 151 | + |
| 152 | + |
| 153 | +## Spack Knowledgebase |
| 154 | + |
| 155 | +In each package installation directory in `spack/opt` Spack keeps a `.spack` directory which contains information on exactly how the package was built. |
0 commit comments