Skip to content

Using Submodule Files in Fortran Applications

JulesKouatchou edited this page Sep 27, 2024 · 20 revisions

Definition

A submodule is a program unit that extends a module or another submodule.

Submodules can access the things declared in their parent module or submodule by host association - the source code can still access PRIVATE things in the same way that it could if it was still part of the physical source code of the parent.

Access to parent's entities

A submodule can access the entities from its parent module or submodule by host association. Unlike a module, a submodule cannot be referenced in other program units by use association. Entities declared in a submodule are only accessible from the submodule and its descendent submodules. Therefore, asubmodule of a module does not USE the parent module.

The submodule statement that starts a submodule program unit identifies the module (and perhaps another submodule) that it extends.

Naming submodules

  • A submodule cannot have the same name as other global entities.
  • The name of a submodule can be the same as the name of another submodule if they do not have the same ancestor module.

Compilation

A parent module can be broken into submodules to avoid compilation cascades, if relevant to the processor being used. Changes to a module require recompilation of that module (and its descendants), and then recompilation of all program units that use that module (and their descendants). Therefore, because of the cascading effect, we will need to recompile all the descendant modules of the modified modules.

Even if a module procedure implementation in a submodule is changed, as long as the module procedure interface declared in the ancestor module remains the same, a recompilation would not be needed for the user of the module. The one of advantages of using submodules is that when one submodule is changed, recompilation is only needed for the submodule and its descendant submodules. This could reduce the rebuilding time for a complex system.

Submodules don’t make your code any faster (nor any slower), but they can lead to a dramatic improvement in programmer productivity through better partitioning and reduced build times.

References

Clone this wiki locally