From 2f1a70472799f6576260f295fa377b48c9b269a4 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sat, 19 Nov 2005 20:15:00 +0000 Subject: 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 --- Carpet/CarpetLib/src/mem.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'Carpet/CarpetLib/src/mem.cc') 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 #include +#include +#include #include #include +#include +#include #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 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 (UniqueBuildID (cctkGH)); + file << "# Build ID: " << build_id << endl; + } + if (CCTK_IsFunctionAliased ("UniqueSimulationID")) { + char const * const job_id + = static_cast (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 + } } -- cgit v1.2.3