---
title: Spack | zh
tags: Guide, TWNIA3, TW
GA:
---
<div style="text-align: right">更新日期:2024/11/10</div>
# Spack
[TOC]
## 簡介
[Spack](https://spack.io/)是由[LLNL](https://www.llnl.gov/)發展的一個套件管理工具,處理安裝各種HPC領域常用的編譯器、函式庫、科學計算軟體編譯設定與相依性,除了LLNL本身的維護外,亦由世界各大HPC單位組織和廠商支持贊助,目前累計各式軟體、函式庫版本超過6800。
國網中心的計算主機系統的用戶來自許多不同領域,執行各式各樣的計算工作,即使是使用相同的軟體,也可能有不同的設定需求,囿於有限的人力資源,無法即時提供完整的軟體安裝協助,因此可依照個人需求選項,自行安裝設定軟體的Spack對HPC用戶就顯得相當實用。
## 設定使用
### 安裝與設定
1. 登入主機執行git取得spack
[demo_user@lgn302 ~]$ git clone -c feature.manyFiles=true https://github.com/spack/spack.git
```
Cloning into 'spack'...
remote: Enumerating objects: 507890, done.
remote: Counting objects: 100% (3199/3199), done.
remote: Compressing objects: 100% (2008/2008), done.
remote: Total 507890 (delta 547), reused 1888 (delta 405), pack-reused 504691
Receiving objects: 100% (507890/507890), 169.26 MiB | 22.69 MiB/s, done.
Resolving deltas: 100% (238331/238331), done.
Updating files: 100% (11129/11129), done.
```
:::info
git於目前目錄建立一個名稱為spack的目錄
:::
2. 設定spack環境變數
[demo_user@lgn302 ~]$ . ~/spack/share/spack/setup-env.sh
或
[demo_user@lgn302 ~]$ source ~/spack/share/spack/setup-env.sh
:::info
此為設定spack相關環境變數,正常情況不會有任何輸出,至此已完成spack設定可以開始利用spack指令搜尋、安裝軟體與library。
:::
3. 日後更新
[demo_user@lgn302 ~]$ cd spack
[demo_user@lgn302 spack]$ git pull
:::spoiler 輸出範例
```
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:
git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only
You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.
remote: Enumerating objects: 4128, done.
remote: Counting objects: 100% (2484/2484), done.
remote: Compressing objects: 100% (288/288), done.
remote: Total 4128 (delta 2186), reused 2371 (delta 2107), pack-reused 1644
Receiving objects: 100% (4128/4128), 2.29 MiB | 30.42 MiB/s, done.
Resolving deltas: 100% (2346/2346), completed with 586 local objects.
From https://github.com/spack/spack
5f58a4c079..0960f691a1 develop -> origin/develop
* [new branch] backports/v0.21.2 -> origin/backports/v0.21.2
* [new branch] bugfix/compiler-flag-propagation -> origin/bugfix/compiler-flag-propagation
* [new branch] bugfix/patches-across-repos -> origin/bugfix/patches-across-repos
* [new branch] dependabot/github_actions/actions/upload-artifact-4.3.1 -> origin/dependabot/github_actions/actions/upload-artifact-4.3.1
* [new branch] e4s-24.02 -> origin/e4s-24.02
fea922e92e..7b5e468a5b features/read-compilers-from-packages-yaml -> origin/features/read-compilers-from-packages-yaml
4d5a4a13a5..233db21d20 gartung-buildcache-check-fix -> origin/gartung-buildcache-check-fix
* [new branch] improve-find-in-env -> origin/improve-find-in-env
* [new branch] install-status-format -> origin/install-status-format
78680aad1b..02cb7ede49 llnl/radiuss-packages-update-start-over -> origin/llnl/radiuss-packages-update-start-over
* [new branch] packages/pythia6-dead-hepforge -> origin/packages/pythia6-dead-hepforge
+ d21f421e44...f672f7d753 solver-setup-type-annotations -> origin/solver-setup-type-annotations (forced update)
* [new branch] task/2024_02_add_conduit_0.9.0_release -> origin/task/2024_02_add_conduit_0.9.0_release
* [new tag] develop-2024-01-21 -> develop-2024-01-21
* [new tag] develop-2024-01-28 -> develop-2024-01-28
* [new tag] develop-2024-02-04 -> develop-2024-02-04
Updating 5f58a4c079..0960f691a1
Updating files: 100% (598/598), done.
Fast-forward
.github/pull_request_template.md | 6 +
.github/workflows/audit.yaml | 2 +-
.github/workflows/build-containers.yml | 4 +-
.github/workflows/ci.yaml | 2 +-
...(略)...
```
:::
<!--
3. 關閉安裝預先編譯二進位檔的選項
[demo_user@lgn302 ~]$ spack bootstrap disable
```
==> Bootstrapping has been disabled
```
:::info
非必要選項,可確保安裝之軟體非預先編譯的二進位檔
:::
-->
### spack基本指令說明
所有的指令都支援使用Tab鍵補齊,包含指令與keyword(package name)都可以。
* list
列出軟體/函式庫。不加任何keyword,則列出全部;keyword可為完整字串或部分字元。如:spack list mpi
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack list <--列出當時spack所有的package
3dtk parquet-format py-sierrapy
3proxy parsec py-simpervisor
7zip parsimonator py-simpleeval
abacus parsplice py-simplegeneric
abduco pasta py-simplejson
abi-compliance-checker pastix py-simplekml
....
parmmg py-shroud zziplib
parquet-cpp py-shtab
==> 7616 packages
[demo_user@lgn302 ~]$ spack list gcc <--列出包含gcc字眼的package
armpl-gcc gcc gcc-runtime gccmakedep gccxml
==> 5 packages
[demo_user@lgn302 ~]$ spack list intel <--列出包含intel字眼的package
intel intel-mkl intel-oneapi-compilers-classic intel-oneapi-ipp intel-oneapi-vpl py-intel-openmp
intel-daal intel-mpi intel-oneapi-dal intel-oneapi-ippcp intel-oneapi-vtune
intel-gpu-tools intel-mpi-benchmarks intel-oneapi-dnn intel-oneapi-itac intel-parallel-studio
intel-gtpin intel-oneapi-advisor intel-oneapi-dpct intel-oneapi-mkl intel-pin
intel-ipp intel-oneapi-ccl intel-oneapi-dpl intel-oneapi-mpi intel-tbb
intel-llvm intel-oneapi-compilers intel-oneapi-inspector intel-oneapi-tbb intel-xed
==> 31 packages
[demo_user@lgn302 ~]$ spack list mpi <--列出包含mpi字眼的package
compiz intel-oneapi-compilers mpich mpiwrapper pnmpi rkt-compiler-lib
cray-mpich intel-oneapi-compilers-classic mpifileutils mpix-launch-swift py-dask-mpi spectrum-mpi
exempi intel-oneapi-mpi mpilander msmpi py-mpi4jax spiral-package-mpi
fujitsu-mpi mpi-bash mpileaks openmpi py-mpi4py sst-dumpi
hpcx-mpi mpi-serial mpip pbmpi py-tempita umpire
intel-mpi mpi-test-suite mpir perl-params-validationcompiler r-rmpi vampirtrace
intel-mpi-benchmarks mpibind mpitrampoline phylobayesmpi rempi wi4mpi
==> 42 packages
```
:::
* info
查詢軟體相關資訊,包含有哪些版本、安裝選項、相依軟體、函式庫、...
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack info intel-oneapi-mpi <--列出intel-oneapi-mpi相關資訊
Package: intel-oneapi-mpi
Description:
Intel MPI Library is a multifabric message-passing library that
implements the open-source MPICH specification. Use the library to
create, maintain, and test advanced, complex applications that perform
better on high-performance computing (HPC) clusters based on Intel
processors. LICENSE INFORMATION: By downloading and using this software,
you agree to the terms and conditions of the software license agreements
at https://intel.ly/393CijO.
Homepage: https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/mpi-library.html
Preferred version: <--未指定版本時的預設安裝版本
2021.11.0 https://registrationcenter-download.intel.com/akdlm//IRC_NAS/2c45ede0-623c-4c8e-9e09-bed27d70fa33/l_mpi_oneapi_p_2021.11.0.49513_offline.sh
Safe versions:
2021.11.0 https://registrationcenter-download.intel.com/akdlm//IRC_NAS/2c45ede0-623c-4c8e-9e09-bed27d70fa33/l_mpi_oneapi_p_2021.11.0.49513_offline.sh
2021.10.0 https://registrationcenter-download.intel.com/akdlm/IRC_NAS/4f5871da-0533-4f62-b563-905edfb2e9b7/l_mpi_oneapi_p_2021.10.0.49374_offline.sh
2021.9.0 https://registrationcenter-download.intel.com/akdlm/IRC_NAS/718d6f8f-2546-4b36-b97b-bc58d5482ebf/l_mpi_oneapi_p_2021.9.0.43482_offline.sh
2021.8.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/19131/l_mpi_oneapi_p_2021.8.0.25329_offline.sh
2021.7.1 https://registrationcenter-download.intel.com/akdlm/irc_nas/19010/l_mpi_oneapi_p_2021.7.1.16815_offline.sh
2021.7.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/18926/l_mpi_oneapi_p_2021.7.0.8711_offline.sh
2021.6.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/18714/l_mpi_oneapi_p_2021.6.0.602_offline.sh
2021.5.1 https://registrationcenter-download.intel.com/akdlm/irc_nas/18471/l_mpi_oneapi_p_2021.5.1.515_offline.sh
2021.5.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/18370/l_mpi_oneapi_p_2021.5.0.495_offline.sh
2021.4.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/18186/l_mpi_oneapi_p_2021.4.0.441_offline.sh
2021.3.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/17947/l_mpi_oneapi_p_2021.3.0.294_offline.sh
2021.2.0 https://registrationcenter-download.intel.com/akdlm/irc_nas/17729/l_mpi_oneapi_p_2021.2.0.215_offline.sh
2021.1.1 https://registrationcenter-download.intel.com/akdlm/irc_nas/17397/l_mpi_oneapi_p_2021.1.1.76_offline.sh
Deprecated versions:
None
Variants:
build_system [generic] generic
Build systems supported by the package
envmods [true] false, true
Toggles environment modifications
external-libfabric [false] false, true
Enable external libfabric dependency
generic-names [false] false, true
Use generic names, e.g mpicc instead of mpiicc
ilp64 [false] false, true
Build with ILP64 support
Build Dependencies:
None
Link Dependencies:
libfabric
Run Dependencies:
libfabric
Licenses:
None
```
:::
* versions
顯示軟體版本,包含safe versions(source chechsum驗證)與未經checksum的版本。
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack versions intel-oneapi-mpi
==> Safe versions (already checksummed):
2021.11.0 2021.10.0 2021.9.0 2021.8.0 2021.7.1 2021.7.0 2021.6.0 2021.5.1 2021.5.0 2021.4.0 2021.3.0 2021.2.0 2021.1.1
==> Remote versions (not yet checksummed):
19131 18926 18471 18186 17729 718d6f8f-2546-4b36-b97b-bc58d5482ebf 2c45ede0-623c-4c8e-9e09-bed27d70fa33
19010 18714 18370 17947 17397 4f5871da-0533-4f62-b563-905edfb2e9b7
```
:::
* install
安裝spack list所列出的packages,除了最新版本外,亦可指定先前版本、指定編譯器、MPI種類、版本等組合
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack install intel-oneapi-mpi
==> Fetching https://mirror.spack.io/bootstrap/github-actions/v0.5/build_cache/linux-centos7-x86_64-gcc-10.2.1-patchelf-0.18.0-afv7arjarb7nzmlh7c5slkfxykybuqce.spec.json
==> Fetching https://mirror.spack.io/bootstrap/github-actions/v0.5/build_cache/linux-centos7-x86_64/gcc-10.2.1/patchelf-0.18.0/linux-centos7-x86_64-gcc-10.2.1-patchelf-0.18.0-afv7arjarb7nzmlh7c5slkfxykybuqce.spack
==> Installing "patchelf@=0.18.0%gcc@=10.2.1 ldflags='-static-libstdc++ -static-libgcc' build_system=autotools arch=linux-centos7-x86_64" from a buildcache
==> Fetching https://mirror.spack.io/bootstrap/github-actions/v0.5/build_cache/linux-centos7-x86_64-gcc-10.2.1-clingo-bootstrap-spack-t4yf34cuvquqp5xd66zybmcfyhwbdlsf.spec.json
==> Fetching https://mirror.spack.io/bootstrap/github-actions/v0.5/build_cache/linux-centos7-x86_64/gcc-10.2.1/clingo-bootstrap-spack/linux-centos7-x86_64-gcc-10.2.1-clingo-bootstrap-spack-t4yf34cuvquqp5xd66zybmcfyhwbdlsf.spack
==> Installing "clingo-bootstrap@=spack%gcc@=10.2.1~docs+ipo+optimized+python+static_libstdcpp build_system=cmake build_type=Release generator=make patches=bebb819,ec99431 arch=linux-centos7-x86_64" from a buildcache
==> Installing gcc-runtime-8.5.0-ifampldlu2tf3ukzkt3yctwksoevqveh [1/2]
==> No binary for gcc-runtime-8.5.0-ifampldlu2tf3ukzkt3yctwksoevqveh found: installing from source
==> No patches needed for gcc-runtime
==> gcc-runtime: Executing phase: 'install'
==> gcc-runtime: Successfully installed gcc-runtime-8.5.0-ifampldlu2tf3ukzkt3yctwksoevqveh
Stage: 0.00s. Install: 0.21s. Post-install: 0.04s. Total: 0.27s
[+] /home/demo_user/spack/opt/spack/linux-rocky8-skylake_avx512/gcc-8.5.0/gcc-runtime-8.5.0-ifampldlu2tf3ukzkt3yctwksoevqveh
==> Installing intel-oneapi-mpi-2021.11.0-2bmu5dpvks5lutv4ncrp2zncrdqg5hwx [2/2]
==> No binary for intel-oneapi-mpi-2021.11.0-2bmu5dpvks5lutv4ncrp2zncrdqg5hwx found: installing from source
==> Fetching https://registrationcenter-download.intel.com/akdlm//IRC_NAS/2c45ede0-623c-4c8e-9e09-bed27d70fa33/l_mpi_oneapi_p_2021.11.0.49513_offline.sh
==> No patches needed for intel-oneapi-mpi
==> intel-oneapi-mpi: Executing phase: 'install'
==> intel-oneapi-mpi: Successfully installed intel-oneapi-mpi-2021.11.0-2bmu5dpvks5lutv4ncrp2zncrdqg5hwx
Stage: 11.71s. Install: 17.10s. Post-install: 1.47s. Total: 30.31s
[+] /home/demo_user/spack/opt/spack/linux-rocky8-skylake_avx512/gcc-8.5.0/intel-oneapi-mpi-2021.11.0-2bmu5dpvks5lutv4ncrp2zncrdqg5hwx
```
```
[demo_user@lgn302 ~]$ spack install intel-oneapi-mpi@2021.10.0 <--指定版本
[+] /home/demo_user/spack/opt/spack/linux-rocky8-skylake_avx512/gcc-8.5.0/gcc-runtime-8.5.0-ifampldlu2tf3ukzkt3yctwksoevqveh
==> Installing intel-oneapi-mpi-2021.10.0-oz7nkbp427zs4agas6huuiyloafbmcq2 [2/2]
==> No binary for intel-oneapi-mpi-2021.10.0-oz7nkbp427zs4agas6huuiyloafbmcq2 found: installing from source
==> Fetching https://registrationcenter-download.intel.com/akdlm/IRC_NAS/4f5871da-0533-4f62-b563-905edfb2e9b7/l_mpi_oneapi_p_2021.10.0.49374_offline.sh
==> No patches needed for intel-oneapi-mpi
==> intel-oneapi-mpi: Executing phase: 'install'
==> intel-oneapi-mpi: Successfully installed intel-oneapi-mpi-2021.10.0-oz7nkbp427zs4agas6huuiyloafbmcq2
Stage: 13.32s. Install: 15.99s. Post-install: 1.43s. Total: 30.77s
[+] /home/demo_user/spack/opt/spack/linux-rocky8-skylake_avx512/gcc-8.5.0/intel-oneapi-mpi-2021.10.0-oz7nkbp427zs4agas6huuiyloafbmcq2
```
:::
* find
列出已透過spack安裝的package
:::spoiler 範例
```
[spiraea7@lgn302 ~]$ spack find
-- linux-rocky8-skylake_avx512 / gcc@8.5.0 ----------------------
gcc-runtime@8.5.0 intel-oneapi-mpi@2021.10.0 intel-oneapi-mpi@2021.11.0
==> 3 installed packages
```
:::
* uninstall
移除已安裝的package,若有不同的版本,須指定版本。
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack uninstall intel-oneapi-mpi@2021.10.0
-- linux-rocky8-skylake_avx512 / gcc@8.5.0 ----------------------
oz7nkbp intel-oneapi-mpi@2021.10.0
==> 1 packages will be uninstalled. Do you want to proceed? [y/N] y
==> Successfully uninstalled intel-oneapi-mpi@2021.10.0%gcc@8.5.0+envmods~external-libfabric~generic-names~ilp64 build_system=generic arch=linux-rocky8-skylake_avx512/oz7nkbp
```
```
[demo_user@lgn302 ~]$ spack uninstall intel-oneapi-mpi
-- linux-rocky8-skylake_avx512 / gcc@8.5.0 ----------------------
2bmu5dp intel-oneapi-mpi@2021.11.0
==> 1 packages will be uninstalled. Do you want to proceed? [y/N] y
==> Successfully uninstalled intel-oneapi-mpi@2021.11.0%gcc@8.5.0+envmods~external-libfabric~generic-names~ilp64 build_system=generic arch=linux-rocky8-skylake_avx512/2bmu5dp
```
:::
* compiler
add/find 搜尋並加入PATH中可用的編譯器
info 列出編譯器路徑、module、OS等相關資訊
list 等同 compilers,列出可用的編譯器
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack compiler list
==> Available compilers
-- dpcpp rocky8-x86_64 ------------------------------------------
dpcpp@2024.0.2
-- gcc rocky8-x86_64 --------------------------------------------
gcc@8.5.0
-- intel rocky8-x86_64 ------------------------------------------
intel@2021.11.1
-- oneapi rocky8-x86_64 -----------------------------------------
oneapi@2024.0.2
```
```
[demo_user@lgn302 ~]$ spack compiler info oneapi@2024.0.2
oneapi@2024.0.2:
paths:
cc = /opt/ohpc/Taiwania3/pkg/intel/2024/oneapi/compiler/2024.0/bin/icx
cxx = /opt/ohpc/Taiwania3/pkg/intel/2024/oneapi/compiler/2024.0/bin/icpx
f77 = /opt/ohpc/Taiwania3/pkg/intel/2024/oneapi/compiler/2024.0/bin/ifx
fc = /opt/ohpc/Taiwania3/pkg/intel/2024/oneapi/compiler/2024.0/bin/ifx
modules = []
operating system = rocky8
```
```
[demo_user@lgn302 ~]$ ml gcc
[demo_user@lgn302 ~]$ spack compiler find
==> Added 1 new compiler to /home/demo_user/.spack/linux/compilers.yaml
gcc@13.2.0
==> Compilers are defined in the following files:
/home/demo_user/.spack/linux/compilers.yaml
[demo_user@lgn302 ~]$ spack compiler info gcc@13.2.0
gcc@13.2.0:
paths:
cc = /opt/ohpc/Taiwania3/Intel/pkg/gcc/13.2.0/bin/gcc
cxx = /opt/ohpc/Taiwania3/Intel/pkg/gcc/13.2.0/bin/g++
f77 = /opt/ohpc/Taiwania3/Intel/pkg/gcc/13.2.0/bin/gfortran
fc = /opt/ohpc/Taiwania3/Intel/pkg/gcc/13.2.0/bin/gfortran
modules = []
operating system = rocky8
```
:::
* compilers
等同compiler list,列出可用編譯器。
:::spoiler 範例
```
[demo_user@lgn302 ~]$ spack compilers
==> Available compilers
-- dpcpp rocky8-x86_64 ------------------------------------------
dpcpp@2024.0.2
-- gcc rocky8-x86_64 --------------------------------------------
gcc@8.5.0 gcc@13.2.0
-- intel rocky8-x86_64 ------------------------------------------
intel@2021.11.1
-- oneapi rocky8-x86_64 -----------------------------------------
oneapi@2024.0.2
```
:::
### 安裝軟體
以安裝gcc 13.1.0為例
* @:指定版本,如gcc@13.1.0
* %:指定編譯器,如 %gcc@8.5.0
* +、-、~:啟用或關閉選項(布林值屬性的選項),其值如true/false、enable/disable的參數選項
* name=<value>:非布林屬性的選項,如build_type=Release
* ^:相依套件的spec
```
[demo_user@lgn302 ~]$ spack install gcc @13.1.0%gcc@8.5.0 build_type=Release +graphite
[+] /usr (external diffutils-3.6-rlm3yakysnl6owva6nnkin3gmrez57zg)
[+] /usr (external gawk-4.2.1-atcivfoublwnzdqb57jljwdnncgv6upj)
...(略)
==> Installing gcc-13.1.0-cdw4nvh6mbehmg4h77kbs62e2mwtjv7y [24/24]
==> No binary for gcc-13.1.0-cdw4nvh6mbehmg4h77kbs62e2mwtjv7y found: installing from source
==> Fetching https://mirror.spack.io/_source-cache/archive/61/61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86.tar.xz
==> Ran patch() for gcc
==> gcc: Executing phase: 'autoreconf'
==> gcc: Executing phase: 'configure'
==> gcc: Executing phase: 'build'
==> gcc: Executing phase: 'install'
==> gcc: Successfully installed gcc-13.1.0-cdw4nvh6mbehmg4h77kbs62e2mwtjv7y
Stage: 12.20s. Autoreconf: 0.00s. Configure: 3.27s. Build: 18m 7.01s. Install: 7.10s. Post-install: 1.76s. Total: 18m 31.53s
[+] /home/demo_user/spack/opt/spack/linux-rocky8-skylake_avx512/gcc-8.5.0/gcc-13.1.0-cdw4nvh6mbehmg4h77kbs62e2mwtjv7y
```
### 如何使用既有的編譯器與函式庫透過Spaack安裝軟體
待補
## 參考連結
* [Spack文件](https://spack.readthedocs.io/en/latest/)
* [Spack support of HPC applications](https://developer.amd.com/spack/)