From d746b25592639a0f8eecab042553fe2a639be9d9 Mon Sep 17 00:00:00 2001 From: Roland Haas Date: Thu, 5 Sep 2013 22:40:00 -0700 Subject: Carpet: use electric fence provided by CarpetLib only active when CarpetLib's electric_fence parameter is set --- Carpet/Carpet/src/CallFunction.cc | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/Carpet/Carpet/src/CallFunction.cc b/Carpet/Carpet/src/CallFunction.cc index 935fe2e4d..224a66346 100644 --- a/Carpet/Carpet/src/CallFunction.cc +++ b/Carpet/Carpet/src/CallFunction.cc @@ -39,6 +39,11 @@ namespace Carpet { SyncGroupsInScheduleBlock (cFunctionData * attribute, cGH * cctkGH, vector const & sync_groups, Timers::Timer & sync_timer); + + // check if scheduled function overwrote any of the poison surrounding + // allocated memory + static void + CheckFence (cGH const * const cctkGH, cFunctionData * attribute); /// Traverse one function on all components of one refinement level /// of one multigrid level. @@ -381,6 +386,7 @@ namespace Carpet { post_timer.stop(); } timer.stop(); + CheckFence (cctkGH, attribute); #ifdef REQUIREMENTS_HH Requirements::AfterRoutine (attribute, @@ -464,5 +470,68 @@ namespace Carpet { SyncProlongateGroups (cctkGH, sync_groups, attribute); sync_timer.stop(); } + + void CheckFence (cGH const * const cctkGH, cFunctionData * attribute) + { + if (is_meta_mode()) return; // meta mode has no accessible variables + + Timers::Timer timer("FenceCheck"); + timer.start(); + + for (int group=0; group=0); + + int const num_tl = CCTK_ActiveTimeLevelsVI(cctkGH, n0); + if (num_tl == 0) continue; + int const min_tl = 0; + int const max_tl = num_tl-1; + + int const grouptype = CCTK_GroupTypeI(group); + if (grouptype == CCTK_GF && not is_local_mode()) continue; + assert(not is_meta_mode()); + + // FIXME: query is_XXX() functions + const bool is_array = grouptype == CCTK_ARRAY or + grouptype == CCTK_SCALAR; + const int m = is_array ? 0 : map; + const int rl = is_array ? 0 : reflevel; + const int ml = is_array ? 0 : mglevel; + const int lc = is_array ? 0 : local_component; + + { + char * const groupname = CCTK_GroupName(group); + Checkpoint ("FenceCheck \"%s\"", groupname); + free (groupname); + } + + for (int var=0; vardata_pointer (tl, rl, lc, ml); + for (int f=0; f<2; ++f) { + if (not data->check_fence(f)) { + char* fullname = CCTK_FullName(n0+var); + CCTK_VError(__LINE__, __FILE__, CCTK_THORNSTRING, + "At iteration %d: timelevel %d, component %d, map %d, refinement level %d of the variable \"%s\" contains was written to beyond to %s bound of the allocated memory by %s::%s at %s.", + cctkGH->cctk_iteration, tl, component, m, + rl, fullname, f ? "lower" : "upper", + attribute->thorn, attribute->routine, attribute->where); + free (fullname); + } + }// for f + } // for tl + } // for var + } + } + timer.stop(); + } } // namespace Carpet -- cgit v1.2.3