diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2008-03-01 09:41:21 -0600 |
---|---|---|
committer | Erik Schnetter <schnetter@cct.lsu.edu> | 2008-03-01 09:41:21 -0600 |
commit | fddf250b40090d60115e90b1f364212184dc5b77 (patch) | |
tree | 75edfd4f25f9ee2b66f59319e3cbf85464be8ed4 /Carpet | |
parent | b3b4faf4e7a0cdbf791467e6dc7c0d6984e31db1 (diff) |
Implement schedule wrappers
Schedule wrappers are routines that can be registered with Carpet. They
will be called before and after any scheduled routine is called. This
allows custom debugging and profiling routines, such as e.g. single-stepping
through the schedule.
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/Carpet/interface.ccl | 19 | ||||
-rw-r--r-- | Carpet/Carpet/src/CallFunction.cc | 2 | ||||
-rw-r--r-- | Carpet/Carpet/src/ScheduleWrapper.cc | 66 | ||||
-rw-r--r-- | Carpet/Carpet/src/carpet.hh | 4 | ||||
-rw-r--r-- | Carpet/Carpet/src/make.code.defn | 1 |
5 files changed, 92 insertions, 0 deletions
diff --git a/Carpet/Carpet/interface.ccl b/Carpet/Carpet/interface.ccl index 06c159757..734020bae 100644 --- a/Carpet/Carpet/interface.ccl +++ b/Carpet/Carpet/interface.ccl @@ -39,6 +39,25 @@ PROVIDES FUNCTION GetMPICommWorld WITH Carpet_GetMPICommWorld LANGUAGE C +# Register and unregister routines which are called before and after +# every scheduled routine +CCTK_INT \ +FUNCTION RegisterScheduleWrapper \ + (CCTK_INT IN CCTK_FPOINTER func_before (CCTK_POINTER_TO_CONST IN cctkGH), \ + CCTK_INT IN CCTK_FPOINTER func_after (CCTK_POINTER_TO_CONST IN cctkGH)) +CCTK_INT \ +FUNCTION UnRegisterScheduleWrapper \ + (CCTK_INT IN CCTK_FPOINTER func_before (CCTK_POINTER_TO_CONST IN cctkGH), \ + CCTK_INT IN CCTK_FPOINTER func_after (CCTK_POINTER_TO_CONST IN cctkGH)) +PROVIDES FUNCTION RegisterScheduleWrapper \ + WITH Carpet_RegisterScheduleWrapper \ + LANGUAGE C +PROVIDES FUNCTION UnRegisterScheduleWrapper \ + WITH Carpet_UnRegisterScheduleWrapper \ + LANGUAGE C + + + # Provide the function to en-/disable prolongation CCTK_INT FUNCTION EnableProlongating(CCTK_INT IN flag) PROVIDES FUNCTION EnableProlongating WITH CarpetEnableProlongating LANGUAGE C diff --git a/Carpet/Carpet/src/CallFunction.cc b/Carpet/Carpet/src/CallFunction.cc index 67d665fe3..ea64fa115 100644 --- a/Carpet/Carpet/src/CallFunction.cc +++ b/Carpet/Carpet/src/CallFunction.cc @@ -310,9 +310,11 @@ namespace Carpet { time_and_mode, attribute->where, attribute->thorn, attribute->routine); + CallBeforeRoutines (cctkGH); user_timer.start(); int const res = CCTK_CallFunction (function, attribute, data); user_timer.stop(); + CallAfterRoutines (cctkGH); assert (res==0); } diff --git a/Carpet/Carpet/src/ScheduleWrapper.cc b/Carpet/Carpet/src/ScheduleWrapper.cc new file mode 100644 index 000000000..4446233ed --- /dev/null +++ b/Carpet/Carpet/src/ScheduleWrapper.cc @@ -0,0 +1,66 @@ +#include <cassert> +#include <list> + +#include "cctk.h" +#include "cctk_Arguments.h" + +#include "carpet.hh" + +namespace Carpet { + + using namespace std; + + + + typedef CCTK_INT (* func) (CCTK_POINTER_TO_CONST cctkGH); + typedef list <func> flist; + + static flist func_befores, func_afters; + + + + extern "C" + CCTK_INT + Carpet_RegisterScheduleWrapper (func const func_before, + func const func_after) + { + // Add functions + if (func_before) func_befores.push_back (func_before); + if (func_after ) func_afters .push_front (func_after ); + return 0; + } + + extern "C" + CCTK_INT + Carpet_UnRegisterScheduleWrapper (func const func_before, + func const func_after) + { + // Remove functions + if (func_before) func_befores.remove (func_before); + if (func_after ) func_afters .remove (func_after ); + return 0; + } + + + + void + CallBeforeRoutines (cGH const * restrict const cctkGH) + { + for (flist::const_iterator + fli = func_befores.begin(); fli != func_befores.end(); ++ fli) + { + (* fli) (cctkGH); + } + } + + void + CallAfterRoutines (cGH const * restrict const cctkGH) + { + for (flist::const_iterator + fli = func_afters.begin(); fli != func_afters.end(); ++ fli) + { + (* fli) (cctkGH); + } + } + +} // namespace Carpet diff --git a/Carpet/Carpet/src/carpet.hh b/Carpet/Carpet/src/carpet.hh index f61f60264..271a86086 100644 --- a/Carpet/Carpet/src/carpet.hh +++ b/Carpet/Carpet/src/carpet.hh @@ -59,6 +59,10 @@ namespace Carpet { void CalculateChecksums (const cGH* cgh, checktimes where); void CheckChecksums (const cGH* cgh, checktimes where); + // Schedule + void CallBeforeRoutines (cGH const * restrict cctkGH); + void CallAfterRoutines (cGH const * restrict cctkGH); + // Debugging output void Output (const char* fmt, ...); void Waypoint (const char* fmt, ...); diff --git a/Carpet/Carpet/src/make.code.defn b/Carpet/Carpet/src/make.code.defn index 2dfbe4219..374e3dad4 100644 --- a/Carpet/Carpet/src/make.code.defn +++ b/Carpet/Carpet/src/make.code.defn @@ -15,6 +15,7 @@ SRCS = AllGatherString.cc \ Poison.cc \ Recompose.cc \ Restrict.cc \ + ScheduleWrapper.cc \ SetupGH.cc \ Shutdown.cc \ Storage.cc \ |