aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/mem.cc
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2005-11-19 20:15:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2005-11-19 20:15:00 +0000
commit2f1a70472799f6576260f295fa377b48c9b269a4 (patch)
tree11432c5275cea233ebc5139144373c28b26a744d /Carpet/CarpetLib/src/mem.cc
parentadf9ca6ecdc5aa29f965ca11f7c2c21560c8fa7e (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
Diffstat (limited to 'Carpet/CarpetLib/src/mem.cc')
-rw-r--r--Carpet/CarpetLib/src/mem.cc77
1 files changed, 77 insertions, 0 deletions
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
+
}
}