# mpim-sw grid generator build on balfrin
Below is a guide of how to compile and run the mpi grid generator on balfrin with uenv.
## Steps
1. Prepare the uenv image. Details about uenv can be found on https://confluence.cscs.ch/display/KB/UENV+user+environments
```bash
git clone https://github.com/eth-cscs/uenv.git
cd uenv
# run the installation script.
# if this is the first time that you are installing uenv,
# type "yes" or "y" when prompted whether to update your ~/.bashrc file.
./install --local
```
2. Activate the environment.
```bash
uenv start /scratch/mch/leclairm/uenvs/images/icon.v1.rc4.sqfs
```
3. Clone the repository.
```bash
git clone git@gitlab.dkrz.de:mpim-sw/grid-generator.git && cd grid-generator
```
4. We make use of the existing non-spack CPU build config for balfrin. Create a `config.sh` script with the following contents in the grid-generator root directory.
```bash
#!/bin/bash
set -e
if [[ "$(hostname)" == *"balfrin"* || "$(hostname)" == *"tasna"* ]]; then
export CUDAARCHS='80'
export SERIALBOX2_ROOT=/scratch/mch/agopal/gh_benchmarks_dsl/spack-c2sm/spack/opt/spack/linux-sles15-zen3/gcc-11.3.0/serialbox-2.6.1-dvuqzvub3ctemalp5aswpd36kcgl2qha
elif [[ "$(hostname)" == *"todi"* || "$(hostname)" == *"santis"* ]]; then
export CUDAARCHS='90'
export SERIALBOX2_ROOT=/user-environment/env/icon
fi
export NETCDF_FORTRAN=/user-environment/env/icon
export NETCDF=/user-environment/env/icon
export XML2_ROOT=/user-environment/env/icon
export ECCODES_ROOT=/user-environment/env/icon
bash ./config/cscs/balfrin.cpu.nvidia
```
The hardcoded paths should be identical to what is used in icon-exclaim.
5. Run the `config.sh` script.
```bash
bash config.sh
```
6. Compile the binary.
```bash
make -j24
```
7. Copy the grid creator of your choice to the run folder.
```bash
cp run/grid_creators/grid.create_torus_grid run/.
```
8. Create the run script.
```bash
./make_runscripts grid.create_torus_grid
```
9. Run the grid generator with the run script.
```bash
cd run && sbatch grid.create_torus_grid.run 100 100 500
```