From fcd89f6124a498e089648ba2d203f768fa6ca073 Mon Sep 17 00:00:00 2001 From: Roland Haas Date: Thu, 6 Sep 2012 22:55:21 -0400 Subject: Carpet: add routines to record READS/WRITES at runtime THe external interface seems ok, but the internals will be rewritten to avoid repeated string parsing, memory allocation and internal std::map manipulations. --- Carpet/Carpet/interface.ccl | 22 +++++++++++ Carpet/Carpet/src/Requirements.cc | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/Carpet/Carpet/interface.ccl b/Carpet/Carpet/interface.ccl index d2f7f5643..8ae894985 100644 --- a/Carpet/Carpet/interface.ccl +++ b/Carpet/Carpet/interface.ccl @@ -319,6 +319,28 @@ PROVIDES FUNCTION VarDataPtrI \ LANGUAGE C +# programmatically check a reads clause +void FUNCTION \ + Requirements_CheckReads \ + (CCTK_POINTER_TO_CONST IN cctkGH, \ + CCTK_INT IN numvars, \ + CCTK_INT ARRAY IN varidx, \ + CCTK_STRING IN reads) +PROVIDES FUNCTION Requirements_CheckReads \ + WITH Carpet_Requirements_CheckReads \ + LANGUAGE C + +# programmatically record a writes clause +void FUNCTION \ + Requirements_NotifyWrites \ + (CCTK_POINTER_TO_CONST IN cctkGH, \ + CCTK_INT IN numvars, \ + CCTK_INT ARRAY IN varidx, \ + CCTK_STRING IN reads) +PROVIDES FUNCTION Requirements_NotifyWrites \ + WITH Carpet_Requirements_NotifyWrites \ + LANGUAGE C + # The true prototype of the routine below: # int Carpet_Regrid (const cGH * cctkGH, diff --git a/Carpet/Carpet/src/Requirements.cc b/Carpet/Carpet/src/Requirements.cc index d1e407f0e..434943db0 100644 --- a/Carpet/Carpet/src/Requirements.cc +++ b/Carpet/Carpet/src/Requirements.cc @@ -4,9 +4,11 @@ #include #include +#include #include #include #include +#include #include #include @@ -294,6 +296,7 @@ namespace Carpet { public: all_clauses_t() {} clauses_t const& get_clauses(cFunctionData const* function_data); + void remove_clauses(cFunctionData const* function_data); // Input/Output helpers void input (istream& is); @@ -314,6 +317,17 @@ namespace Carpet { return *ret.first->second; } + void all_clauses_t:: + remove_clauses(cFunctionData const* const function_data) + { + clauses_map_t::iterator const iclauses = + clauses_map.find(function_data); + if (iclauses != clauses_map.end()) { + clauses_map.erase(iclauses); + } + return; + } + inline ostream& operator<< (ostream& os, const all_clauses_t& a) { a.output(os); return os; @@ -945,6 +959,40 @@ namespace Carpet { } } + extern "C" + void Carpet_Requirements_CheckReads(const cGH *cctkGH, CCTK_INT nvars, + CCTK_INT const * varidx, + char const * clause) + { + DECLARE_CCTK_PARAMETERS; + if (check_requirements) { + // TODO: come up with a scheme to avoid constructing and destroying clauses + cFunctionData const* const function_data = + CCTK_ScheduleQueryCurrentFunction(cctkGH); + int const reflevel = GetRefinementLevel(cctkGH); + int const map = GetMap(cctkGH); + int const timelevel = GetTimeLevel(cctkGH); + // TODO: design an interface to all_state.before_routine that operates + // on indices and claues directly + for (int v = 0; v 0); + temp_function_data.n_WritesClauses = 0; + temp_function_data.WritesClauses = NULL; + temp_function_data.n_ReadsClauses = 1; + temp_function_data.ReadsClauses = (const char**)&reads; + all_clauses.get_clauses(&temp_function_data); + BeforeRoutine(&temp_function_data, reflevel, map, timelevel); + all_clauses.remove_clauses(&temp_function_data); + free((void*)fullname); + free(reads); + } + } + } + void all_state_t::before_routine(cFunctionData const* const function_data, int const reflevel, int const map, int const timelevel) @@ -1023,6 +1071,40 @@ namespace Carpet { "Aborting because schedule clauses were not satisfied"); } } + + extern "C" + void Carpet_Requirements_NotifyWrites(const cGH *cctkGH, CCTK_INT nvars, + CCTK_INT const * varidx, + char const * clause) + { + DECLARE_CCTK_PARAMETERS; + if (check_requirements) { + // TODO: come up with a scheme to avoid constructing and destroying clauses + cFunctionData const* const function_data = + CCTK_ScheduleQueryCurrentFunction(cctkGH); + int const reflevel = GetRefinementLevel(cctkGH); + int const map = GetMap(cctkGH); + int const timelevel = GetTimeLevel(cctkGH); + // TODO: design an interface to all_state.before_routine that operates + // on indices and claues directly + for (int v = 0; v 0); + temp_function_data.n_WritesClauses = 1; + temp_function_data.WritesClauses = (const char**)&writes; + temp_function_data.n_ReadsClauses = 0; + temp_function_data.ReadsClauses = NULL; + all_clauses.get_clauses(&temp_function_data); + AfterRoutine(&temp_function_data, reflevel, map, timelevel); + all_clauses.remove_clauses(&temp_function_data); + free((void*)fullname); + free(writes); + } + } + } void all_state_t::after_routine(cFunctionData const* const function_data, int const reflevel, int const map, -- cgit v1.2.3