Compile-belt

From Arbeitsgruppe Kuiper
Jump to navigation Jump to search

Overview

Compiling belt (from scratch) takes place in 4 steps:

  1. configuring the auxiliary library PETSc, which may include selecting a compiler and an MPI implementation
  2. making PETSc
  3. adapting makefile_user_machinedefs
  4. making belt

configuring PETSc

Python 2

belt needs an old PETSc version, namely 3.1-p8 from March 2011. That version needs Python < 3 for its configuration, with the last version (Python 2.7.18) having been discontinued in 2020 and dropped from the major Linux distros around 2024. If there is really no Python 2 on the machine, two possible solutions are:

  1. Download pypy2.7, extract it to a suitable location in your $HOME (will consume about 130MB) and use pypy2.7-v*-linux64/bin/python2 as Python interpreter.
  2. As an alternative, install miniconda into your $HOME and create a Python 2.7 environment: conda create -n py27 python=2.7 (will consume about 1GB). Don't install anything else into this environment. (Because the package binutils may be pulled in; it provides the miniconda version of the linker ld, which may later confuse make.)
  3. (The most lightweight variant would be to get a statically built python2.7 binary to work, or at least a portable one.)

extracting and patching PETSc

  1. Extract petsc-3.1-p8 into a suitable location in your $HOME.
  2. Even with Python 2 being available, PETSc's C-code and the configuration scripts need a bit of patching: Save the petsc.patch into the PETSc folder.

setting up the configuration

It it advisable to create a tiny bash script which carries out the configuration (because the parameters will probably have to be adjusted more than once):

#!/bin/bash

python=python2  # Is probably not available right away.

if [ -d ~/pypy2.7-v*-linux64 ]; then
    python=~/pypy2.7-v*-linux64/bin/$python
elif [ -d ~/miniconda3 ]; then
    source ~/miniconda3/bin/activate py27
fi

export PETSC_DIR=$PWD
$python config/configure.py PETSC_ARCH=my_arch \
        --CFLAGS='' \
        --COPTFLAGS=-O3 --FOPTFLAGS=-O3 \
        --with-x=0 --with-debugging=0 --download-hypre=0

(to be continued)

To be patrolled, yet

(and to be converted from Markdown to Wikitext)

## Belt initialization

1. Clone the belt repository from the Gitlab of the university `git clone https://git.uni-due.de/agkuiper/belt` using your university credentials.

2. Enter dependencies folder and unpack petsc-3.1-p8.tar with `tar -xvf petsc-3.1-p8.tar`.

3. Open the file PETSc compile.sh and copy the command for "Rolfs MacBook Pro". Enter petsc-3.1-p8 and execute the copied statement with python2 in the command line to compile PETSc.

4. Follow the instructions in the terminal to complete the setup.

5. Exit the dependencies folder and enter the tests44 folder and open the `makefile_user_machinedefs` file. In this file we need to adjust the paths so that the code knows where the dependencies are. You find an example of the needed settings here:

  ```plaintext

   ################

   ##            ##

   ##  Compiler  ##

   ##            ##

   ################

   CC           = /home/your_name/Documents/belt/dependencies/petsc-3.1-p8/externalpackages/mpich2-1.0.8/bin/mpicc

   FC           = gfortran

   

   

   ############

   ##        ##

   ##  belt  ##

   ##        ##

   ############

   BELT_DIR     = /home/your_name/Documents/belt

   

   

   #############

   ##         ##

   ##  PETSc  ##

   ##         ##

   #############

   PETSC_DIR    = /home/your_name/Documents/belt/dependencies/petsc-3.1-p8

   PETSC_ARCH   = linux-gnu-c-opt

   PETSC_HYPRE  = YES

   PETSC_ML     = NO

   PETSC_LAPACK = flapack

   PETSC_BLAS   = fblas

   

   

   ################

   ##            ##

   ##  gfortran  ##

   ##            ##

   ################

   GFORTRAN         = YES

   GFORTRAN_LIB_DIR = /usr/lib64

   GFORTRAN_LIB     = gfortran

   

   

   ###########

   ##       ##

   ##  GSL  ##

   ##       ##

   ###########

   GSL          = NO

   GSL_DIR      = /Applications/Science/gsl/gsl-2.1-install

   GSL_LIB      = gsl

  ```

These could be different for your machine, please double check! Make sure that there are no spaces at the end of each line, the code won't compile if there are. GSL is not needed and you don't have to change anything there.

5. Choose a test setup, for example Grids/Spherical3D, enter the folder and create a folder "bin" as well as "data".

6. Open the file `makefile_user_CFLAGS_FFLAGS_LDFLAGS` and comment out the LDFlags line: `#LDFLAGS +="-Wl,-no_compact_unwind"`. Instead write `LDFLAGS += -ldl`. Beware of the spaces.

7. Now we are ready to run the first test. Type `make -j 8`, where the -j 8 gives the number of cores to compile on. Note that there are individual setups (BonnerEbert-Sphere 1D) that don't work in parallel yet. The number can not be higher than the physical number of cores.

8. Run the code with `./belt` on a single core and with e.g. `/home/your_name/Documents/belt/dependencies/petsc-3.1-p8/externalpackages/mpich2-1.0.8/bin/mpiexec -n 8 ./belt` depending on your path and the number of cores.

### Additional stuff:

- Check the file in the log folder to see the progress of your code. Here you find the current step the calculation is at, as well as the normalization units to convert the outputs from code units to cgs. When the run is finished the file also contains the total runtime at the bottom.

- If you stop the code while executing you can restart it using the last output to continue from, e.g. `./belt -restart 191`.