aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Haas <roland.haas@physics.gatech.edu>2012-09-06 22:55:21 -0400
committerRoland Haas <roland.haas@physics.gatech.edu>2012-09-06 22:55:21 -0400
commitfcd89f6124a498e089648ba2d203f768fa6ca073 (patch)
treec44af60373bb2ea832cab156691baf9e1505221f
parent4b548cef6528ff0527c697e930cbef6261209d7a (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.ccl22
-rw-r--r--Carpet/Carpet/src/Requirements.cc82
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,