Compile-belt: Difference between revisions

From Arbeitsgruppe Kuiper
Jump to navigation Jump to search
(→‎Overview: +prerequisites, restructured)
Line 1: Line 1:
= Overview =
= Overview =


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


# configuring the auxiliary library [https://petsc.org/release/overview PETSc], which may include selecting a compiler and an MPI implementation
# installing packages needed by [https://petsc.org/release/overview PETSc] (the  ''Portable, Extensible Toolkit for Scientific Computation'' used by ''belt'')
# configuring PETSc, which may include selecting a compiler and an MPI implementation
# making PETSc
# making PETSc
# adapting <code>makefile_user_machinedefs</code>
# adapting <code>makefile_user_machinedefs</code>
# making ''belt''
# making ''belt''


== configuring PETSc ==
= prerequisites for PETSc =


=== Python 2 ===
== MPI and linear algebra ==
 
If you're on a compute cluster/server, those packages will already be installed. Probably there will be several versions and you have to pick the right ones later. If you're on your own computer, you need
 
* an implementation of the ''Message Passing Interface'', namely OpenMPI (package ''libopenmpi-dev'' or ''openmpi-devel'' on Debian-like or Redhat-like distros, respectively) '''or''' MPICH (''libmpich-dev'', ''mpich-devel'')
* the linear algebra libraries BLAS ([open?] ''libblas-dev'', ''blas-devel'') '''and''' LAPACK (''liblapack-dev'', ''lapack-devel'')
 
== Python 2 ==


''belt'' needs an old PETSc version, namely [https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-3.1-p8.tar.gz 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:
''belt'' needs an old PETSc version, namely [https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-3.1-p8.tar.gz 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:
Line 18: Line 26:
# (The most lightweight variant would be to get a [https://git.sr.ht/~knazarov/static-python statically built python]2.7 binary to work, or at least a [https://pypi.org/project/portable-python portable] one.)
# (The most lightweight variant would be to get a [https://git.sr.ht/~knazarov/static-python statically built python]2.7 binary to work, or at least a [https://pypi.org/project/portable-python portable] one.)


=== extracting and patching PETSc ===
= configuring PETSc =
 
== extracting and patching PETSc ==


# Extract [https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-3.1-p8.tar.gz petsc-3.1-p8] into a suitable location in your $HOME.
# Extract [https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-3.1-p8.tar.gz petsc-3.1-p8] into a suitable location in your $HOME.
# Even with Python 2 being available, PETSc's C-code and the configuration scripts need a bit of [https://en.wikipedia.org/wiki/Patch_(Unix) patching]: Save the [[:Media:Petsc.patch|petsc.patch]] into the PETSc folder.
# Even with Python 2 being available, PETSc's C-code and the configuration scripts need a bit of [https://en.wikipedia.org/wiki/Patch_(Unix) patching]: Save the [[:Media:Petsc.patch|petsc.patch]] into the PETSc folder.


=== setting up the configuration ===
== 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):
It it advisable to have a small bash script which carries out the configuration . Here's a minimal template (to be saved into the PETSc folder), where you'll have to adjust the path of ''pypy2.7'' or'' miniconda'' if you haven't chosen your home-directory:


<syntaxhighlight lang="shell">
<syntaxhighlight lang="shell">
#!/bin/bash
#!/bin/bash


python=python2 # Is probably not available right away.
[ -r include/newMPInames.h ] || patch -p0 < petsc.patch # patch if not done, yet


if [ -d ~/pypy2.7-v*-linux64 ]; then
python=python2  # probably not available right away, hence:
     python=~/pypy2.7-v*-linux64/bin/$python
if [ -d $HOME/pypy2.7-v*-linux64 ]; then
elif [ -d ~/miniconda3 ]; then
     python=$HOME/pypy2.7-v*-linux64/bin/$python
     source ~/miniconda3/bin/activate py27
elif [ -d $HOME/miniconda3 ]; then
     source $HOME/miniconda3/bin/activate py27
fi
fi


export PETSC_DIR=$PWD
export PETSC_DIR=$PWD
$python config/configure.py PETSC_ARCH=my_arch \
$python config/configure.py PETSC_ARCH=my_arch \
         --CFLAGS='' \
         --CFLAGS='-Wno-deprecated-declarations -Wno-unused-result -Wno-format-overflow' \
         --COPTFLAGS=-O3 --FOPTFLAGS=-O3 \
         --COPTFLAGS=-O3 --FOPTFLAGS=-O3 \
         --with-x=0 --with-debugging=0 --download-hypre=0
         --with-x=0 --with-debugging=0 --download-hypre=0

Revision as of 08:56, 18 March 2026

Overview

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

  1. installing packages needed by PETSc (the Portable, Extensible Toolkit for Scientific Computation used by belt)
  2. configuring PETSc, which may include selecting a compiler and an MPI implementation
  3. making PETSc
  4. adapting makefile_user_machinedefs
  5. making belt

prerequisites for PETSc

MPI and linear algebra

If you're on a compute cluster/server, those packages will already be installed. Probably there will be several versions and you have to pick the right ones later. If you're on your own computer, you need

  • an implementation of the Message Passing Interface, namely OpenMPI (package libopenmpi-dev or openmpi-devel on Debian-like or Redhat-like distros, respectively) or MPICH (libmpich-dev, mpich-devel)
  • the linear algebra libraries BLAS ([open?] libblas-dev, blas-devel) and LAPACK (liblapack-dev, lapack-devel)

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.)

configuring PETSc

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 have a small bash script which carries out the configuration . Here's a minimal template (to be saved into the PETSc folder), where you'll have to adjust the path of pypy2.7 or miniconda if you haven't chosen your home-directory:

#!/bin/bash

[ -r include/newMPInames.h ] || patch -p0 < petsc.patch  # patch if not done, yet

python=python2  # probably not available right away, hence:
if [ -d $HOME/pypy2.7-v*-linux64 ]; then
    python=$HOME/pypy2.7-v*-linux64/bin/$python
elif [ -d $HOME/miniconda3 ]; then
    source $HOME/miniconda3/bin/activate py27
fi

export PETSC_DIR=$PWD
$python config/configure.py PETSC_ARCH=my_arch \
        --CFLAGS='-Wno-deprecated-declarations -Wno-unused-result -Wno-format-overflow' \
        --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`.