Bringing Fortran and C++ together

puzzle

Parts of puzzle: If codes in different programming languages should work together, you will need tolls like an adapter. Foto: Adobe

Fortran and C++ are widely used in High Performance Computing (HPC), and often even codes or software written in these languages need to work together. To make this easier, Ivan Pribec, a researcher at the Leibniz Supercomputing Centre (LRZ) and part of the Computational X Support for supercomputer users, has developed an adapter. During the Platform for Advanced Supercomputing (PASC) conference in Davos, the chemical engineer presented this solution for better interoperability - and won one of the best scientific poster awards: a great opportunity to have new programming techniques and tasks explained by him.

Congratulation, Ivan, to the honored scientific poster at PASC23. What do you explain in your poster? Ivan Pribec: Thank you for the congratulations. My poster explains a solution for passing arrays between C++ and Fortran, two programming languages which are very common in HPC and wider. In software jargon this type of solution is known as an adapter – it makes two distinct entities interoperable by converting their interface to one that clients expect. 

Why are you interested in these both programming languages, Fortran and C++? Pribec: My original interest was in doing chemical engineering calculations, for things such as chemical reactors or industrial dryers. To do good work you need reliable and performant libraries of mathematical routines and numerical solvers. Many of these are coded in Fortran, C and C++.

How did you come up with the technical solution? Pribec: After familiarising myself with the new features of C++20 and Fortran in 2018, I was able to develop the solution step by step. For my own research, I had already written several wrapper libraries, i.e. libraries with unique, standardised interfaces for both programming languages. So I was familiar with the interoperability  of C and Fortran. I then attended a course on advanced C++ concepts given by the Erlangen computer scientist Klaus Iglberger. At the LRZ, I have been in charge of the CompBioMed Cluster of Excellence since the middle of 2022, which develops software, algorithms, simulations codes and HPC codes for medical and pharmaceutical problems. We work with several codes written in C++ as well as Alya, a large computational mechanics code for multiphysics calculations in Fortran. The question arose as to how we could optimise or simplify the exchange of data between these codes in the future. And so, step by step, the solution I presented at PASC23 emerged.

Why do researchers or scientists need your solution? Pribec: Increasingly, researchers rely on software to analyze their data and perform calculations. More and more specialist software libraries are written nowadays in C++ due to its powerful abstraction capabilities and performance. It makes sense to (re)use the libraries, if possible, rather than rewriting them in a different language. There is a saying among programmers that the best code is the code you don’t need to write yourself. At the same time, Fortran has a few tricks which make writing numeric codes very expressive and appealing to engineers. Researchers therefore very often work with both languages, and with my solution they can combine and mix them. 

Do you have more tricks for working with Fortran and C++?  Pribec: C++ has made some big strides recently introducing two new standard containers, the span and mdspan. These can already be a big benefit for interoperability, without much extra effort or the adapter solution.

You are in charge of the Cluster of Excellence CompBioMed at the LRZ - do you also have to deal with the interoperability of Fortran and C++?  Pribec: CompBioMed explores multiphysics simulation to couple different physical models, such as a model of the electrophysiology and mechanics of the heart with a model of blood flow in arteries and veins. Depending on the expertise and skills of the researchers, such models are written in different programming languages, but need to work together on the supercomputer. There are several ways to couple these different codes: via external files, message passing, or library calls. The adapter I have developed is intended to simplify the writing of code in the coupling layer.

What are your tasks for CompBioMed? Pribec: CompBioMed focuses on the digitalisation of medicine and pharmaceutical research, with the aim of developing a digital twin for humans or the Virtual Human. My main role is to coordinate the Data Management and Analysis work package, monitor the team's solutions and progress, ensure the exchange of information between the partner institutions involved, and prepare presentations and reports. In collaboration with the researchers and developers, I also help prepare existing CompBioMed codes for the next generation of supercomputers, the exascale computers. For example, we help them with porting to the newer Graphics Processing Units, GPUs, test software and develop benchmarks for performance comparisons.

You will also be involved in the preparations for the CompBioMed Conference in Garching near Munich starting at September, 12th, 2023. Pribec: The conference will be a showcase of the progress achieved in biomedical computing. My responsibility is to make things run smoothly on site, related to the venue and conference program. Luckily, I am supported by colleagues at LRZ, and the rest of the Organisation Committee.

Do-you show you poster there? Pribec: Yes, I’d like to do so, but with a few more enhancements and practical usage examples.

What is your background and how did you come to the LRZ and CompBiomed? Pribec: I was born in Australia, grew up in Slovenia and studied chemical engineering at the University of Ljubljana. After that I wanted to do a PhD at the Technical University of Munich, TUM, and at the Chair of Brewing and Beverage Technology in Weihenstephan. I worked on various interesting topics, such as pasta drying, cell population balances, surface tension measurements, and also with lattice Boltzmann methods. At Weihenstephan, they gave me a lot of support and allowed me to develop my own ideas. I was also a certified beer taster and regularly tasted new beers. After four years, I decided to dive deeper into the world of computers and applied to the LRZ and the CompBioMed project,

What are your plans for the near future? Pribec: I am currently writing two technical papers on variants of the lattice Boltzmann methods as part of my PhD work. I‘d like to defend my thesis next year. Since I joined the LRZ, I have become more and more interested in good and sustainable software practices, and this is a topic I would like to pursue further. I would also like to learn more about performance tuning in HPC and the programming of Graphics Processing Units, GPU. And of course, I would like to see how the Fortran/C++ adapter is accepted by the programming community and how it evolves. (Interview:vs)

You will find Ivan Privbec's poster here: https://tiny.badw.de/zOEcHP

IP

Ivan Pribec, researcher at LRZ