Skip to content
Snippets Groups Projects
Unverified Commit 19c4dac2 authored by René Fritze's avatar René Fritze
Browse files

adds a few utility functions from dune-multiscale

- allows dumping of the process env
- csv output of memory usage stats
- exception handlers
parent bd42ac2f
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ set(lib_dune_xt_common_sources
filesystem.cc
color.cc
convergence-study.cc
exceptions.cc
localization-study.cc
logging.cc
timedlogging.cc
......@@ -19,6 +20,7 @@ set(lib_dune_xt_common_sources
configuration.cc
signals.cc
math.cc
memory.cc
misc.cc
parallel/threadmanager.cc
parallel/helper.cc
......
#include <config.h>
#include "exceptions.hh"
#include <dune/xt/common/timings.hh>
#include <dune/xt/common/memory.hh>
#include <dune/xt/common/parallel/helper.hh>
#if HAVE_TBB
#include <tbb/tbb_exception.h>
#endif
namespace Dune {
namespace XT {
namespace Common {
int handle_exception(const Dune::Exception& exp)
{
std::cerr << "Failed with Dune::Exception: " << exp.what();
DXTC_TIMINGS.output_per_rank("profiler");
mem_usage();
return abort_all_mpi_processes();
}
int handle_exception(const std::exception& exp)
{
std::cerr << "Failed with std::exception: " << exp.what();
DXTC_TIMINGS.output_per_rank("profiler");
mem_usage();
return abort_all_mpi_processes();
}
#if HAVE_TBB
int handle_exception(const tbb::tbb_exception& exp)
{
std::cerr << "Failed with tbb::exception" << exp.name() << ": " << exp.what();
DXTC_TIMINGS.output_per_rank("profiler");
mem_usage();
return abort_all_mpi_processes();
}
#endif
} // namespace Common
} // namespace XT
} // namespace Dune
......@@ -20,6 +20,11 @@
#undef DUNE_THROW
#endif
#if HAVE_TBB
namespace tbb {
class tbb_exception;
}
#endif
/**
* \brief Macro to throw a colorfull exception.
*
......@@ -127,6 +132,12 @@ class spe10_data_file_missing : public Dune::IOError
};
} // namespace Exceptions
int handle_exception(const Dune::Exception& exp);
int handle_exception(const std::exception& exp);
#if HAVE_TBB
int handle_exception(const tbb::tbb_exception& exp);
#endif
} // namespace Common
} // namespace XT
} // namespace Dune
......
#include <config.h>
#include "memory.hh"
#include <dune/xt/common/timings.hh>
#include <dune/xt/common/filesystem.hh>
#include <dune/xt/common/configuration.hh>
#include <sys/resource.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
namespace Dune {
namespace XT {
namespace Common {
void mem_usage(std::string filename)
{
auto comm = Dune::MPIHelper::getCollectiveCommunication();
// Compute the peak memory consumption of each processes
int who = RUSAGE_SELF;
struct rusage usage;
getrusage(who, &usage);
long peakMemConsumption = usage.ru_maxrss;
// compute the maximum and mean peak memory consumption over all processes
long maxPeakMemConsumption = comm.max(peakMemConsumption);
long totalPeakMemConsumption = comm.sum(peakMemConsumption);
long meanPeakMemConsumption = totalPeakMemConsumption / comm.size();
// write output on rank zero
if (comm.rank() == 0) {
std::unique_ptr<boost::filesystem::ofstream> memoryConsFile(make_ofstream(filename));
*memoryConsFile << "global.maxPeakMemoryConsumption,global.meanPeakMemoryConsumption\n"
<< maxPeakMemConsumption << "," << meanPeakMemConsumption << std::endl;
}
}
void mem_usage()
{
mem_usage(std::string(DXTC_CONFIG_GET("global.datadir", "data/")) + std::string("/memory.csv"));
}
} // namespace Common
} // namespace XT
} // namespace Dune
......@@ -389,6 +389,10 @@ private:
std::unique_ptr<internal::AccessInterface<T>> storage_;
}; // class StorageProvider
//! dumps kernel stats into a file
void mem_usage(std::string filename);
void mem_usage();
} // namespace Common
} // namespace XT
} // namespace Dune
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment