Memory management cleanup and initialization fixes#1413
Merged
Conversation
This patch fixes up and enables several of the derived type destructor
functions (`_end()`) used to handle memory management of the model.
- Two uninitialized logical flags which would cause errors in optimized
builds have also been fixed.
* `Visbeck_S_max` in thickness diffusion is now initialized to zero,
which acts to disable it in subsequent operations.
* `remap_answers_2018` is now unset when `NDIFF_CONTINUOUS` is false.
- Several of the destructor functions were restructured so that they do
not explicitly deallocate their pointer inputs. This will allow us to
stage the functions as formal destructors for the derived types via
the `final` keyword in a later patch. It also allows us to pass the
inputs on stack rather than as pointers.
* `barotropic_end`
* `continuity_end`
* `CoriolisAdv_end`
* `deallocate_MOM_domain`
* `diabatic_driver_end`
* `geothermal_end`
* `hor_visc_end`
* `MEKE_end`
* `MOM_CVMix_conv_end`
* `MOM_CVMix_ddiff_end`
* `MOM_CVMix_shear_end`
* `MOM_diagnostics_end`
* `MOM_regridding_end`
* `MOM_sum_output_end`
* `PressureForce_end`
* `set_diffusivity_end`
* `thickness_diffuse_end`
* `tidal_forcing_end`
* `VarMix_end`
* `vertvisc_end`
- In a few cases, the deallocations were re-ordered to match the
reversed order of allocation.
* `MOM_CVMix_conv_mod`
* `MOM_CVMix_ddiff_mod`
* `MOM_CVMix_shear_mod`
- A few constructors always initialized their control structures, even
when disabled. In some of these cases, the allocation is now skipped
if the corresponding feature is disabled.
- `diag_mediator_end` now includes the following changes:
* `axes_grp_end` was introduced to deallocate axes_grp types.
The `remap_axes*` are now deallocated.
* We now cycles through the diagnostic list and deallocate the
supplemental diagnostics.
* Downsampled diagnostic masks and remaps are now deallocated
- The initialized `blockName` of the param file parser are now
dellocated before reinitializing them. Although the existing value is
still lost, it is at least now deallocated from heap.
- A bug was fixed in `hor_visc_end`; Smag_Ah and Leith_Ah areas were
incorrectly swapped.
The principal motivation for this work is to eliminate any errors
detected by valgrind, and to integrated automated memcheck testing to
the verification test suite.
Hallberg-NOAA
approved these changes
Jun 7, 2021
Collaborator
Hallberg-NOAA
left a comment
There was a problem hiding this comment.
I have examined all of these changes, and I agree with the direction that they are heading, although it should be noted that there is still more to do along these lines.
This PR conditionally passed the pipeline testing at https://gitlab.gfdl.noaa.gov/ogrp/MOM6/-/pipelines/12831, but because the code after this PR no longer logs the parameter VISBECK_MAX_SLOPE in all cases, there will have to be a manual update to the MOM_parameter_doc files in MOM6-examples as soon as this PR is merged into dev/gfdl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch fixes up and enables several of the derived type destructor
functions (
_end()) used to handle memory management of the model.Two uninitialized logical flags which would cause errors in optimized
builds have also been fixed.
Visbeck_S_maxin thickness diffusion is now initialized to zero,which acts to disable it in subsequent operations.
remap_answers_2018is now unset whenNDIFF_CONTINUOUSis false.Several of the destructor functions were restructured so that they do
not explicitly deallocate their pointer inputs. This will allow us to
stage the functions as formal destructors for the derived types via
the
finalkeyword in a later patch. It also allows us to pass theinputs on stack rather than as pointers.
barotropic_endcontinuity_endCoriolisAdv_enddeallocate_MOM_domaindiabatic_driver_endgeothermal_endhor_visc_endMEKE_endMOM_CVMix_conv_endMOM_CVMix_ddiff_endMOM_CVMix_shear_endMOM_diagnostics_endMOM_regridding_endMOM_sum_output_endPressureForce_endset_diffusivity_endthickness_diffuse_endtidal_forcing_endVarMix_endvertvisc_endIn a few cases, the deallocations were re-ordered to match the
reversed order of allocation.
MOM_CVMix_conv_modMOM_CVMix_ddiff_modMOM_CVMix_shear_modA few constructors always initialized their control structures, even
when disabled. In some of these cases, the allocation is now skipped
if the corresponding feature is disabled.
diag_mediator_endnow includes the following changes:axes_grp_endwas introduced to deallocate axes_grp types.The
remap_axes*are now deallocated.We now cycles through the diagnostic list and deallocate the
supplemental diagnostics.
Downsampled diagnostic masks and remaps are now deallocated
The initialized
blockNameof the param file parser are nowdellocated before reinitializing them. Although the existing value is
still lost, it is at least now deallocated from heap.
A bug was fixed in
hor_visc_end; Smag_Ah and Leith_Ah areas wereincorrectly swapped.
The principal motivation for this work is to eliminate any errors
detected by valgrind, and to integrated automated memcheck testing to
the verification test suite.