Closed mgduda closed 3 weeks ago
I rebuilt MPAS bundle and ran the MPAS-JEDI CTests using these changes. They fixed the problem we were having with config_halo_exch_method being deallocated too early.
@amstokely Thanks for testing this PR with MPAS-JEDI. We'll call that good enough for an approval!
I just pushed a fix to the commit message: "first-in, first-out"
should be "last-in, first-out"
.
This PR fixes a potential issue in destroying halo exchange groups when there are multiple domain instances.
When there exist multiple domain instances, and
atm_destroy_halo_groups
andmpas_deallocate_domain
are called in a particular order for the domains, theconfig_halo_exch_method
module variable in thempas_atm_halos
module may be invalid, leading to an error when destroying halo groups. This results in as the error messagein the MPAS-Atmosphere log file.
Consider a situation in which we have two domain instances,
domain_0
anddomain_1
. If theatm_build_halo_groups
routine and theatm_destroy_halo_groups
plusmpas_deallocate_domain
routines are called in "last-in, first-out" order, i.e.,the module variable
config_halo_exch_method
would be first set to point to memory owned bydomain_0
and then re-set to point to memory owned bydomain_1
in the calls toatm_build_halo_groups
. Upon callingatm_destroy_halo_groups
fordomain_1
followed by a call tompas_deallocate_domain
, theconfig_halo_exch_method
pointer would become invalid, leading to an error when callingmpas_destroy_halo_groups
fordomain_0
.Since the domain instance is passed as an argument to
atm_destroy_halo_groups
routine, rather than using a module variable set when halo exchange groups were built, we can simply retrieveconfig_halo_exch_method
from the domain argument, thereby avoiding the original problem.