ShallowWater2D is a mini-app designed to test different parallelization models to simulate the shallow water equations in two dimensions. ShallowWater2D is a lean mini-app (only one source file) written in object-oriented C++. The project is a work in progress.
There are currently 4 versions of the code:
- serial,
- pure openMP using tasks,
- pure MPI using Cartesian virtual topology,
- OpenACC with unified memory.
All versions have been validated against an analytical travelling wave solution in 1D and periodic boundary conditions (using ghost cells).
The shallow water equations solved are:
where
The fluid equations are evolved on a cartesian grid using the finite volume method to achieve second-order accuracy. This is done using a strong stability-preserving 3rd order Runge-Kutta scheme for the timestepping and a Lax-Friedrichs numerical flux for linear interpolation at the cell faces with slope-limiters (minmod, van Leer).
- serial:
g++ main.cpp -O3 -o main.exe - OpenMP
Run with:
g++ main_openmp.cpp -O3 -fopenmp -o main_openmp.exeexport OMP_NUM_THREADS=4; ./main_openmp.exe - MPI
Run with:
mpic++ main_mpi.cpp -O3 -o main_mpi.exempirun -np 4 ./main_mpi.exe 256 256 - OpenACC
nvc++ -acc -Minfo=accel -gpu=mem:managed -o main_acc.exe main_acc.cpp
The performance of the different versions of ShallowWater2D can be profiled using different tools. One possibility is with Nvidia Nsight and NVTX annotations.
An example command for profiling is:
nsys profile --trace cuda,nvtx --stats=true ./main.exe 256 256
For the serial code, the timings are:
| Time (%) | Total Time (ns) | Instances | Avg (ns) | Med (ns) | Min (ns) | Max (ns) | StdDev (ns) | Style | Range |
|---|---|---|---|---|---|---|---|---|---|
| 59.3 | 20,927,886,491 | 1,511 | 13,850,355.1 | 13,774,741.0 | 13,559,033 | 20,144,508 | 407,534.6 | PushPop | advanceTime |
| 19.9 | 7,033,304,803 | 4,533 | 1,551,578.4 | 1,543,874.0 | 1,535,097 | 1,866,331 | 24,152.5 | PushPop | compute_tendencies_x |
| 19.6 | 6,924,805,648 | 4,533 | 1,527,643.0 | 1,520,053.0 | 1,512,024 | 1,831,376 | 23,371.3 | PushPop | compute_tendencies_y |
| 1.0 | 353,188,751 | 1,511 | 233,745.0 | 232,110.0 | 231,312 | 288,900 | 4,193.6 | PushPop | compute_dt |
| 0.0 | 13,429,268 | 4,534 | 2,961.9 | 3,092.0 | 1,486 | 32,613 | 1,320.7 | PushPop | set_halo_values_y |
| 0.0 | 11,394,816 | 4,534 | 2,513.2 | 2,177.0 | 1,710 | 16,334 | 930.2 | PushPop | set_halo_values_x |
The numerical schemes and the choice of the physical model are based on the project work that the author did for the course "Numerical Methods for Conservation Laws" with Professor Jan S. Hesthaven at the École polytechnique fédérale de Lausanne (EPFL) for the Master in Physics (minor in Computational Science and Engineering), a. 2016-2018.