Important
The helper script run.sh and the nm4pde-lab configure preset are intended for HPC systems (like PC's of Politecnico di Milano students) that provide compilers and libraries via mk-style module stacks
(the preset uses fixed toolchain paths under /u/sw/toolchains/...).
If you are not on such a system, do not use ./run.sh, instead follow the "Manual build" instructions below or adapt CMakePresets.json to your local toolchain.
Why use mk modules? Why configure a CMakeLists.txt file with mk modules?
-
Why use
mkmodules? The purpose of this repository is to provide a learning environment for numerical methods for PDEs, not to build a complex C++ project. Since the courses are held at PoliMI, where students have access to HPC systems that use mk modules to manage software environments, the providedrun.shscript andCMakePresets.jsonare tailored for that context. -
Why configure a
CMakeLists.txtfile withmkmodules? I know that you could just load the mk modules in your shell and then run CMake. However, I use IDEs like CLion or VSCode that invoke CMake in a clean environment without the mk modules loaded. By configuring theCMakeLists.txtwith the appropriate paths, I can ensure that the project builds correctly within these IDEs without needing to manually load mk modules each time.
This repository was created to learn and practice PDE programming techniques taught in the "Numerical Methods for Partial Differential Equations" course at Politecnico di Milano (PoliMI). The materials and labs were adapted from the course exercises. For reference:
- Original labs repository: michelebucelli/nmpde-labs-aa-24-25
- Notes and explanations for these codes (provided by the repository creator): HPC-E-PoliMI-university-notes
- PDF notes site with full lecture/materials: PoliMI Notes website
This repository contains small labs and examples used in the Numerical Methods for Partial Differential Equations course.
The code demonstrates practical implementations for simple PDE problems
(Poisson 1D examples are provided in lab-1 and lab-2).
It is intended as a learning reference and starting point for experiments.
Note
You can download the mk tool from pcafrica/mk github repository. Specifically, we use the version tagged v2024.0 in the release section (full version).
- CMake
>= 3.12 - Ninja build (or another generator supported by CMake)
- A C++ compiler (the presets target GCC 11 and MPI C++ wrappers)
fzf(required for interactive example selection with the keyboard)- (Optional) On the HPC target: the toolchain and libraries referenced in the presets (deal.II, Boost, ARPACK, HDF5, etc.)
Quickstart (recommended on the target HPC system with mk modules)
-
Make the helper scripts executable (if not already):
chmod +x requirements.sh run.sh
-
Run the helper to install/check requirements and build+run the examples:
./run.sh
The run.sh script will:
- Check/install local packages (via
requirements.sh) - Configure the project using the
nm4pde-labpreset fromCMakePresets.json - Ask which example to build and run (select
lab-1orlab-2for now) - Build the selected example and run the produced executable with the appropriate
LD_LIBRARY_PATHvalues from the preset environment.
Manual build (if not using run.sh or you need to adapt to a local machine)
- Using the preset (if your environment matches the preset paths):
mkdir -p build && cd build
cmake .. --preset nm4pde-lab
cmake --build build/nm4pde-lab -- -j
# or use ninja directly in the preset binary dir- Manual configure (recommended if you don't have the HPC toolchain):
mkdir -p build && cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++
cmake --build . -- -jIf your system uses MPI wrappers, set MPI_CXX_COMPILER accordingly, or configure CMAKE_CXX_COMPILER to the MPI C++ wrapper (mpicxx).
If you use CLion to build or run the examples, the IDE runs programs in a clean environment and may not have the mk toolchain libraries on LD_LIBRARY_PATH.
Add the following line to the Environment variables of your Run/Debug Configuration for the executable (Run -> Edit Configurations... -> select the target):
LD_LIBRARY_PATH=/u/sw/toolchains/gcc-glibc/11.2.0/pkgs/arpack/3.8.0/lib:/u/sw/toolchains/gcc-glibc/11.2.0/base/lib:/u/sw/toolchains/gcc-glibc/11.2.0/pkgs/hdf5/1.12.0/lib:$LD_LIBRARY_PATH
This ensures CLion will find ARPACK/HDF5 and other libraries provided by the nm4pde-lab mk toolchain when running the executable from the IDE.
(If you prefer to set this globally for your user session, add the same line to your shell startup file, e.g. ~/.bashrc.)
Tip
Open your Run/Debug Configuration and paste the LD_LIBRARY_PATH string into the Environment variables field.
The run.sh helper script has improved UX and supports automatic preset selection and a small CLI. The script supports:
--preset NAME: explicitly choose a CMake preset (for examplenm4pde-laborlocal-debug).--presets: print all available configure preset names fromCMakePresets.jsonand exit (handy to know which presets you can pass to--preset).--example NAME: build and run the chosen example non-interactively. IMPORTANT:--examplerequires a non-empty NAME argument; calling./run.sh --examplewithout a name will now print an error and exit instead of entering the interactive prompt loop.-yor--yes: non-interactive mode: assume "yes" at prompts.NM4PDE_PRESETenvironment variable: if set, it is used when--presetis not provided.
Auto-selection logic (default behavior)
- If
--presetis provided, the script uses that preset. - Else if
NM4PDE_PRESETis set, it uses that value. - Else if the mk toolchain path (
/u/sw/toolchains/gcc-glibc/11.2.0) exists, the script defaults tonm4pde-lab. - Else, if
mpicxxandg++are available on the system, the script falls back tolocal-debug. - If none of the above applies the script aborts with a short set of manual build instructions.
To build and run any available lab, simply run:
./run.shYou will be presented with an interactive menu (powered by fzf) to select which example to build and run. Use your keyboard to navigate and select the desired lab.
You can also build and run a specific example directly:
./run.sh --example lab-1Or list all available labs:
./run.sh --listOr list all available CMake presets:
./run.sh --presets- When using the
nm4pde-labpreset, the script setsLD_LIBRARY_PATHto include ARPACK/HDF5 libraries from the mk toolchain. - The
local-debugpreset uses/usr/bin/g++and/usr/bin/mpicxxfor local development. - If you add a new lab (e.g.,
lab-3), it will automatically appear in the interactive menu.
- If you see errors about missing tools (e.g.,
fzf,cmake,ninja), run./requirements.shto install them. - If a build fails, check that your environment matches the requirements and that you have the correct toolchain or preset selected.

