From 7119df45e3bd7e7ad353719f7b41a71ebb604912 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sun, 4 Aug 2013 00:27:34 -0400 Subject: Carpet: Add aliased function Driver_TotalMemoryUsed Add aliased function Driver_TotalMemoryUsed that calculates the total amount of memory currently used by Carpet. --- Carpet/Carpet/interface.ccl | 13 ++++++ Carpet/Carpet/src/helpers.cc | 97 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) 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; mtimelevels(ml, rl); + for (int lc=0; lcdata_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; vitimelevels(ml, rl); + const int lc = 0; + for (int tl=0; tldata_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 -- cgit v1.2.3