8. Optimization
Implementation
Cluster Setup (1.1 & 1.2)
The repository was cloned directly on the Draco login node and the Chapter 6
input data was fetched via wget. Compilation uses the same SCons-based
build as locally; SCons itself was installed once into the user environment
through module load tools/python/3.8 followed by pip install --user
scons. Compilation runs on the login node, simulations strictly on
compute nodes — either through an interactive allocation
(salloc --partition=short) or via sbatch.
Reproducing the Chapter 6 Chile event on Draco yields a NetCDF result that matches the local run bit-for-bit (same domain, same \(\Delta t\), same checkpoint), confirming that the build behaves identically on both machines.
Time Measurement (1.3)
To compare the cluster against the local machine we added a wall-clock
timer to main.cpp that wraps only the compute kernel
(setGhost + timeStep). File I/O (NetCDF / CSV / station writes),
the initial cell sampling and all allocations are deliberately outside the
measured region, as requested by the task.
std::chrono::nanoseconds l_computeDuration{0};
tsunami_lab::t_idx l_iterCount = 0;
while (l_simTime < l_endTime) {
// ... I/O and station writes (not timed) ...
auto l_tic = std::chrono::steady_clock::now();
l_waveProp->setGhost(l_bcLeft, l_bcRight);
l_waveProp->timeStep(l_scaling, l_solverMode);
l_computeDuration += std::chrono::steady_clock::now() - l_tic;
l_iterCount++;
l_timeStep++;
l_simTime += l_dt;
}
After the loop the solver prints the totals and the normalized metric time per cell and iteration:
This metric is independent of grid size and run length and is therefore the quantity used to compare the two machines.
Results & Visualizations
Both runs use the same setup, the same input files and the same end time on a checkpoint of the Chile scenario:
./build/tsunami_lab -n 500 -t 1000 -p TsunamiEvent2d \
resources/chile/output/chile_gebco20_usgs_250m_bath_fixed.nc \
resources/chile/output/chile_gebco20_usgs_250m_displ_fixed.nc
Resulting domain: \(500 \times 421 = 210{,}500\) cells at a cell size of \(7000\,\text{m}\). Both runs resumed from the same checkpoint at \(t \approx 931.63\,\text{s}\) and executed 6 timesteps to reach \(t = 1000\,\text{s}\).
Machine |
Compute wall-clock |
Iterations |
\(t_{\text{cell,iter}}\) |
|---|---|---|---|
Local (macOS) |
\(0.1079\,\text{s}\) |
6 |
\(\approx 85.5\,\text{ns}\) |
Draco |
\(0.0683\,\text{s}\) |
6 |
\(\approx 54.1\,\text{ns}\) |
The compute kernel runs roughly 1.58× faster per cell and iteration on the Draco compute node compared to the local machine. Note that the sample covers only 6 iterations because both runs were resumed from a checkpoint close to the end time; a longer run gives a more stable estimate, but the relative ordering is consistent across repetitions.
Compilers (8.2)
Generic Compiler Support (8.2.1)
The build script was extended to honour the CXX environment variable so
that any compiler can be selected without editing SConstruct. The
surrounding shell environment is forwarded into SCons (ENV = os.environ)
and, if present, CXX overrides the compiler:
env = Environment( variables = vars, ENV = os.environ )
if 'CXX' in os.environ:
env['CXX'] = os.environ['CXX']
A build with Clang is therefore a one-liner: CXX=clang++ scons. Four
further build options were added for the compiler study:
Option |
Effect |
|---|---|
|
optimization level ( |
|
target architecture ( |
|
Clang optimization remarks ( |
|
toggle inlining ( |
Optimization Switches and Numerical Implications (8.2.3)
-O2 and -O3 are IEEE-754 conforming. -Ofast additionally enables
-ffast-math, which relaxes the floating-point model: it allows
reassociation of operations, assumes no NaN/Inf operands
(-ffinite-math-only) and flushes denormals to zero. This permits faster
code — vectorizable reductions, cheaper sqrt/division — but can change
results in the last bits and breaks code that relies on IEEE corner cases.
The f-wave solver only operates on well-behaved positive water heights, so the
relaxed model is safe here and the simulation output is unaffected.
A subtle side effect surfaced during the study: under -ffast-math the LLVM
compilers (clang++ and icpx) fold sin(pi*x) in the
ArtificialTsunami2d setup into calls to sinpif/cospif from Intel’s
math library libimf. icpx links libimf automatically, but plain
clang++ does not, producing an undefined reference at link time. The
build script therefore links -limf explicitly for the LLVM compilers;
GCC + glibc never emit these symbols.
Compiler and Flag Comparison (Compilers 2 & 3)
All three compilers available on Draco — GCC 12.2, the bundled upstream LLVM
clang++ and Intel’s icpx — were benchmarked on an exclusive short
node. Each variant is recompiled from scratch and run back-to-back on the
same Tohoku scenario (250 m bathymetry, -n 1000, -t 7200) by a single
batch script, so the only difference is the compiler / flags. Reported is the
normalized time per cell and iteration in nanoseconds (lower is better):
Compiler |
|
|
|
|
|---|---|---|---|---|
GCC 12.2 |
46.08 |
41.04 |
37.01 |
30.34 |
Clang (LLVM) |
45.09 |
42.78 |
40.31 |
37.22 |
icpx |
38.74 |
— |
40.42 |
37.04 |
Observations:
Vectorization is the single largest lever. Adding
-march=native(AVX-512 on the Ice Lake nodes) cuts GCC from 37.01 to 30.34 ns (−18 %) and Clang/icpx by ≈ 8 %. Without-marchthe compilers target the generic x86-64 baseline (SSE2) and cannot use the wide vector units. This answers the task’s question: yes, the per-edge time-step loop is auto-vectorizable, but only once a suitable architecture is specified.GCC produces the fastest code at its best setting — 30.34 ns vs. ≈ 37.2 ns for both LLVM compilers, a ≈ 19 % lead.
Optimization level scales as expected for GCC:
-O2→-O3gains ≈ 11 %, and the step to-Ofastanother ≈ 10 % from-ffast-math(reassociation and cheapersqrt/division in the solver).icpx defaults to fast-math. Its
-O2already uses the relaxed floating-point model, soicpx -O2(38.74 ns) is not directly comparable to the IEEE-strictgcc -O2/clang -O2, and-Ofastbrings it no further benefit. The strict baselines are consistent at ≈ 45–46 ns.
Absolute numbers carry a few percent of run-to-run noise (e.g. gcc -O2
measured 40–46 ns across batch jobs); the relative ordering above is stable
across repetitions.
Vectorization, Inlining and Reports (8.2.4)
Disabling inlining isolates its cost:
Variant |
\(t_{\text{cell,iter}}\) |
|---|---|
|
37.01 ns |
|
62.59 ns |
Turning off inlining makes the solver 69 % slower. This confirms that the
f-wave solver is inlined under optimization: waveSpeeds,
waveStrengths, flux and deltaXPsi are folded into netUpdates,
removing four function calls per cell edge per timestep. Inlining is also a
prerequisite for vectorization — only the inlined loop body exposes the
independent per-edge work that -march=native can then vectorize, which is
why the two largest speedups (inlining and SIMD) are coupled.
The report=1 option adds Clang’s -Rpass=.*, -Rpass-missed=.* and
-Rpass-analysis=.* remark flags. Building with report=1 was used to
inspect the time-step loop: with arch=native the inner loop is reported as
vectorized (loop-vectorize), whereas at the generic baseline the same loop
appears under -Rpass-missed — consistent with the measured AVX-512 speedup
and with the f-wave functions being inlined into the hot loop.
Instrumentation and Performance Counters (8.3)
VTune Profiler was made available on Draco via:
export PATH=/cluster/intel/oneapi/2025.0.0/vtune/2025.0/bin64:$PATH
The GUI was launched on the login node with X-forwarding (ssh -X).
A Hotspots analysis was configured for the solver binary and executed on a
compute node — interactively first, then as a batch job. The solver was
recompiled with scons inline=0 (enables -g -fno-inline) for
finer-grained results.
Function |
CPU Time |
% of CPU Time |
|---|---|---|
|
16.288 s |
34.8 % |
|
13.297 s |
28.4 % |
|
11.925 s |
25.5 % |
|
3.000 s |
6.4 % |
|
1.510 s |
3.2 % |
The F-Wave solver functions dominate with ~95 % of CPU time — specifically
netUpdates, waveStrengths, timeStep and waveSpeeds. This
was expected: netUpdates is called for every cell edge at every
timestep, making it the innermost hot loop of the simulation. Physical
core utilization was 2.0 % (0.941 / 48), confirming the solver is
single-threaded.
The following optimizations target the hotspots directly:
Inlining — with
inline=0(profiling build),waveStrengths,waveSpeeds,fluxanddeltaXPsiare all separate call sites insidenetUpdates. Re-enabling inlining folds all of them into a single function body, eliminating four function calls per edge per timestep at \(O(n_x \cdot n_y)\) call sites.Redundant ``sqrt`` —
waveSpeedscomputes three square roots:std::sqrt(i_hL),std::sqrt(i_hR)andstd::sqrt(l_hRoe). The third can be replaced by \(0.5(\sqrt{h_L} + \sqrt{h_R})\), reusing the already-computedl_hSqrtLandl_hSqrtRand saving onesqrtcall per edge.Redundant division —
fluxis called twice insidewaveStrengthsand each call computesi_hu / i_h. The velocitiesl_uLandl_uRare already computed innetUpdatesand could be passed intowaveStrengthsdirectly to avoid the redundant division.SIMD vectorization — building with
arch=icelake-serverenables AVX-512 on Draco’s Ice Lake nodes. The per-edge computation intimeStepis independent across edges; with inlining enabled the compiler can auto-vectorize the loop and process multiple edges per clock cycle.
Individual Contributions
Jan Vogt: Cluster setup on Draco (clone, modules, SCons install, interactive and batch runs reproducing Ch. 6). Implementation of the
std::chronotimer around the compute kernel inmain.cppand derivation of the normalized time per cell and iteration metric. Local vs. Draco comparison.Yannik Köllmann: VTune Hotspots analysis (interactive and batch), profiling build (
scons inline=0), hotspot interpretation and documentation of section 8.3.Mika Brückner: Compiler support in the build script (
CXXenvironment variable; theopt,arch,reportandinlineoptions). Compiler and optimization-flag study on Draco (GCC vs. Clang vs. icpx;-O2/-O3/-Ofast;-march=native/AVX-512; inlining), including the automated batch benchmark, thelibimf/sinpiflink fix and the analysis in the Compilers section.