diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2005-11-19 20:15:00 +0000 |
---|---|---|
committer | Erik Schnetter <schnetter@cct.lsu.edu> | 2005-11-19 20:15:00 +0000 |
commit | 2f1a70472799f6576260f295fa377b48c9b269a4 (patch) | |
tree | 11432c5275cea233ebc5139144373c28b26a744d | |
parent | adf9ca6ecdc5aa29f965ca11f7c2c21560c8fa7e (diff) |
CarpetLib: Output memory statistics to file
Add new parameter CarpetLib::memstat_file. If set, then memory
statistics are periodically written to this file.
darcs-hash:20051119201538-dae7b-88c8b8cd5b9d2643d1be6e682f2aa32e7a00ef2d.gz
-rw-r--r-- | Carpet/CarpetLib/interface.ccl | 14 | ||||
-rw-r--r-- | Carpet/CarpetLib/param.ccl | 12 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/mem.cc | 77 |
3 files changed, 103 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/interface.ccl b/Carpet/CarpetLib/interface.ccl index 26178a95f..7a507d949 100644 --- a/Carpet/CarpetLib/interface.ccl +++ b/Carpet/CarpetLib/interface.ccl @@ -25,3 +25,17 @@ includes header: th.hh in th.hh includes header: operators.hh in operators.hh uses include header: carpet_typecase.hh + + + +# Return a pointer to an unmodifiable C string +# which contains a unique ID for this build +CCTK_POINTER_TO_CONST \ +FUNCTION UniqueBuildID (CCTK_POINTER_TO_CONST IN cctkGH) +USES FUNCTION UniqueBuildID + +# Return a pointer to an unmodifiable C string +# which contains a unique ID for this simulation +CCTK_POINTER_TO_CONST \ +FUNCTION UniqueSimulationID (CCTK_POINTER_TO_CONST IN cctkGH) +USES FUNCTION UniqueSimulationID diff --git a/Carpet/CarpetLib/param.ccl b/Carpet/CarpetLib/param.ccl index 3756062f3..62c7c6e9b 100644 --- a/Carpet/CarpetLib/param.ccl +++ b/Carpet/CarpetLib/param.ccl @@ -44,6 +44,18 @@ INT max_allowed_memory_MB "Maximum allowed amount of memory per process (in Mega 1:* :: "abort if more memory is used" } 0 +STRING memstat_file "File name to which memstat output is collected (because stdout from the root node may not be enough)" +{ + "^$" :: "empty filename: no file output" + "^.+$" :: "file name" +} "memory-statistics" + +SHARES: IO + +USES STRING out_dir + +PRIVATE: + # Options to tune MPI communication diff --git a/Carpet/CarpetLib/src/mem.cc b/Carpet/CarpetLib/src/mem.cc index c32cc053b..0c0348412 100644 --- a/Carpet/CarpetLib/src/mem.cc +++ b/Carpet/CarpetLib/src/mem.cc @@ -1,18 +1,36 @@ #include <algorithm> #include <cassert> +#include <cstring> +#include <fstream> #include <iomanip> #include <iostream> +#include <sstream> +#include <string> #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "defs.hh" +#include "dist.hh" #include "mem.hh" +using namespace std; + + + +struct mstat { + int total_bytes; + int total_objects; + int max_bytes; + int max_objects; +}; + + + // Total number of currently allocated bytes and objects static size_t total_allocated_bytes = 0; static size_t total_allocated_objects = 0; @@ -121,6 +139,7 @@ void CarpetLib_printmemstats (CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; + if (print_memstats_every and cctk_iteration % print_memstats_every == 0) { @@ -132,6 +151,64 @@ void CarpetLib_printmemstats (CCTK_ARGUMENTS) << " Maximum allocated memory: " << setprecision(3) << max_allocated_bytes / 1.0e6 << " MB" << endl << endl; + + if (strcmp (memstat_file, "") != 0) { + + mstat mybuf; + mybuf.total_bytes = total_allocated_bytes; + mybuf.total_objects = total_allocated_objects; + mybuf.max_bytes = max_allocated_bytes; + mybuf.max_objects = max_allocated_objects; + vector<mstat> allbuf (dist::size()); + MPI_Gather (& mybuf, 4, MPI_INT, + & allbuf.front(), 4, MPI_INT, + 0, dist::comm()); + + if (dist::rank() == 0) { + + int max_max_bytes = 0; + int avg_max_bytes = 0; + int cnt_max_bytes = 0; + for (size_t n=0; n<allbuf.size(); ++n) { + max_max_bytes = max (max_max_bytes, allbuf[n].max_bytes); + avg_max_bytes += allbuf[n].max_bytes; + ++ cnt_max_bytes; + } + avg_max_bytes /= cnt_max_bytes; + + ostringstream filenamebuf; + filenamebuf << out_dir << "/" << memstat_file; + string const filename = filenamebuf.str(); + ofstream file; + static bool did_truncate = false; + if (not did_truncate) { + did_truncate = true; + file.open (filename.c_str(), ios::out | ios::trunc); + if (CCTK_IsFunctionAliased ("UniqueBuildID")) { + char const * const build_id + = static_cast<char const *> (UniqueBuildID (cctkGH)); + file << "# Build ID: " << build_id << endl; + } + if (CCTK_IsFunctionAliased ("UniqueSimulationID")) { + char const * const job_id + = static_cast<char const *> (UniqueSimulationID (cctkGH)); + file << "# Simulation ID: " << job_id << endl; + } + file << "# Running on " << dist::size() << " processors" << endl; + file << "#" << endl; + file << "# iteration maxmaxbytes avgmaxbytes" << endl; + } else { + file.open (filename.c_str(), ios::out | ios::app); + } + + file << cctk_iteration << " " + << max_max_bytes << " " << avg_max_bytes << endl; + + file.close (); + + } // if on root processor + } // if output to file + } } |