Fork me on GitHub
Credit and license

Mixed Martial Arts: Interfacing Fortran, C, C++, and Python for Great Good!

Status

This lesson is currently under construction - feedback and suggestions are most welcome.

Learning goals

The programming languages Fortran, C, C++, and Python each have their strengths and weaknesses and their own fan base. This workshop is for people who would like to be able to combine these languages within one code project:

  • When writing a high-level abstraction layer or interface to a “bare metal” legacy software written for instance in Fortran or C.
  • When writing an efficient back-end to a code mainly written in a high-level language such as Python.
  • When combining modules written in different programming languages.
  • When writing a Python interface to a software in C or C++ or Fortran to leverage the wealth of libraries available in Python.

Prerequisites

To appreciate the material it helps to have some previous exposure to Python and a compiled language (such as C, C++, or Fortran).

To traverse the material you will need a C++ compiler which is C++11 compliant, a Fortran compiler, CMake, Make, Git and a couple of Python packages.

Schedule

13:00 Motivation Why is one programming language often not enough?
13:10 Overview over different approaches Which tools are out there?
13:20 Hands-on example using PyBind11 What tool do you recommend to interface Python and C++?
14:00 Break
14:10 Fortran, C and C++ talking to each other How can we couple Fortran with C/C++?
What is name mangling?
How can we avoid worrying about it?
How can we safely pass data types across languages?
14:30 Using the C Foreign Function Interface for Python Is there a non-intrusive way to couple C/C++/Fortran and Python?
Can I test my Fortran code with Python?
15:10 Memory allocation for arrays that pass the API Where and how should we allocate memory?
15:20 API design How can we create composable code units?
How can we improve the API to make it easier to understand and use?
15:40 Roadmap for migrating and modularizing legacy code Big untested legacy monolith code in front of you - what now?
15:50 Finish