aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2008-02-02 15:43:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2008-02-02 15:43:00 +0000
commit1beb710e75a868f71b74ca5a2b13017593a4469e (patch)
treed9d916cb78ae9b3ee1bd824fbfc9d32401892d2d
parentd2d5504fd8975ae714d70cbdda4805d49f0c5bf5 (diff)
CarpetLib: Add function memoryof to measure size of data structures
Add an overloaded function memoryof which measures the size in bytes of CarpetLib's data structures. darcs-hash:20080202154302-dae7b-de41c79cb04617327695fae27928c05c5d431ee8.gz
-rw-r--r--Carpet/CarpetLib/src/bbox.hh14
-rw-r--r--Carpet/CarpetLib/src/bboxset.hh9
-rw-r--r--Carpet/CarpetLib/src/data.cc16
-rw-r--r--Carpet/CarpetLib/src/data.hh10
-rw-r--r--Carpet/CarpetLib/src/defs.cc86
-rw-r--r--Carpet/CarpetLib/src/defs.hh24
-rw-r--r--Carpet/CarpetLib/src/dh.cc47
-rw-r--r--Carpet/CarpetLib/src/dh.hh14
-rw-r--r--Carpet/CarpetLib/src/gf.cc12
-rw-r--r--Carpet/CarpetLib/src/gf.hh1
-rw-r--r--Carpet/CarpetLib/src/ggf.cc20
-rw-r--r--Carpet/CarpetLib/src/ggf.hh8
-rw-r--r--Carpet/CarpetLib/src/gh.cc22
-rw-r--r--Carpet/CarpetLib/src/gh.hh6
-rw-r--r--Carpet/CarpetLib/src/mem.cc38
-rw-r--r--Carpet/CarpetLib/src/mem.hh11
-rw-r--r--Carpet/CarpetLib/src/region.hh21
-rw-r--r--Carpet/CarpetLib/src/th.cc15
-rw-r--r--Carpet/CarpetLib/src/th.hh5
-rw-r--r--Carpet/CarpetLib/src/vect.hh10
20 files changed, 386 insertions, 3 deletions
diff --git a/Carpet/CarpetLib/src/bbox.hh b/Carpet/CarpetLib/src/bbox.hh
index 0b813d39d..a79fbe87b 100644
--- a/Carpet/CarpetLib/src/bbox.hh
+++ b/Carpet/CarpetLib/src/bbox.hh
@@ -2,6 +2,7 @@
#define BBOX_HH
#include <cassert>
+#include <cstdlib>
#include <iostream>
#include <limits>
@@ -177,6 +178,12 @@ public:
which means that it also points to the first point. */
iterator end () const;
+ // Memory usage
+ size_t memory () const
+ {
+ return memoryof (_lower) + memoryof (_upper) + memoryof (_stride);
+ }
+
// Input/Output helpers
void input (istream& is);
void output (ostream& os) const;
@@ -184,6 +191,13 @@ public:
+// Memory usage
+
+template<class T, int D>
+inline size_t memoryof (bbox<T,D> const & b) { return b.memory(); }
+
+
+
// Input
/** Read a formatted bbox from a stream. */
diff --git a/Carpet/CarpetLib/src/bboxset.hh b/Carpet/CarpetLib/src/bboxset.hh
index 1a797e2c5..45e0dc0f2 100644
--- a/Carpet/CarpetLib/src/bboxset.hh
+++ b/Carpet/CarpetLib/src/bboxset.hh
@@ -142,6 +142,9 @@ public:
// iterator begin () const { return bs.begin(); }
// iterator end () const { return bs.end(); }
+ // Memory usage
+ size_t memory () const { return memoryof (bs); }
+
// Output
void output (ostream& os) const;
};
@@ -246,6 +249,12 @@ inline bool operator>= (const bboxset<T,D>& s, const bbox<T,D>& b) {
+// Memory usage
+template<class T, int D>
+inline size_t memoryof (bboxset<T,D> const & s) { return s.memory(); }
+
+
+
// Output
template<class T,int D>
inline ostream& operator<< (ostream& os, const bboxset<T,D>& s) {
diff --git a/Carpet/CarpetLib/src/data.cc b/Carpet/CarpetLib/src/data.cc
index 195e75627..2c334da5a 100644
--- a/Carpet/CarpetLib/src/data.cc
+++ b/Carpet/CarpetLib/src/data.cc
@@ -916,6 +916,22 @@ time_interpolate (vector <data *> const & /*srcs*/,
+// Memory usage
+template<typename T>
+size_t
+data<T>::
+memory ()
+ const
+{
+ return
+ memoryof (_memory) +
+ memoryof (vectorlength) +
+ memoryof (vectorindex) +
+ memoryof (vectorleader);
+}
+
+
+
// Output
template<typename T>
ostream &
diff --git a/Carpet/CarpetLib/src/data.hh b/Carpet/CarpetLib/src/data.hh
index fa11e2852..be30a96c7 100644
--- a/Carpet/CarpetLib/src/data.hh
+++ b/Carpet/CarpetLib/src/data.hh
@@ -155,10 +155,20 @@ private:
public:
+ // Memory usage
+ size_t memory () const;
+
// Output
ostream & output (ostream& os) const;
friend ostream & operator<< <T> (ostream & os, data<T> const & d);
};
+
+// Memory usage
+template<typename T>
+inline size_t memoryof (data<T> const & d)
+{
+ return d.memory();
+}
#endif // DATA_HH
diff --git a/Carpet/CarpetLib/src/defs.cc b/Carpet/CarpetLib/src/defs.cc
index 1dd6cb34f..a3d43d88d 100644
--- a/Carpet/CarpetLib/src/defs.cc
+++ b/Carpet/CarpetLib/src/defs.cc
@@ -81,6 +81,63 @@ void consume (istream& is, const char * const s) {
+// Container memory usage
+template <class T>
+size_t
+memoryof (list<T> const & c)
+{
+ size_t s = sizeof c;
+ for (typename list<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Assume that there are two pointers per list element, pointing
+ // to the previous and next element, respectively
+ s += 2 * sizeof (void *) + memoryof(*i);
+ }
+ return s;
+}
+
+template <class T>
+size_t
+memoryof (set<T> const & c)
+{
+ size_t s = sizeof c;
+ for (typename set<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Assume that there are three pointers per list element, forming
+ // a tree structure
+ s += 3 * sizeof (void *) + memoryof(*i);
+ }
+ return s;
+}
+
+template <class T>
+size_t
+memoryof (stack<T> const & c)
+{
+ size_t s = sizeof c;
+#if 0
+ for (typename stack<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Assume that a stack is stored in an efficient manner
+ s += memoryof(*i);
+ }
+#endif
+ // Cannot access elements... a stack is LIFO!
+ s += c.size() * sizeof (T);
+ return s;
+}
+
+template <class T>
+size_t
+memoryof (vector<T> const & c)
+{
+ size_t s = sizeof c;
+ for (typename vector<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Vectors are stored contiguously
+ s += memoryof(*i);
+ }
+ return s;
+}
+
+
+
// Vector input
template<class T>
istream& input (istream& is, vector<T>& v) {
@@ -166,12 +223,41 @@ ostream& output (ostream& os, const vector<T>& v) {
#include "bbox.hh"
#include "bboxset.hh"
+#include "dh.hh"
+#include "gdata.hh"
+#include "ggf.hh"
+#include "region.hh"
+#include "th.hh"
#include "vect.hh"
template int ipow (int x, int y);
template CCTK_REAL ipow (CCTK_REAL x, int y);
template vect<int,3> ipow (vect<int,3> x, int y);
+template size_t memoryof (list<bbox<int,3> > const & l);
+template size_t memoryof (list<vect<int,3> > const & l);
+template size_t memoryof (list<dh*> const & l);
+template size_t memoryof (list<ggf*> const & l);
+template size_t memoryof (list<th*> const & l);
+template size_t memoryof (stack<void*> const & s);
+template size_t memoryof (vector<bool> const & v);
+template size_t memoryof (vector<int> const & v);
+template size_t memoryof (vector<CCTK_REAL> const & v);
+template size_t memoryof (vector<bbox<int,3> > const & v);
+template size_t memoryof (vector<vect<int,3> > const & v);
+template size_t memoryof (vector<pseudoregion_t> const & v);
+template size_t memoryof (vector<region_t> const & v);
+template size_t memoryof (vector<sendrecv_pseudoregion_t> const & v);
+template size_t memoryof (vector<vector<int> > const & v);
+template size_t memoryof (vector<vector<CCTK_REAL> > const & v);
+template size_t memoryof (vector<vector<bbox<int,3> > > const & v);
+template size_t memoryof (vector<vector<dh::dboxes> > const & v);
+template size_t memoryof (vector<vector<region_t> > const & v);
+template size_t memoryof (vector<vector<vector<dh::dboxes> > > const & v);
+template size_t memoryof (vector<vector<vector<region_t> > > const & v);
+template size_t memoryof (vector<vector<vector<gdata*> > > const & v);
+template size_t memoryof (vector<vector<vector<vector<gdata*> > > > const & v);
+
template istream& input (istream& os, vector<int>& v);
template istream& input (istream& os, vector<CCTK_REAL>& v);
template istream& input (istream& os, vector<bbox<int,3> >& v);
diff --git a/Carpet/CarpetLib/src/defs.hh b/Carpet/CarpetLib/src/defs.hh
index 807e9fc59..59d22f4c8 100644
--- a/Carpet/CarpetLib/src/defs.hh
+++ b/Carpet/CarpetLib/src/defs.hh
@@ -235,6 +235,30 @@ namespace CarpetLib {
+// Container memory usage
+inline size_t memoryof (char e) { return sizeof e; }
+inline size_t memoryof (short e) { return sizeof e; }
+inline size_t memoryof (int e) { return sizeof e; }
+inline size_t memoryof (long e) { return sizeof e; }
+inline size_t memoryof (long long e) { return sizeof e; }
+inline size_t memoryof (unsigned char e) { return sizeof e; }
+inline size_t memoryof (unsigned short e) { return sizeof e; }
+inline size_t memoryof (unsigned int e) { return sizeof e; }
+inline size_t memoryof (unsigned long e) { return sizeof e; }
+inline size_t memoryof (unsigned long long e) { return sizeof e; }
+inline size_t memoryof (float e) { return sizeof e; }
+inline size_t memoryof (double e) { return sizeof e; }
+inline size_t memoryof (long double e) { return sizeof e; }
+inline size_t memoryof (void * e) { return sizeof e; }
+template<class T> inline size_t memoryof (T * e) { return sizeof e; }
+template<class T> inline size_t memoryof (T const * e) { return sizeof e; }
+template<class T> size_t memoryof (list<T> const & c);
+template<class T> size_t memoryof (set<T> const & c);
+template<class T> size_t memoryof (stack<T> const & c);
+template<class T> size_t memoryof (vector<T> const & c);
+
+
+
// Container input
template<class T> istream& input (istream& is, vector<T>& v);
diff --git a/Carpet/CarpetLib/src/dh.cc b/Carpet/CarpetLib/src/dh.cc
index 5190c8217..d7825925d 100644
--- a/Carpet/CarpetLib/src/dh.cc
+++ b/Carpet/CarpetLib/src/dh.cc
@@ -1042,7 +1042,54 @@ remove (ggf * const f)
+// Memory usage
+
+size_t
+dh::
+memory ()
+ const
+{
+ return
+ memoryof (ghost_width) +
+ memoryof (buffer_width) +
+ memoryof (prolongation_order_space) +
+ memoryof (boxes) +
+ memoryof (oldboxes) +
+ memoryof (gfs);
+}
+
+size_t
+dh::dboxes::
+memory ()
+ const
+{
+ return
+ memoryof (exterior) +
+ memoryof (is_outer_boundary) +
+ memoryof (outer_boundaries) +
+ memoryof (communicated) +
+ memoryof (boundaries) +
+ memoryof (owned) +
+ memoryof (buffers) +
+ memoryof (active) +
+ memoryof (sync) +
+ memoryof (bndref) +
+ memoryof (ghosts) +
+ memoryof (interior) +
+ memoryof (fast_mg_rest_sendrecv) +
+ memoryof (fast_mg_prol_sendrecv) +
+ memoryof (fast_ref_prol_sendrecv) +
+ memoryof (fast_ref_rest_sendrecv) +
+ memoryof (fast_sync_sendrecv) +
+ memoryof (fast_ref_bnd_prol_sendrecv) +
+ memoryof (fast_old2new_sync_sendrecv) +
+ memoryof (fast_old2new_ref_prol_sendrecv);
+}
+
+
+
// Output
+
ostream &
dh::
output (ostream & os)
diff --git a/Carpet/CarpetLib/src/dh.hh b/Carpet/CarpetLib/src/dh.hh
index ea9b0f294..09d3579e5 100644
--- a/Carpet/CarpetLib/src/dh.hh
+++ b/Carpet/CarpetLib/src/dh.hh
@@ -2,6 +2,7 @@
#define DH_HH
#include <cassert>
+#include <cstdlib>
#include <iostream>
#include <list>
#include <string>
@@ -23,7 +24,6 @@ class ggf;
class dh;
-
// A data hierarchy (grid hierarchy plus ghost zones)
class dh {
@@ -75,6 +75,7 @@ public:
srpvect fast_old2new_sync_sendrecv;
srpvect fast_old2new_ref_prol_sendrecv;
+ size_t memory () const;
ostream & output (ostream & os) const;
};
@@ -125,11 +126,22 @@ public:
void remove (ggf * f);
// Output
+ size_t memory () const;
ostream & output (ostream & os) const;
};
+inline size_t memoryof (dh::dboxes const & b)
+{
+ return b.memory ();
+}
+
+inline size_t memoryof (dh const & d)
+{
+ return d.memory ();
+}
+
inline ostream & operator<< (ostream & os, dh::dboxes const & b)
{
return b.output (os);
diff --git a/Carpet/CarpetLib/src/gf.cc b/Carpet/CarpetLib/src/gf.cc
index b765b3fd2..37b06db75 100644
--- a/Carpet/CarpetLib/src/gf.cc
+++ b/Carpet/CarpetLib/src/gf.cc
@@ -62,6 +62,18 @@ data<T>* gf<T>::operator() (int tl, int rl, int c, int ml)
+// Memory usage
+template<typename T>
+size_t
+gf<T>::
+memory ()
+ const
+{
+ return ggf::memory();
+}
+
+
+
// Output
template<typename T>
ostream& gf<T>::output (ostream& os) const
diff --git a/Carpet/CarpetLib/src/gf.hh b/Carpet/CarpetLib/src/gf.hh
index b4f2e211d..0ca125631 100644
--- a/Carpet/CarpetLib/src/gf.hh
+++ b/Carpet/CarpetLib/src/gf.hh
@@ -71,6 +71,7 @@ public:
// Output
+ virtual size_t memory () const;
virtual ostream& output (ostream& os) const;
private:
gf (); // canonical default construtor
diff --git a/Carpet/CarpetLib/src/ggf.cc b/Carpet/CarpetLib/src/ggf.cc
index b0c9baa56..3e397e999 100644
--- a/Carpet/CarpetLib/src/ggf.cc
+++ b/Carpet/CarpetLib/src/ggf.cc
@@ -519,3 +519,23 @@ transfer_from_all (comm_state & state,
total.stop (0);
}
+
+
+
+// Memory usage
+size_t
+ggf::
+memory ()
+ const
+{
+ return
+ memoryof (varindex) +
+ memoryof (transport_operator) +
+ memoryof (prolongation_order_time) +
+ memoryof (timelevels_) +
+ memoryof (storage) +
+ memoryof (vectorlength) +
+ memoryof (vectorindex) +
+ memoryof (vectorleader) +
+ memoryof (oldstorage);
+}
diff --git a/Carpet/CarpetLib/src/ggf.hh b/Carpet/CarpetLib/src/ggf.hh
index bd0ab64b0..63bb2f59b 100644
--- a/Carpet/CarpetLib/src/ggf.hh
+++ b/Carpet/CarpetLib/src/ggf.hh
@@ -182,12 +182,12 @@ public:
// Access to the data
virtual const gdata* operator() (int tl, int rl, int c, int ml) const = 0;
-
virtual gdata* operator() (int tl, int rl, int c, int ml) = 0;
// Output
+ virtual size_t memory () const;
virtual ostream& output (ostream& os) const = 0;
private:
@@ -199,7 +199,11 @@ private:
-template<int D>
+inline size_t memoryof (ggf const & f)
+{
+ return f.memory ();
+}
+
inline ostream& operator<< (ostream& os, const ggf& f)
{
return f.output(os);
diff --git a/Carpet/CarpetLib/src/gh.cc b/Carpet/CarpetLib/src/gh.cc
index 66722e11d..6a7738048 100644
--- a/Carpet/CarpetLib/src/gh.cc
+++ b/Carpet/CarpetLib/src/gh.cc
@@ -301,6 +301,28 @@ remove (dh * const d)
+// Memory usage
+
+size_t
+gh::
+memory ()
+ const
+{
+ return
+ memoryof (reffacts) +
+ memoryof (refcent) +
+ memoryof (mgfact) +
+ memoryof (mgcent) +
+ memoryof (baseextents) +
+ memoryof (boundary_width) +
+ memoryof (regions) +
+ memoryof (oldregions) +
+ memoryof (ths) +
+ memoryof (dhs);
+}
+
+
+
// Output
void
diff --git a/Carpet/CarpetLib/src/gh.hh b/Carpet/CarpetLib/src/gh.hh
index 6346e1509..4d1592120 100644
--- a/Carpet/CarpetLib/src/gh.hh
+++ b/Carpet/CarpetLib/src/gh.hh
@@ -128,6 +128,7 @@ public:
void remove (dh * d);
// Output
+ size_t memory () const;
ostream & output (ostream & os) const;
private:
@@ -138,6 +139,11 @@ private:
+inline size_t memoryof (gh const & g)
+{
+ return g.memory ();
+}
+
inline ostream & operator<< (ostream & os, gh const & h)
{
return h.output(os);
diff --git a/Carpet/CarpetLib/src/mem.cc b/Carpet/CarpetLib/src/mem.cc
index b6b1c9c8e..d8603591b 100644
--- a/Carpet/CarpetLib/src/mem.cc
+++ b/Carpet/CarpetLib/src/mem.cc
@@ -150,6 +150,25 @@ has_clients () const
+// Memory usage
+template<typename T>
+size_t
+mem<T>::
+memory ()
+ const
+{
+ return
+ memoryof (storage_) +
+ memoryof (nelems_) +
+ memoryof (vectorlength_) +
+ memoryof (owns_storage_) +
+ memoryof (clients_) +
+ memoryof (num_clients_) +
+ (owns_storage_ ? sizeof (T) * vectorlength_ * nelems_ : 0);
+}
+
+
+
size_t const mempool::chunksize;
size_t const mempool::align;
@@ -205,6 +224,25 @@ alloc (size_t nbytes)
+// Memory usage
+size_t
+mempool::
+memory ()
+ const
+{
+ return
+ memoryof (chunks) +
+ memoryof (freeptr) +
+ memoryof (freesize) +
+ (chunksize * chunks.size());
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+
+
+
extern "C" void CarpetLib_setmemlimit (CCTK_ARGUMENTS);
void CarpetLib_setmemlimit (CCTK_ARGUMENTS)
diff --git a/Carpet/CarpetLib/src/mem.hh b/Carpet/CarpetLib/src/mem.hh
index b38d5459b..084383104 100644
--- a/Carpet/CarpetLib/src/mem.hh
+++ b/Carpet/CarpetLib/src/mem.hh
@@ -33,8 +33,14 @@ public:
void register_client (size_t vectorindex);
void unregister_client (size_t vectorindex);
bool has_clients () const;
+
+ // Memory usage
+ size_t memory () const;
};
+template<typename T>
+inline size_t memoryof (mem<T> const & m) { return m.memory(); }
+
// A mempool (memory pool) is a large chunk of memory. You can
@@ -73,6 +79,11 @@ public:
// Allocate some memory and return a pointer to it. This cannot
// fail.
void * alloc (size_t nbytes);
+
+ // Memory usage
+ size_t memory () const;
};
+inline size_t memoryof (mempool const & m) { return m.memory(); }
+
#endif // ifndef MEM_HH
diff --git a/Carpet/CarpetLib/src/region.hh b/Carpet/CarpetLib/src/region.hh
index 73b60004e..dcf618133 100644
--- a/Carpet/CarpetLib/src/region.hh
+++ b/Carpet/CarpetLib/src/region.hh
@@ -29,6 +29,15 @@ bool operator!= (region_t const & a, region_t const & b)
+inline size_t memoryof (region_t const & reg)
+{
+ return
+ memoryof (reg.extent) +
+ memoryof (reg.outer_boundaries) +
+ memoryof (reg.map) +
+ memoryof (reg.processor);
+}
+
istream & operator>> (istream & is, region_t & reg);
ostream & operator<< (ostream & os, region_t const & reg);
@@ -50,6 +59,13 @@ struct pseudoregion_t {
}
};
+inline size_t memoryof (pseudoregion_t const & p)
+{
+ return
+ memoryof (p.extent) +
+ memoryof (p.processor);
+}
+
ostream & operator<< (ostream & os, pseudoregion_t const & p);
struct sendrecv_pseudoregion_t {
@@ -65,6 +81,11 @@ struct sendrecv_pseudoregion_t {
}
};
+inline size_t memoryof (sendrecv_pseudoregion_t const & srp)
+{
+ return memoryof (srp.send) + memoryof (srp.recv);
+}
+
ostream & operator<< (ostream & os, sendrecv_pseudoregion_t const & srp);
diff --git a/Carpet/CarpetLib/src/th.cc b/Carpet/CarpetLib/src/th.cc
index e8d5bbb49..a10dcb289 100644
--- a/Carpet/CarpetLib/src/th.cc
+++ b/Carpet/CarpetLib/src/th.cc
@@ -62,6 +62,21 @@ void th::regrid ()
+// Memory usage
+size_t
+th::
+memory ()
+ const
+{
+ return
+ memoryof (reffacts) +
+ memoryof (delta) +
+ memoryof (times) +
+ memoryof (deltas);
+}
+
+
+
// Output
void th::output (ostream& os) const
{
diff --git a/Carpet/CarpetLib/src/th.hh b/Carpet/CarpetLib/src/th.hh
index b3dc315b0..34e9af999 100644
--- a/Carpet/CarpetLib/src/th.hh
+++ b/Carpet/CarpetLib/src/th.hh
@@ -91,11 +91,16 @@ public:
}
// Output
+ size_t memory () const;
void output (ostream& os) const;
};
+inline size_t memoryof (th const & t)
+{
+ return t.memory ();
+}
inline ostream& operator<< (ostream& os, const th& t) {
t.output(os);
return os;
diff --git a/Carpet/CarpetLib/src/vect.hh b/Carpet/CarpetLib/src/vect.hh
index 29b8a3ba8..e3f6b086b 100644
--- a/Carpet/CarpetLib/src/vect.hh
+++ b/Carpet/CarpetLib/src/vect.hh
@@ -293,6 +293,9 @@ public:
};
#endif
+ // Memory usage
+ size_t memory () const { return D * memoryof (*elt); }
+
// Input/Output helpers
void input (istream& is);
void output (ostream& os) const;
@@ -509,6 +512,13 @@ inline vect<U,D> scan1 (U (* const func)(U val, T x), U val,
+// Memory usage
+
+template<typename T,int D>
+inline size_t memoryof (vect<T,D> const & a) { return a.memory(); }
+
+
+
// Input
/** Read a formatted vector from a stream. */