How can I adapt such legacy Fortran (f77 like) code to using modules?

99 Views Asked by At

I have a scientific simulation program in Fortran. It uses some f90 syntax/capabilities (mainly direct operations on arrays) but is otherwise architecturally f77, ie it's simply a collection of functions and subroutines, grouped/organized in different .f files according to what general, larger "functionality" or "block" they are a part of.

These files are typically either "libray like" (eg there's a .f which is a collection of subroutines for a given scientific domain, another .f for another scientific domain...) or "functionality"-linked (eg if there is a result used or required by the global program / simulation, that requires some "significant" algorithms or code, then all relevant specific functions / calculations / algorithms required to produce this result will be grouped in the same file).

A typical project like this has about 20-30 such files total. It has worked, and has been continuously developed, fine like that for years (and still does, to be fair). We use gcc/gfortran, usually in its latest available revision.

I am trying to assess how modules could, at least progressively, be introduced/used ; mainly hoping this will allow for some additional compiler optimizations and thus execution time speed-up, although expected better checking is of course also always a positive (we do have / already run global static analyzers on the program of course)).

At least as a first step and in a "quick win" mindset, can I "simply"

  • keep the physical (eg files) organization as-is
  • wrap an existing file with
module x

contains

(existing code, eg collection of thematically linked subroutines and functions, here)

end module
  • add a "use" statement where needed

  • make sure these now "modules" are being seen / compiled first by the compiler.

And expect to start benefitting from what modules are supposed to allow for (better compiler optimizations and additional checks) ? It looks like doing this works fine, but is there some additional work required to leverage advantages of using modules ?

0

There are 0 best solutions below