Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoization leading to extreme memory demands in reactive transport simulations #72

Open
j-engelmann opened this issue Aug 26, 2024 · 1 comment

Comments

@j-engelmann
Copy link

I initially created this issue over on the Reaktoro github, but as it seems to be related to ThermoFun i will also raise it here. In developing reactive transport simulations using Reaktoro and ThermoFun as the thermodynamic backend, i discovered that the ThermoFun part (namely the PropertiesSolvent, ElectroPropertiesSolvent and ThermoPropertiesSubstance objects) grows in memory use over runtime, until it crashes the program.

From the previous discussion with @allanleal, this may be related to memoization in ThermoFun. I believe the memory issues arise because the thermodynamic properties are stored at all unique P/T points. While this may be efficient for smaller batch calculations, its too much information to handle in the kinds of simulations i run.

Is there a way to control or turn off this feature?

Any help would be greatly appreciated!

Cheers,

Jasper

@j-engelmann
Copy link
Author

If anyone else runs into this issue, i have found a solution:

The memoization is set up in ThermoFun/ThermoEngine.cpp, using template functions defined in OptimizationUtils.h. By commenting lines 107, 113, 119 and 125, you can simply turn it off. For reference, they all look something like this, calling memoize():

107 thermo_properties_substance_fn = memoize(thermo_properties_substance_fn);

I also created a new template memoizeN(fun,max_cache_size) where the least recently used entry is removed if the max size of the cache is reached. Using that with a max size of 1e6, i can smoothly run my simulations with stable memory usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@j-engelmann and others