I am currently working on a large fortran 90 code. Most of the modules have a large number of subroutines (>15). The modules USE other modules in its specification part, while their subroutines USE other modules on top of that. Here is what it looks like:
MODULE OneModule
USE GlobalConstant
USE GlobalVariable
CONTAINS
SUBROUTINE Subroutine1()
[...]
END SUBROUTINE Subroutine1
SUBROUTINE Subroutine2()
USE Mesh
[...]
END SUBROUTINE Subroutine2
[Other Subroutines]
END MODULE OneModule
Seeing this in every module, I was wondering if that was done for the sake of clarity or optimisation. If the module OneModule has a large number of subroutines, does it affect performance if we USE the module MESH in the specification part if only a handful of those subroutines need it?
I would be stunned (and writing a bug report to the compiler vendor) if the positioning of USE made any difference to execution times, given typical compiler implementation. It might make an inconsequential difference to compilation time.
Positioning in inner or outer scopes is more a question of preferred programming style intersected with program requirements for identifier accessibility.
(There is one exception, but it isn't relevant here. F2003 introduced a set of intrinsic (compiler provided) modules for IEEE floating point support. The mere presence of some of these modules can change the code that a compiler generates for anything in the scope of the USE.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With