Disclaimers:
- This query is reposted from SO upon SO person’s suggestion to place it right here since there is no such thing as a particular code in query.
- This query is a subset of my bigger theme of Fortran modernization.
- There are helpful variations of this query requested already (1, 2, 3) and weblog posts, and though useful, I’m curious of what’s finest follow now (a few of these posts are 5-10 years previous) and the context of my state of affairs, which is the rationale for asking it in an identical manner.
Our present code base is basically Fortran (400Ok LOC, most F90/some F77/possibly some newer variations), dispersed amongst some 10 separate dev groups (organizationally) in (considerably) standalone modules.
We’re exploring the most effective follow thought of taking a type of modules and writing it in a faster-to-develop language (Python), and wrapping and increasing bottlenecks in Fortran.
Nonetheless, because the module is at the moment fully in Fortran and interacts with different Fortran modules and a fundamental Fortran loop, we have to hold the looks or interface of the module to fundamental Fortran loop the identical.
So the incremental change strategy for this Fortran module – and different equally architected Fortran modules – is to maintain the interfaces the identical and alter the internals.
In different phrases, the shell or signature of the Fortran subroutines or features can be unchanged, however the performance contained in the operate can be modified.
This performance contained in the operate is what we wish to rewrite in Python.
From discussions on-line – and my instinct, no matter that’s value – it appears unadvised to embed Python like this, and as an alternative do the reverse: prolong Python with Fortran (for bottlenecks, as wanted).
Nonetheless, this embedding Python strategy appears the one logical, smallest, atomic step ahead to isolate modifications to the bigger Fortran system.
It seems that there are some choices for this embedding Python downside.
Essentially the most future-proof and steady manner is through ISO_C_BINDING and utilizing the Python C API (in principle…).
There are additionally steady options through Cython and possibly ctypes which can be dependable and nicely maintained.
There are extra dependency-heavy approaches like cffi and forpy, that introduce complexity for the advantage of not writing the extra C interface code.
We’re additionally conscious of easy system calls of Python scripts from Fortran, however these appear too disk write/learn heavy; we would like to do minimal disk reads/writes and hold the array passing in reminiscence (hopefully simply pointer areas handed, not array copies).
One other constraint is that this Fortran-Python interface ought to be capable of deal with commonest datatypes and buildings, together with multi-dimensional arrays, or no less than have a method to decompose complicated customized datatypes to some assortment of less complicated datatypes like strings and arrays.
Given the above description, do you’ve got any recommendation on what are the most effective follow methods which can be at the moment accessible to name Python (or different related versatile language) from Fortran (say, utilizing 2003 or 2008 variations; undecided if all 2018 options are carried out in our Intel Fortran compiler)?