Load all configuration parameters once, at the beginning of the DYNAMICO initalisation
Instead of reading parameters with IOIPSL getin()
at different points in space and time, it would be better to read them once at the beginning of the initialization phase. Many of these parameters are kept in specific modules, which creates an illusion of an encapsulation, but it is only a semantic grouping (parameters connected to a specific part of DYNAMICO, like caldyn or output_fields). In fact, they are not encapsulated because there is no setter/getter mechanism making sure that each reading of a parameter returns a correct value (in programming, encapsulation is not only about hidding/grouping data, but also about creating a reasonable method of accessing/modifying it).
In short, the parameters are accessible everywhere, but they are not necessary correct everywhere. Recent case of this is the hydrostatic
parameter which was initialized with getin
in init_caldyn
, but previously used uninitialized in init_restart
. Another case, is the xios_output
parameter read for the first time in output_field_init
, but also used in init_etat0
(this is actually something I have coded).
In future, this will cause more problems as the sequence of their initialization is obstructed. The solution would be to read all parameters at the beginning of the initialization. I would argue that this is the normal approach, as usually programs read the whole configuration file at once and then store the required configuration parameters in designated variables. If the configuration is fixed, and known at the start, there is no reason to read it on demand (which incur synchronization and communication in parallel sections).
However, this change will probably create several problems, notably:
- Sharing the parameter variables across threads/processes
- Handling default values depending on other values (computed during the run)
To be analysed...
Snippets
Load all parameters in one routine, hence, we can easily know if the parameter is correctly loaded or not as there is only one routine to inspect.
subroutine load_configuration(...)
use ioipsl, only: getin
use caldyn_vars_mod, only: hydrostatic
...
hydrostatic = .FALSE.
call getin("hydrostatic", hydrostatic)
end subroutine