I’d like to call an externally compiled Fortran routine, passing input and output variables, from python in two steps.
-
an initial call, which is very slow, it will read a lot of data files and allocates variable structures, etc., in the Fortran program
-
millions of subsequent calls which only take milli-seconds to do the actual computations.
subroutine crunch(input, output)
implicit none
real,intent(in) :: input
real,intent(out) :: output
logical,save :: firstCall=.true.
real,save :: data(10000)
if (firstCall) then
!--- initialisation: reads data from files ---
firstCall = .false.
endif
!--- the actual computations, which depend on input and data ---
output = ...
end subroutine
So the variable structures (here called “data”), resulting from call (1) must stay in the memory of the Fortran routine.
Thanks, your help is appreciated
I could only find examples of single calls where all initialisations of the Fortran routine are erased on exit
pw31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.