Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_MemUtils.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef PANZER_MEMUTILS_HPP
12#define PANZER_MEMUTILS_HPP
13
14#include <Teuchos_Comm.hpp>
15#include <iostream>
16
17namespace panzer
18{
20 struct MemUsage
21 {
23 MemUsage(size_t inCurrMin = 0, size_t inCurrMax = 0, size_t inCurrTot = 0,
24 size_t inPeakMin = 0, size_t inPeakMax = 0, size_t inPeakTot = 0)
25 :
26 currMin(inCurrMin), currMax(inCurrMax), currTot(inCurrTot), peakMin(inPeakMin),
27 peakMax(inPeakMax), peakTot(inPeakTot)
28 {
29 }
30 MemUsage operator+(const MemUsage& that) const
31 {
32 return MemUsage(currMin + that.currMin, currMax + that.currMax,
33 currTot + that.currTot, peakMin + that.peakMin, peakMax + that.peakMax,
34 peakTot + that.peakTot);
35 }
36 MemUsage operator-(const MemUsage& that) const
37 {
38 return MemUsage(currMin - that.currMin, currMax - that.currMax,
39 currTot - that.currTot, peakMin - that.peakMin, peakMax - that.peakMax,
40 peakTot - that.peakTot);
41 }
42 MemUsage& operator*=(const size_t& that)
43 {
44 currMin *= that; peakMin *= that;
45 currMax *= that; peakMax *= that;
46 currTot *= that; peakTot *= that;
47 return *this;
48 }
49 MemUsage& operator/=(const size_t& that)
50 {
51 currMin /= that; peakMin /= that;
52 currMax /= that; peakMax /= that;
53 currTot /= that; peakTot /= that;
54 return *this;
55 }
56 };
58
60 void printMemoryUsage(std::ostream& os, const Teuchos::Comm<int>& comm);
61 void printMemoryUsage(std::ostream& os, const Teuchos::Comm<int>& comm,
62 const MemUsage& mem);
63 void pretty(std::ostream& s, size_t num);
64
66 MemUsage getMemoryUsage(const Teuchos::Comm<int>& comm);
67
70 MemUsage getPeakRSS(const Teuchos::Comm<int>& comm);
71
74 MemUsage getCurrentRSS(const Teuchos::Comm<int>& comm);
75
77 MemUsage reduceMemUsage(size_t& mem, const Teuchos::Comm<int>& comm,
78 const MemUsageType& type);
79} // end namespace panzer
80
81#endif // PANZER_MEMUTILS_HPP
MemUsage getCurrentRSS(const Teuchos::Comm< int > &comm)
void pretty(std::ostream &s, size_t num)
void printMemoryUsage(std::ostream &s, const Teuchos::Comm< int > &comm)
Print memory usage to stream.
MemUsage reduceMemUsage(size_t &mem, const Teuchos::Comm< int > &comm, const MemUsageType &type)
Reduce the memory usage over all the processors.
MemUsage getMemoryUsage(const Teuchos::Comm< int > &comm)
Get memory usage in B.
MemUsage getPeakRSS(const Teuchos::Comm< int > &comm)
The memory usage information.
MemUsage(size_t inCurrMin=0, size_t inCurrMax=0, size_t inCurrTot=0, size_t inPeakMin=0, size_t inPeakMax=0, size_t inPeakTot=0)
MemUsage operator-(const MemUsage &that) const
MemUsage & operator/=(const size_t &that)
MemUsage & operator*=(const size_t &that)
MemUsage operator+(const MemUsage &that) const