Customizing Compilers
-
Spack doesn’t come with any compiler. To add a compiler you type:
spack compiler add -
This will add the default compiler
gcc@4.8.0that comes with thecentos7. Now you can use the compiler to install another packages.
Listing Available Compilers
-
To list available compilers, you simply type:
spack compilers -
This will show all available compilers that you can use when installing packages. For example, the following output shows that there is only one available compiler.
==> Available compilers -- gcc centos7-x86_64 ------------------------------------------- gcc@4.8.5The
spack compilerscommand is an alias for the commandspack compiler list.
Adding a Compiler to Spack
-
To add a compiler to Spack, you need to make sure that the compiler is installed. Suppose that you need to add
gccat version7.1.0. This compiler hasn’t been installed, so you need to install it using the following command:spack install gcc@7.1.0 -
To make sure that
gccat version7.1.0has been installed successfully, type:spack find -p gcc -
The flag
-pis to show paths to the installed package directories. The following output shows that the compiler has been installed successfully.==> 2 installed packages -- linux-centos7-x86_64 / gcc@4.8.5 ----------------------------- gcc@9.3.0 /home/tahat/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/gcc-9.3.0-vxq35mmyzthsbvcdkikwpnkexqj4h3hx -- linux-centos7-x86_64 / gcc@9.3.0 ----------------------------- gcc@7.1.0 /home/tahat/spack/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp -
To add a compiler as an available compiler, use the
spack compiler addcommand.spack compiler add <location> -
Location is the location of the installed compiler. To print the location of the
gcc@8.3.0compiler, type:spack location -i gcc@7.1.0output:
/home/tahat/spack/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp -
You can add
gccgcc@7.1.0to Spack as an available compiler using thespack compiler addcommand. This will allow future packages to build withgcc@7.1.0.spack compiler add /home/tahat/spack/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp -
The following output shows that
gcc@7.1.0has been added.==> Added 1 new compiler to /home/tahat/.spack/linux/compilers.yaml gcc@7.1.0 ==> Compilers are defined in the following files: /home/tahat/.spack/linux/compilers.yaml---- -
Alternatively, you can add compilers to Spack by editing
compilers.yamlwhich is located in$SPACK_ROOT/etc/spack/linux. -
You can add the compiler you installed above (gcc@7.1.0) manually. You can find the location of this compiler using the
spack locationcommand as shown above. You’ll find it’s installed in$SPACK_ROOT/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp. You edit thecompilers.yamlfile as follows:vim $SPACK_ROOT/opt/spack/compilers.yaml -
The file looks like the following:
compilers: - compiler: spec: gcc@4.8.5 paths: cc: /usr/bin/gcc cxx: /usr/bin/g++ f77: /usr/bin/gfortran fc: /usr/bin/gfortran flags: {} operating_system: centos7 target: x86_64 modules: [] environment: {} extra_rpaths: [] ... -
You can see that the file begins with
compilers:. Also, it has-compiler:where you can add your compiler. -
You found the location of the installed compiler:
/home/tahat/spack/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp---- -
Now, you specify different compilers such as
cc,cxxandFortranusing the path of the installed compiler. You add the following section to thecompilers.yamlfile:- compiler: spec: gcc@7.1.0 paths: cc: $SPACK_ROOT/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp/bin/gcc cxx: $SPACK_ROOT/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp/bin/g++ f77: $SPACK_ROOT/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp/bin/gfortran fc: $SPACK_ROOT/opt/spack/linux-centos7-x86_64/gcc-9.3.0/gcc-7.1.0-tnyp43zpkz6yrcqlglauwiyetmvrifpp/bin/gfortran operating_system: centos7 flags: {} operating_system: centos7 target: x86_64 modules: [] environment: {} extra_rpaths: [] -
To check if the compiler has been added successfully, type:
spack compiler list -
The following output shows that the
gcc@7.1.0compiler is available and can be used to build packages.==> Available compilers -- gcc centos7-x86_64 ------------------------------------------- gcc@9.3.0 gcc@8.3.0 gcc@7.1.0 gcc@4.8.5For more details go to Spack Documentation.