Dune INI syntax (`[Group]` and `Key = Value` pairs)
DUNE INI syntax:
`params.input`
```cpp
[Grid]
...
...
@@ -291,62 +353,69 @@ Cells = 24 16
[Problem]
Name=test
```
Input files are specified as arguments to the executable
`./myexecutable params.input`
See [slides on runtime parameters](./runtimeparams-grids.html) for details.
# Main program and main function
## The input file
## Main program
If no input file is given it defaults to the file `params.input` or `myexecutablename.input`
* Each problem has one main file (`test_name.cc` or `main.cc`)
* Contains the `main` function (mandatory in C/C++ programs)
Parameters can be overwritten in the command line via:
## Main function
```bash
./executable params.input –Problem.Name myNewName
Calling `Dumux::initialize` is mandatory
at the beginning of each DuMu^x^ program to make sure the
environment is correctly set up.
```cpp
intmain(intargc,char**argv)
{
// initialize MPI+X backends (mandatory)
Dumux::initialize(argc,argv);
```
##
Parse runtime parameters:
# The main file <small>(`2pmain.cc`)</small>
```cpp
// parse command line arguments and input file
Dumux::Parameters::init(argc,argv);
```
## The main source file
* Each problem has a specific main file (`test_name.cc` or `main.cc`) which sets up the program structure and calls assembler and solvers to assemble and solve the PDEs.
* Depending on the complexity of the problem the main file can be either set up to solve a linear problem, a non-linear problem and stationary as well as instationary problems.
* The main file usually includes the problem, the solvers, the assembler, the VTK output module and the gridmanager.
See [slides on runtime parameters](./runtimeparams-grids.html) for details.
But you can of course "install" Dune modules and DuMu^x^.
## Build system - what is CMake?
* Open source build system tool developed by KITware.
* Offers a one-tool-solution to all building tasks, like configuring, building, linking, testing and packaging.
* Is a build system generator: It supports a set of backends called generators.
* Is portable and supports cross-platform compilation.
* Is controlled by ONE rather simple language.
* Every directory in a project contains a file called `CMakeLists.txt`, which is written in the CMake language. You can think of these as a distributed configure script. Upon configure, the top-level `CMakeLists.txt` is executed.
*[Open-source build system tool developed by KITware](https://cmake.org/)
* Offers a one-tool-solution to all building tasks, like configuring, building, linking, testing and packaging
* Is portable and supports cross-platform compilation
* Build file generator: Support various backends called generators (default: GNU Makefiles)
* Control files written in the CMake language
## Build system - configuring
## Build system - CMakeLists.txt
* Configure build time compiler parameters / linking information.
* Create „targets“ that can be build to create executables.
* Every directory in a project contains a file called `CMakeLists.txt`, which is written in the CMake language
* Upon configure, the top-level `CMakeLists.txt` is executed
* Subfolders are included with the `add_subdirectory(...)` function
## Build system - configuring
*Build with the script `dune-common/bin/dunecontrol <options>` which takes care of all dependencies and modular dune structure.
*Option `all`: build all libraries and executables.
*Option `--opts=<optionfile.opts>` specify e.g. compiler flags; For DuMu$^\mathsf{x}$, you may use `dumux/cmake.opts`.
* Option `--build-dir=<build directory>` specify path for out-of-source build; Default: every module contains its own build directory `build-cmake/`.
* You have to reconfigure (possibly deleting all build directories first) whenever a dependency changes or a Dune library is updated.
*Configure build-time compiler parameters / linking information
*Create "targets" that can be build to create executables
*Find and link external libraries / software dependencies
## Build system - dunecontrol
## Invoking `dunecontrol`
* For Dune, CMake is triggered via the`dunecontrol` script
```bash
./dune-common/bin/dunecontrol --opts=dumux/cmake.opts all
removes the `CMake` cache files from all Dune modules.
(Use `--only <module>` to only remove caches of specific modules.)
## Build system - basic CMake functions
* Use `add_subdirectory` for recursively adding subdirectories
* Subdirectory must contain a `CMakeLists.txt` (can be empty)
* Executables are added via `add_executable(<name> source1 [source2 ...])`
* Tests are added via `dumux_add_test` which also add a test executable to the test suite
* Symlinks can be added via `dune_symlink_to_source_files`
## Build system
Simplest incorporation of a test by defining name, source file and command line arguments:
`CMakeLists.txt` for an example application: create a test target `test_2p_incompressible_box`
by defining name, source file and command line arguments:
```cmake
dumux_add_test(
NAME test_2p_incompressible_box
...
...
@@ -570,9 +692,12 @@ dumux_add_test(
```
## Build system
Add extra compile definitions and commands:
Add extra compile definitions and commands (typical
for DuMu^x^ regression tests):
```cmake
dune_add_test(
dumux_add_test(
NAME test_2p_incompressible_box
SOURCES test_2p_fv.cc
COMPILE_DEFINITIONS TYPETAG=TwoPIncompressibleBox
...
...
@@ -598,19 +723,26 @@ target_compile_definitions(
```
## Build system
Important basic commands:
* See also Dune build system documentation on [https://www.dune-project.org/sphinx/core/](https://www.dune-project.org/sphinx/core/) for a comprehensive CMake online documentation.
*[Dune CMake online documentation](https://www.dune-project.org/sphinx/core/) for CMake functions available with Dune.
# Parallelism
## Distributed memory parallelism with MPI
* MPI stands for Message Passing Interface.
* Main idea is the concept of domain decomposition.
* Each local subdomain is solved on an individual process(rank).
* MPI manages the communication between the ranks.
* Most solvers in DuMu$^\mathsf{x}$ are capable of parallel solving.
* MPI stands for Message Passing Interface
* MPI manages communication between processes that run in parallel
## Distributed memory parallelism with MPI
* Main idea is the concept of domain decomposition
* The grid manages the grid partitioning
* Each local subdomain is assembled on an individual process (rank)
* Solvers have to handle decomposed vectors/matrices
* Most solvers in DuMu^x^ (iterative Krylov subspace methods based on dune-istl) are capable of MPI parallel solving
## Distributed memory parallelism with MPI
...
...
@@ -618,38 +750,55 @@ Run with:
```cpp
mpirun-np[n_cores][executable_name]
```
Handling results:
* Each rank creates its own `*.vtu`/`*.vtp` file.
* These are combined into `*.pvtu`/`*.pvtp` files for each time step.
* A normal `*.pvd` file is created from the `*.pvtu`/`*.pvtp` files.
## Distributed memory parallelism with MPI
Partitioned VTK output files:
## Shared-memory parallelism and multi-threaded applications
* Each rank creates its own `*.vtu`/`*.vtp` file
* Combined into `*.pvtu`/`*.pvtp` files for each time step
*`*.pvd` groups all `*.pvtu`/`*.pvtp` files into a time series
* Dumux can exploit parallelism with the shared memory model.
* Used in the `Dumux::FVAssembler` by default to assemble the residual and stiffness matrix.
* Is enabled when a multi-threading backend is found.
* Backend is selected by `CMAKE` during configuration and stored in `DUMUX_MULTITHREADING_BACKEND`.
* Possible examples are `OpenMP`, `TBB`, C++ parallel algorithms and `Kokkos`.
## Shared-memory parallelism
## Switching off multi-threading
* Dumux can exploit parallelism with the shared memory model
* Used in the `Dumux::FVAssembler` by default to assemble the residual and stiffness matrix
* Is enabled when a multi-threading backend is found
* Backend is selected by `CMAKE` during configuration and stored in `DUMUX_MULTITHREADING_BACKEND`
* Possible examples are `OpenMP`, `TBB`, C++ parallel algorithms, and `Kokkos`
Simply add the following to your input file:
## Shared-memory parallelism
**Restrict the number of threads**
Number of threads can be restricted via the environment variable `DUMUX_NUM_THREADS`
```sh
DUMUX_NUM_THREADS=2 ./executable
```
## Shared-memory parallelism
**Multi-threaded assembly**
Control use of multi-threading during assembly in input file:
```cpp
[Assembly]
Multithreading=false
```
Important for working on clusters: Number of threads can also be restricted via manipulating the environment variable `DUMUX_NUM_THREADS=2 ./executable`
Defaults to `true`.
# Exercises
## Exercises:
Exercise about setting boundary conditions, the problem file etc:
## Exercises
Basic application setup:
* Go to [Exercise basic](https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/tree/master/exercises/exercise-basic#exercise-basics-dumux-course)
* Go to [https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/tree/master/exercises/exercise-basic](https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/tree/master/exercises/exercise-basic) and check out the README
Exercise for the main-files:
The main function:
* Go to [https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/tree/master/exercises/exercise-mainfile](https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/-/tree/master/exercises/exercise-mainfile) and check out the README
* Go to [Exercise mainfile](https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/-/tree/master/exercises/exercise-mainfile#exercise-mainfiles-dumux-course)