1.6. Compile SPEX from source

Table of Contents:

  • Getting started

  • Library dependencies

  • MacOS instructions

  • General compilation instructions

  • Optional features

  • Create install packages

1.6.1. Getting started

The SPEX source code can be compiled using the multi-platform Cmake build system. See http://www.cmake.org/ for more information and downloads, or check the package manager of your Linux distribution. The SPEX install needs CMake version 3.0 or higher.

Since SPEX is programmed mostly in Fortran 90, it is recommended to use a recent Fortran compiler. SPEX has been tested with GFortran (version 4 and above) and the Intel Fortran Compiler.

This Zenodo contains a tar.bz2 file containing the source code of SPEX: spex-3.07.02-Source.tar.bz2. Unpack it in a convenient directory:

unix:~/Software> tar xvfj spex-3.08.00-Source.tar.bz2

In the top-level directory, a script called compile.py is available to guide the user through the compilation process. Please read the section about library dependencies first and install what is needed. Otherwise, the script will tell you what is missing. To run the script call:

unix:~/Software/spex> python compile.py

Please note that the compile script requires Python 3 to be installed.

1.6.2. Library dependencies

SPEX depends on a few external libraries to function. For some of those, the library source code has been included in the SPEX source code package. By default, CMake will look for system libraries to link to. If they are not there, then the version in the source package will be used.

The following libraries and packages are required to compile SPEX:

  • CMake

  • X11

  • Readline

  • CFITSIO (*)

  • BLAS (*)

  • LAPACK (*)

  • PGPLOT (*)

(*) The SPEX source tree also contains the library if necessary.

All these libraries are commonly available in Linux distributions, so please read the documentation of your distribution to find out how to install these libraries. Please note that some distributions require you to also install the ‘development’ package of a library to be able to use them during compilation. In the Debian repository, for example, the development package of readline is called ‘libreadline-dev’.

Below, we list some library-specific comments that can be helpful in case of problems.

1.6.2.1. Readline

Note for Mac OSX users: The OSX readline library is NOT compatible with the GNU readline library. You need to compile your own readline library from source or find a GNU readline library elsewhere on your system to link to. Compilation may work in, for example, a MacPorts environment, although this has not been tested. The official Mac version of SPEX statically links to a compiled version of readline downloaded from:

https://tiswww.case.edu/php/chet/readline/rltop.html

1.6.2.2. CFITSIO

The cmake program will be able to find system versions of CFITSIO automatically. If CFITSIO is not installed, please install it using a package manager or compile it yourself. In case cmake cannot find the CFITSIO library, then add the flag -DCFITSIO_ROOT_DIR=/usr/local to the cmake command (in this example, CFITSIO was compiled using --prefix=/usr/local and the library is found in /usr/local/lib/libcfitsio.so. Make sure to provide the path where your libcfitsio library is installed).

1.6.2.3. BLAS and LAPACK

Some of the SPEX models depend heavily on the BLAS and LAPACK linear algebra packages. The default routines are available in the SPEX source tree, but compiling those will not provide the best performance. The performance improves substantially if an optimized BLAS or LAPACK library is used. There are two tested options:

  • Intel Math Kernel Library (MKL)

  • OpenBLAS

When compiling with the Intel Fortran compiler, using MKL is quite obvious. To link the MKL library, add the following option to the cmake command:

cmake . -DMKL=YES

If MKL is not set, cmake will look for other options, like OpenBLAS, if they are installed on your machine. If nothing is found, the non-optimized code in the SPEX source tree is used. On Mac, CMake could find the MacOS Accelerator framework.

1.6.3. MacOS instructions

The compilation of SPEX on MacOS is slightly more demanding. SPEX can run natively on MacOS (without ports), but then it needs a few pre-installed programs:

1.6.4. General Compilation Instructions

When all library dependencies are installed, the compilation process can begin. Execute cmake in the root directory of the SPEX source tree, where CMakeLists.txt is located (mind the dot):

unix:~/Software/SPEX-3.08.00-Source> cmake .

If no errors occured and all libraries were found, then type ‘make’:

unix:~/Software/SPEX-3.08.00-Source> make

When the program needs to be installed system wide, then execute:

unix:~/Software/SPEX-3.08.00-Source> sudo make install

The program will be installed to /opt/spex by default. Usually, administrator rights are necessary to copy the files to the right location.

Before you can run SPEX, the environment needs to be set. This can be done with the source command:

source /opt/spex/spexdist.sh (bash shell)
source /opt/spex/spexdist.csh (C-type shell)

In case you used another prefix for the SPEX installation directory, you can find spexdist.sh or spexdist.csh in the prefix directory that you set. To load the SPEX environment automatically, add the relevant source line to your ~/.cshrc or ~/.bashrc file.

1.6.5. Optional features

There are several options that can be passed to CMake to influence the build process through the -D operator. Of course, all options can be combined in a single cmake call. See the cmake documentation and the CMakeLists.txt file for details.

1.6.5.1. Compiler selection

Select a different fortran compiler:

unix:~/Software/SPEX-3.08.00-Source> cmake . -DCMAKE_Fortran_COMPILER=ifort

1.6.5.2. Install prefix

Install SPEX at a different location in the ‘make install’ step:

unix:~/Software/SPEX-3.08.00-Source> cmake . -DCMAKE_INSTALL_PREFIX=/home/user/software

1.6.5.3. Force use of SPEX libraries

The use of the SPEX libraries in the source tree can be forced:

unix:~/Software/SPEX-3.08.00-Source> cmake . -DPGPLOT=YES

The command above will compile the pgplot library from the SPEX source tree. See the CMakeLists.txt file for more options.