# uk-mac/cloverleaf architecture

> Architecture diagram of the GitHub repository uk-mac/cloverleaf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uk-mac/cloverleaf
- Repository: https://github.com/uk-mac/cloverleaf

## Overview

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`](https://github.com/uk-mac/cloverleaf/tree/master/Makefile) (Makefile), [`CloverLeaf_ref`](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_ref) (Ref core), [`CloverLeaf_Serial`](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_Serial) (Serial), [`CloverLeaf_OpenMP`](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenMP) (OpenMP)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build"]
  node_makefile["Makefile<br/>build system"]
  node_readme["README<br/>repo guide<br/>[README.md]"]
end

subgraph group_core["Core simulation"]
  node_init_state["Init state<br/>startup phase"]
  node_timestep_loop{{"Timestep loop<br/>solver loop"}}
  node_physics_kernels["Physics kernels<br/>numerics"]
end

subgraph group_backends["Execution backends"]
  node_ref_core["Ref core<br/>canonical hybrid impl"]
  node_serial["Serial<br/>single-process impl"]
  node_openmp["OpenMP<br/>shared-memory impl"]
  node_mpi["MPI<br/>distributed-memory impl"]
  node_openacc["OpenACC<br/>accelerator impl"]
  node_offload["Offload<br/>accelerator impl"]
  node_cuda["CUDA<br/>gpu impl"]
  node_openmp4["OpenMP4<br/>directive impl"]
end

subgraph group_runtime["Runtime data"]
  node_clover_in["clover.in<br/>runtime input"]
  node_bench_inputs["Bench inputs<br/>benchmark inputs"]
  node_self_test(("Self-test<br/>validation mode"))
  node_diag_output["Summary output<br/>diagnostics"]
end

node_makefile -->|"builds"| node_ref_core
node_makefile -->|"builds"| node_serial
node_makefile -->|"builds"| node_openmp
node_makefile -->|"builds"| node_mpi
node_makefile -->|"builds"| node_openacc
node_makefile -->|"builds"| node_offload
node_makefile -->|"builds"| node_cuda
node_makefile -->|"builds"| node_openmp4
node_readme -->|"documents"| node_makefile
node_readme -->|"describes"| node_bench_inputs
node_clover_in -->|"drives"| node_init_state
node_self_test -->|"falls back to"| node_init_state
node_init_state -->|"enters"| node_timestep_loop
node_timestep_loop -->|"uses"| node_physics_kernels
node_timestep_loop -->|"emits"| node_diag_output
node_bench_inputs -->|"provide"| node_clover_in
node_ref_core -->|"specializes to"| node_serial
node_ref_core -->|"specializes to"| node_openmp
node_ref_core -->|"specializes to"| node_mpi
node_ref_core -->|"extends to"| node_openacc
node_ref_core -->|"extends to"| node_offload
node_ref_core -->|"extends to"| node_cuda
node_ref_core -->|"extends to"| node_openmp4
node_serial -->|"implements"| node_timestep_loop
node_openmp -->|"implements"| node_timestep_loop
node_mpi -->|"implements"| node_timestep_loop
node_openacc -->|"implements"| node_timestep_loop
node_offload -->|"implements"| node_timestep_loop
node_cuda -->|"implements"| node_timestep_loop
node_openmp4 -->|"implements"| node_timestep_loop

click node_makefile "https://github.com/uk-mac/cloverleaf/tree/master/Makefile"
click node_readme "https://github.com/uk-mac/cloverleaf/blob/master/README.md"
click node_ref_core "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_ref"
click node_serial "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_Serial"
click node_openmp "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenMP"
click node_mpi "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_MPI"
click node_openacc "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenACC"
click node_offload "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_Offload"
click node_cuda "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_CUDA"
click node_openmp4 "https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenMP4"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_makefile,node_readme toneBlue
class node_init_state,node_timestep_loop,node_physics_kernels toneAmber
class node_ref_core,node_serial,node_openmp,node_mpi,node_openacc,node_offload,node_cuda,node_openmp4 toneMint
class node_clover_in,node_bench_inputs,node_self_test,node_diag_output toneRose
```

## Components

### Build

Top-level build and repository guidance

- [Makefile](https://github.com/uk-mac/cloverleaf/tree/master/Makefile): build system · Single build entrypoint with compiler and flag selection · `Makefile`
- [README](https://github.com/uk-mac/cloverleaf/blob/master/README.md): repo guide · Build, usage, reproducibility, and benchmark notes · `README.md`

### Core simulation

Shared hydrodynamics flow and validation paths

- **Init state**: startup phase · Initializes mesh and problem state before time stepping
- **Timestep loop**: solver loop · Hydrodynamics update loop that advances the simulation
- **Physics kernels**: numerics · Core update logic shared across execution models

### Execution backends

Parallel and accelerator variants of the same solver

- [Ref core](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_ref): canonical hybrid impl · Reference MPI + OpenMP implementation that other variants track · `CloverLeaf_ref`
- [Serial](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_Serial): single-process impl · No MPI or OpenMP · `CloverLeaf_Serial`
- [OpenMP](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenMP): shared-memory impl · OpenMP-only execution variant · `CloverLeaf_OpenMP`
- [MPI](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_MPI): distributed-memory impl · MPI-only execution variant · `CloverLeaf_MPI`
- [OpenACC](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenACC): accelerator impl · MPI plus directive-based accelerator support · `CloverLeaf_OpenACC`
- [Offload](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_Offload): accelerator impl · MPI plus Intel offload path · `CloverLeaf_Offload`
- [CUDA](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_CUDA): gpu impl · MPI plus explicit CUDA GPU support · `CloverLeaf_CUDA`
- [OpenMP4](https://github.com/uk-mac/cloverleaf/tree/master/CloverLeaf_OpenMP4): directive impl · Additional directive-based OpenMP variant · `CloverLeaf_OpenMP4`

### Runtime data

Input, benchmark, and output artifacts

- **clover.in**: runtime input · Required working-directory input for a normal run
- **Bench inputs**: benchmark inputs · Standard problem-size inputs used for scaling and regression runs
- **Self-test**: validation mode · Built-in known-solution check when no input file is present
- **Summary output**: diagnostics · Periodic and final state summaries for checking and regression

## Connections

- 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
