foap4 - Fortran OpenAcc p4est
April 24, 2026 ยท View on GitHub
This project aims to combine p4est with OpenAcc and Fortran. The goal is to build a simple and compact code for numerical simulations on quadtrees/octrees, using multiple GPUs.
Installation
Prerequisites
- fypp
- An MPI-compatible C and Fortran compiler
- NVHPC or another OpenACC-compatible compiler for GPU support
Compiling p4est
The p4est library is included as a git submodule. It seems most robust to compile this library using a GCC toolchain. To compile it into p4est/build, the following steps can be used:
-
Get the
p4estsource code:git submodule init git submodule update -
Get the
scsource code required forp4est:cd p4est git submodule init git submodule update -
Go back to the top folder and execute the
build_p4est.shscript with:bash build_p4est.sh
It is also possible to install p4est in a different location (or through a different method), but then the main Makefile has to be updated accordingly.
Compiling foap4 with NVHPC
Load the NVHPC compilers, so that mpif90 points to nvfortran etc. Then simply execute
make
To see a list of compilation options, use
make help
Included examples
These are compiled under build/bin/, typically as both a 2D and 3D variant. Some notable tests/examples are:
test_refinement_2/3d: tests mesh refinement, prolongation and restrictiontest_xdmf_writer_2/3d: tests XDMF outputtest_advection_2/3d: simple scalar advection testtest_euler_2/3d: solves Euler's equations of gas dynamics
Viewing results
There is currently an inconsistency between Visit and Paraview regarding the order of XDMF data. To write output that can be viewed from Paraview, add viewer="paraview" to io_write_grid calls, like:
call io_write_grid(f4, base_name, n_output, viewer="paraview")
Then use the legacy XDMF Reader. For visit no viewer="visit" argument is required, since it is the default.
For most of the included test cases, the type of output is controlled by an optional argument, like:
mpirun -np 1 ./build/bin/test_euler_2d -viewer=paraview