P11 - Bridging the Language Gap: Classes for C++/Fortran Interoperability
DescriptionFortran and C++ remain popular languages for high-performance scientific computing. Interoperation of these two languages is of great interest; be it to take advantage of a mature ecosystem of libraries, or for coupling individual simulation codes into larger multi-scale or multi-physics applications. Fortran 2018 introduced enhanced facilities for interoperability with C including an API for passing and manipulating Fortran arrays (including those with allocatable and pointer attributes). This is achieved by means of a C descriptor - an opaque C structure type - and an accompanying library of functions. In this contribution I present a handful of new templated C++ classes that wrap the C descriptor and expose native semantic features of C++ including iterators, range-based for loops and elemental access operators. Implicit casts to std::span (C++20) and std::mdspan (C++23) containers enable efficient reuse of C++ routines. Reuse of Fortran routines from C++ is also simplified through the use of class template argument deduction (CTAD) to construct compatible C descriptors for popular C++ container and array types.
TimeMonday, June 2611:20 - 11:50 CEST
Event Type