Sometimes, we need to use some fortran code in our project. A good practice is that we can compile the .f90 codes into dynamic link libraries (.so in Linux or .dll in windows). Then, we can use the ctypes in python to load the libs and get the handlers.
# as dynamic link lib
mpifort -fPIC -shared -o libtest.so test.f90
python test.py-
we use
subroutinein fortran to provide the interface. However, there is no return value. There is a smart way that we can make the following argreement.- the
subroutinewe need to use in fortran only accept array as arguments. - we use
numpy.arrayto pass arguments to the fortran handler.
- the
-
Pay attention to the difference in the memory modle between C and fortran. Defenitely, we use the
Cinterface in python.
- MPI Use.
- Optimize fortran
subroutinein python byscipy.optimize.