diff options
author | Roland Haas <roland.haas@physics.gatech.edu> | 2012-09-06 22:55:21 -0400 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2012-09-11 18:23:37 +0100 |
commit | 30480663f724f94921b4db6152c0f8f44a85b6e4 (patch) | |
tree | 36c05022e6bbfceb0d9668c96aa2251c482b8959 | |
parent | 95bfa92c1b78692244ae18d295f421e16784b26c (diff) |
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.
-rw-r--r-- | Carpet/Carpet/interface.ccl | 22 | ||||
-rw-r--r-- | Carpet/Carpet/src/Requirements.cc | 82 |
2 files changed, 104 insertions, 0 deletions
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 <cctk.h> #include <cctk_Parameters.h> +#include <cctk_Functions.h> #include <cctk_Schedule.h> #include <cctki_GHExtensions.h> #include <cctki_Schedule.h> +#include <util_String.h> #include <algorithm> #include <cassert> @@ -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<nvars; ++v) { + cFunctionData temp_function_data = *function_data; + char const * const fullname = CCTK_FullName(varidx[v]); + char * reads; + const int len_written = Util_asprintf(&reads, "%s(%s)", fullname, clause); + assert(len_written > 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<nvars; ++v) { + cFunctionData temp_function_data = *function_data; + char const * const fullname = CCTK_FullName(varidx[v]); + char * writes; + const int len_written = Util_asprintf(&writes, "%s(%s)", fullname, clause); + assert(len_written > 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, |