Cracking the Code - Porting Energy Diagnostics from Fortran to C++
Lauenburg, 6 August 2025 – After diving deep into climate event detection during the first coding challenge, days 8-10 of the hpc4climate 2025 Summer School shifted gears into a high-performance computing challenge that pushed participants to their limits: porting ICON’s Fortran energy diagnostics to C++ using Kokkos – and then testing its correctness and performance on both CPUs and GPUs.
Energy diagnostics are crucial within the ICON climate model, as they calculate and monitor the distribution of energy in the atmosphere. This is key to improving the representation of convection, radiation, and turbulence effects in weather and climate simulations. But as modern supercomputers increasingly combine heterogeneous architectures, the question arises: how can we make this code portable and efficient across different systems?
An Exercise in Three Acts
Students, split into 10 teams, were tasked to:
- Port key Fortran routines (computing energy density and energy content) into C++ using Kokkos parallel programming patterns.
- Integrate the C++ version into ICON via Fortran bindings and ensure the whole model compiled.
- Validate and benchmark the new implementation against the original, comparing results on both CPU and GPU runs.

Challenges Along the Way
Participants quickly discovered that software engineering for climate science is not for the faint of heart. From the presentations, several common hurdles emerged:
- A steep learning curve for Kokkos, especially for those new to bindings and parallel programming.
- Compilation issues on GPU builds – “catastrophic errors” were a constituting part of the exercise.
- Complexity in understanding wrapping and interoperability between Fortran and C++.

Successes and Lessons Learned
Despite the hurdles, all groups managed to produce a C++ version of the energy diagnostics and hook it into ICON. While not every team reached full correctness and performance verification, a few achieved performance comparisons and even identified functions affecting runtime efficiency.
This challenge was definitely one with quite a few take-aways:
- Collaboration matters: Teams self-organized based on experience, showcasing leadership and knowledge sharing.
- Good practices: “Save before committing” became a mantra. Asking questions, even seemingly basic ones, helped everyone progress.
- Understanding complexity: Porting scientific code for performance portability is a non-trivial, multi-layered task.
And above all, as one team concluded:
“It’s all about the friends you make along the way.”
Why It Matters
Exercises like this one show the real challenges of modernizing climate codes: balancing numerical correctness, code maintainability, and performance portability. They prepare the next generation of scientists and developers to work on the cutting edge of exascale climate simulations.
