nextsimhub / nextsimdg

neXtSIM_DG : next generation sea-ice model with DG
https://nextsim-dg.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
10 stars 13 forks source link

incorrect resource lifetimes due to static data #614

Closed Thanduriel closed 1 month ago

Thanduriel commented 4 months ago

Currently significant parts of the model are constructed and managed through ConfiguredModule::configuredModules and therefore have static lifetimes. This makes resource management via RAII challenging since the order of init/release is hard to track and destructors will only be called during the epilogue of main.

A concrete example for a problem this causes can be found in the GPU code. Usage of the GPU requires both manual initialize and finalize calls and the management of memory buffers. Currently the simulation will always terminate with an exception because the buffers are freed by a destructor which is only called after the finalize.

The easiest solution would probably be to make the ConfiguredModule data non-static and to introduce a finalize call.

timspainNERSC commented 2 months ago

A greater problem is the static data at the foundation of every Module<>.

Also check the rest of the infrastructure in core/src/include/*.hpp for static data members.

timspainNERSC commented 2 months ago

Classes to look at: