aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-08-04 00:27:34 -0400
committerErik Schnetter <schnetter@gmail.com>2013-08-04 00:27:34 -0400
commit7119df45e3bd7e7ad353719f7b41a71ebb604912 (patch)
tree63b75d96c1c60e35a257747ae32e6fc838a557e4
parent3a4bc5a1416ea920644f3e0850920898f52459aa (diff)
Carpet: Add aliased function Driver_TotalMemoryUsed
Add aliased function Driver_TotalMemoryUsed that calculates the total amount of memory currently used by Carpet.
-rw-r--r--Carpet/Carpet/interface.ccl13
-rw-r--r--Carpet/Carpet/src/helpers.cc97
2 files changed, 110 insertions, 0 deletions
diff --git a/Carpet/Carpet/interface.ccl b/Carpet/Carpet/interface.ccl
index 577cbb059..9bf2ee08b 100644
--- a/Carpet/Carpet/interface.ccl
+++ b/Carpet/Carpet/interface.ccl
@@ -64,6 +64,19 @@ PROVIDES FUNCTION CCTK_ProcsOnHost WITH Carpet_ProcsOnHost LANGUAGE C
+# Return total amount of memory used by Carpet
+# These numbers report number of bytes for the current MPI process.
+# They are mutually exclusive.
+# The return value indicates success (0) or an error (negative).
+CCTK_INT FUNCTION Driver_TotalMemoryUsed( \
+ CCTK_REAL OUT metadata, \
+ CCTK_REAL OUT grid_structure, \
+ CCTK_REAL OUT grid_arrays, \
+ CCTK_REAL OUT grid_functions)
+PROVIDES FUNCTION Driver_TotalMemoryUsed WITH Carpet_TotalMemoryUsed LANGUAGE C
+
+
+
# Register and unregister routines which are called before and after
# every scheduled routine
CCTK_INT \
diff --git a/Carpet/Carpet/src/helpers.cc b/Carpet/Carpet/src/helpers.cc
index a34fd974c..83f9964d6 100644
--- a/Carpet/Carpet/src/helpers.cc
+++ b/Carpet/Carpet/src/helpers.cc
@@ -575,4 +575,101 @@ namespace Carpet {
return map0group;
}
+
+
+ extern "C"
+ CCTK_INT Carpet_TotalMemoryUsed(CCTK_REAL* metadata,
+ CCTK_REAL* grid_structure,
+ CCTK_REAL* grid_arrays,
+ CCTK_REAL* grid_functions)
+ {
+ // Various metadata, excluding the small change
+ *metadata = 0.0 +
+ // memoryof(main_timer_tree) +
+ // memoryof(mode_timer_tree) +
+ memoryof(origin_space) +
+ memoryof(delta_space) +
+ // memoryof(domainspecs) +
+ memoryof(vhh) +
+ memoryof(vdd) +
+ memoryof(level_regridding_epochs);
+ // memoryof(groupdata) +
+ // memoryof(arrdata);
+
+ // TODO: Add TimerNode.root(?), TimerSet.timers
+
+ // Grid structure
+ *grid_structure = 0.0;
+ // Storage for grid arrays
+ *grid_arrays = 0.0;
+ // Storage for grid functions
+ *grid_functions = 0.0;
+
+ for (size_t m=0; m<vhh.size(); ++m) {
+ *grid_structure += memoryof(*vhh.AT(m));
+ }
+ for (size_t m=0; m<vdd.size(); ++m) {
+ *grid_structure += memoryof(*vdd.AT(m));
+ }
+ grid_structure += memoryof(*tt);
+
+ const int myproc = CCTK_MyProc(0);
+ for (size_t gi=0; gi<arrdata.size(); ++gi) {
+ if (CCTK_GroupTypeI(gi) == CCTK_GF) {
+ for (size_t m=0; m<arrdata.AT(gi).size(); ++m) {
+ const gh& hh = *vhh.AT(m);
+ for (size_t vi=0; vi<arrdata.AT(gi).AT(m).data.size(); ++vi) {
+ const ggf* f = arrdata.AT(gi).AT(m).data.AT(vi);
+ if (f) {
+ *grid_structure += memoryof(*f);
+ for (int ml=0; ml<hh.mglevels(); ++ml) {
+ for (int rl=0; rl<hh.reflevels(); ++rl) {
+ const int tls = f->timelevels(ml, rl);
+ for (int lc=0; lc<hh.local_components(rl); ++lc) {
+ for (int tl=0; tl<tls; ++tl) {
+ const gdata* d = f->data_pointer(tl, rl, lc, ml);
+ *grid_structure += memoryof(*d);
+ // TODO: add memoryof(d->_memory);
+ if (d->has_storage()) {
+ assert(d->proc() == myproc);
+ *grid_functions += d->size() * d->elementsize();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else { // not CCTK_GF
+ const int m = 0;
+ *grid_structure += 0.0 +
+ memoryof(*arrdata.AT(gi).AT(m).hh) +
+ memoryof(*arrdata.AT(gi).AT(m).dd) +
+ memoryof(*arrdata.AT(gi).AT(m).tt);
+ for (size_t vi=0; vi<arrdata.AT(gi).AT(m).data.size(); ++vi) {
+ const ggf* f = arrdata.AT(gi).AT(m).data.AT(vi);
+ if (f) {
+ *grid_structure += memoryof(*f);
+ const int ml = 0;
+ const int rl = 0;
+ const int tls = f->timelevels(ml, rl);
+ const int lc = 0;
+ for (int tl=0; tl<tls; ++tl) {
+ const gdata* d = f->data_pointer(tl, rl, lc, ml);
+ *grid_arrays += memoryof(*d);
+ // TODO: add memoryof(d->_memory);
+ if (d->has_storage()) {
+ assert(d->proc() == myproc);
+ *grid_functions += d->size() * d->elementsize();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+ }
+
} // namespace Carpet