How uk-mac/cloverleaf works
CloverLeaf is a hydrodynamics mini-app organized as one shared application with multiple execution backends. The top-level repository contains a single build system and several sibling implementation directories, each representing the same simulation pipeline mapped to different parallel/runtime technologies.
The main architectural boundary is between the core CloverLeaf algorithm and the parallel model used to execute it. The CloverLeaf_ref tree is the canonical hybrid OpenMP/MPI implementation; the Serial, OpenMP, and MPI variants are derived from it by removing the relevant runtime layer. This means the physics and timestep logic are intended to stay aligned across implementations, while the parallelization layer changes.
The implementation families in the tree are:
• CloverLeaf_Serial: single-process, no MPI or OpenMP
• CloverLeaf_OpenMP: shared-memory parallelism only
• CloverLeaf_MPI: distributed-memory parallelism only
• CloverLeaf_OpenACC: MPI plus accelerator directives
• CloverLeaf_Offload: MPI plus Intel offload
• CloverLeaf_CUDA: MPI plus explicit CUDA GPU support
• CloverLeaf_OpenMP4: an additional directive-based OpenMP variant in the repository
• CloverLeaf_ref: the hybrid reference implementation
The runtime data flow is simple and benchmark-oriented. The executable starts, reads a required clover.in input file from the working directory, initializes the mesh and problem state, then enters a hydrodynamic timestep loop. During the run it emits summary state variables periodically and again at the end. Those summaries are used for correctness checking and performance regression comparisons.
A notable functional boundary is validation versus production runs. If no clover.in file is present, the code runs a built-in self-test against a known solution. The README also describes several standard benchmark inputs (clover_bm_short.in, clover_bm.in, clover_bm16_short.in, clover_bm16.in) that exercise progressively larger and more communication-heavy meshes.
The numerical model is designed for parallel consistency, but not perfect bitwise identity across all compilers/platforms. The README explicitly calls out IEEE/strict-floating-point modes as important for reproducibility on some systems, especially Intel and Cray. That makes floating-point compiler settings part of the effective architecture, not just a build detail.
The code is built with a single top-level Makefile, with compiler selection controlled through environment variables and flags rather than separate build scripts. MPI_COMPILER and C_MPI_COMPILER select the Fortran and C MPI wrappers, while COMPILER, IEEE, OPTIONS, C_OPTIONS, and DEBUG tune optimization, reproducibility, and target-specific settings. This is important because the same source tree is expected to compile across CPU, OpenMP, MPI, and accelerator environments.
Accelerator support is primarily directive- or platform-driven rather than a separate application architecture. For OpenACC and HMPP/CAPS-style builds, the code can still run on the CPU if the accelerator toolchain or modules are absent; the pragmas are simply ignored. The CUDA backend is the most explicit accelerator path and requires selecting the GPU architecture with NV_ARCH.
From a system perspective, the repo is a performance benchmark as much as a solver. The README emphasizes cache behavior, memory bandwidth, scaling regimes, compiler vectorization, and hardware-specific options like huge pages or turbo modes. Those concerns matter because the same algorithm is intentionally exercised under very different execution models and machine configurations.
The key architecture diagram should therefore show one shared CloverLeaf simulation core feeding multiple backend-specific build/runtime paths, with the input file at the top, the timestep kernel in the center, and summary/validation output at the bottom. The main variation is how that core is partitioned across threads, ranks, or GPUs, not the overall application flow.
Main entry points: Makefile Makefile · CloverLeaf_ref Ref core · CloverLeaf_Serial Serial · CloverLeaf_OpenMP OpenMP
Components 17
Build
Top-level build and repository guidance
Core simulation
Shared hydrodynamics flow and validation paths
- Init state · Initializes mesh and problem state before time stepping
- Timestep loop · Hydrodynamics update loop that advances the simulation
- Physics kernels · Core update logic shared across execution models
Execution backends
Parallel and accelerator variants of the same solver
- Ref core · Reference MPI + OpenMP implementation that other variants track
CloverLeaf_ref - Serial · No MPI or OpenMP
CloverLeaf_Serial - OpenMP · OpenMP-only execution variant
CloverLeaf_OpenMP - MPI · MPI-only execution variant
CloverLeaf_MPI - OpenACC · MPI plus directive-based accelerator support
CloverLeaf_OpenACC - Offload · MPI plus Intel offload path
CloverLeaf_Offload - CUDA · MPI plus explicit CUDA GPU support
CloverLeaf_CUDA - OpenMP4 · Additional directive-based OpenMP variant
CloverLeaf_OpenMP4
Runtime data
Input, benchmark, and output artifacts
- clover.in · Required working-directory input for a normal run
- Bench inputs · Standard problem-size inputs used for scaling and regression runs
- Self-test · Built-in known-solution check when no input file is present
- Summary output · Periodic and final state summaries for checking and regression
Connections 30
- Makefile → Ref core: builds · Top-level build targets the reference tree and variants
- Makefile → Serial: builds · Builds the serial backend
- Makefile → OpenMP: builds · Builds the OpenMP backend
- Makefile → MPI: builds · Builds the MPI backend
- Makefile → OpenACC: builds · Builds the OpenACC backend
- Makefile → Offload: builds · Builds the offload backend
- Makefile → CUDA: builds · Builds the CUDA backend
- Makefile → OpenMP4: builds · Builds the OpenMP4 backend
- README → Makefile: documents · Describes compiler variables, flags, and backend selection
- README → Bench inputs: describes · Lists standard benchmark problem inputs
- clover.in → Init state: drives · Input file selects and parameterizes a normal run
- Self-test → Init state: falls back to · Known-solution mode initializes without an input file
- Init state → Timestep loop: enters · Initialization feeds the main solver loop
- Timestep loop → Physics kernels: uses · Time stepping is implemented through shared numerical kernels
- Timestep loop → Summary output: emits · Produces periodic and final state summaries
- Bench inputs → clover.in: provide · Benchmark inputs are alternative run configurations
- Ref core → Serial: specializes to · Derived by removing parallel layers
- Ref core → OpenMP: specializes to · Derived by keeping shared-memory parallelism
- Ref core → MPI: specializes to · Derived by keeping distributed-memory parallelism
- Ref core → OpenACC: extends to · Directive-based accelerator variant aligned with the reference solver
- Ref core → Offload: extends to · Offload-oriented accelerator variant aligned with the reference solver
- Ref core → CUDA: extends to · GPU implementation aligned with the reference solver
- Ref core → OpenMP4: extends to · Additional OpenMP directive variant aligned with the reference solver
- Serial → Timestep loop: implements · Maps the shared simulation flow to a single process
- OpenMP → Timestep loop: implements · Maps the shared simulation flow to threads
- MPI → Timestep loop: implements · Maps the shared simulation flow to ranks
- OpenACC → Timestep loop: implements · Adds accelerator directives to the shared simulation flow
- Offload → Timestep loop: implements · Adds offload execution to the shared simulation flow
- CUDA → Timestep loop: implements · Adds explicit GPU execution to the shared simulation flow
- OpenMP4 → Timestep loop: implements · Directive-based OpenMP execution of the shared simulation flow