Fortran Carpentries

Durham HPC Days 2026

Connor Aird

University College London

2026-06-16

Current state of Fortran testing

Some known Fortran projects

Repository Description Integration tests Unit tests
epochpic/epoch Popular particle-in-cell plasma code

ukaea/ReMKiT1D Framework for 1D multifluid and kinetic simulations of Tokamaks

geoschem/geos-chem Popular atmospheric chemistry code

MetOffice/ukca The UK’s main atmospheric chemistry code

MetOffice/lfric_core The Met Office’s next generation weather model

Why is testing Fortran hard

Note that these points are from my experience in academia.

  • Fortran is often legacy code.
    • Lots of global state.
    • Lack of units to test.
    • Locked into specific compilers or dependencies.
  • Many custom testing setups exist
    • Test frameworks do not benefit from open source contibutions.
  • Lack of know-how
    • Developers are often PhD students new to Fortran development.
  • Unclear which frameworks to choose.

Available frameworks

Fortran wiki

A list of known Fortran testing frameworks on the Fortran wiki

Fortran-lang

A list of Fortran libraries and tools on the fortran-lang website.

My chosen framework

The framework I tend to choose to work with is pFUnit, because…

  • Previous experience within our department.
  • Open source and still being developed.
  • Appears to be the most fully featured.
  • Most importantly, supports unit testing MPI parallelised code.

What is pFUnit

Overview of pFUnit

  • Created by developers from NASA.
  • Open source on GitHub and accepting contributions - Goddard-Fortran-Ecosystem/pFUnit
  • Availale under a NASA OPEN SOURCE AGREEMENT VERSION 1.3 licence
    • Permissive license similar to MIT and BSD but there are differences.
  • Uses a preprocessor to convert .pf files to .f90.
  • Follows the style of JUnit. i.e. Directives (annotations in JUnit) label code sections for the preprocessor.
  • F2003 object oriented features and some F2008 features, thus requires more recent versions of compilers.

Syntax

.pf syntax is similar to .f90 with preprocessor directives, such as @Test and @assertEqual.

module test_something
    use maths_operations, only : double_int
    use funit
    implicit none

contains

    @Test
    subroutine test_double_int_1()
        integer :: input, actual_output

        input = 1

        call double_int(input, actual_output)

        @assertEqual(2, actual_output, "Unexpected output from double_int")
    end subroutine test_double_int_1
end module test_something

The preprocessor

  • Written in Python.
  • Converts .pf with directives into .f90.
  • Called automatically when building with Make or CMake.
  • Directives exist for the following tasks
    • Labeling subroutines as tests.
    • Parameterising tests.
    • Labelling subroutines as setup and teardown steps.
    • Specifying assertions.

Assert preprocessor directives

Software carpentries

The Carpentries teaches foundational coding and data science skills to researchers worldwide.

Carpentries and the incubator

  • Carpentries lessons are small, volunteer-led, hands on workshops.
  • The incubator is a space to host lessons that are still in-development.
  • Lessons can remain in the incubator for years.
  • Incubator lessons can still be taught.
  • Lessons move through the lesson life cycle.

Workshop material

  • A Fortran curriculum is in-development.
  • Further lessons are planned

flowchart TD
    accTitle: Learner Pathways for the Introduction to Modern Fortran Course
    accDescr {This diagram shows the possible learning pathways after completing the Introduction to Modern Fortran course.
    The Intermediate and Advanced Topics in Modern Fortran courses are in the pre-alpha stage.
    The MPI and OpenMP courses are from ARCHER2, the UK's national supercomputing facility, courses.}
    A("Introduction to Modern Fortran") --> B
    B(Intermediate Modern Fortran) --> C & D & E
    C(Advanced Topics<br>in Modern Fortran)
    D(Message-passing<br>Programming with MPI)
    E(Shared Memory<br>Programming with OpenMP)
    F(Making Legacy Fortran Sustainable) --> G
    B --> G(Unit Testing in Fortran)

    linkStyle default stroke:#000,stroke-width:2px
    classDef archer2 fill:#201f5e,stroke:#fff,stroke-width:1px,color:#fff
    classDef default fill:#ddd,stroke:#000,stroke-width:1px,color:#000
    classDef existing fill:#ddd,stroke:#000,stroke-width:1px,color:#2a78dd
    class D,E archer2
    class A,G existing
    click A href "https://carpentries-incubator.github.io/intro-to-modern-fortran/" "Link to the Introduction to modern Fortran Course"
    click G href "https://carpentries-incubator.github.io/fortran-unit-testing/" "Link to the Unit Testing in Fortran Course"
    click D href "https://www.archer2.ac.uk/training/courses/#message-passing-programming-with-mpi" "Link to the MPI Archer2 Course"
    click E href "https://www.archer2.ac.uk/training/courses/#shared-memory-programming-with-openmp" "Link to the OpenMP Archer2 Course"

Get involved

  • Future workshops will deliver the lessons that have been developed so far.
  • If you are interested, sign-up to our mailing list.
  • We are also happy to accept contributions to the material (i.e. worked examples, curriculum suggestions)

Acknowledgements

Thank you

Scan to view the slides

QR code linking to this talk's web page.