From 9166952a1e2571bf5656345d7f8f1d1246e033d7 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sun, 4 Aug 2013 00:25:49 -0400 Subject: CarpetLib: Store registered gh, dh, th, gf, data etc. via sets, not via lists Use set instead of list to store registered gh, dh, th, gf, data. Do not store an iterator as handle for de-registering. This corrects some memory corruption with the Intel compiler; the previous code may have been illegal. --- Carpet/CarpetLib/src/defs.cc | 16 ++++++++++----- Carpet/CarpetLib/src/dh.cc | 44 +++++++++++++++++++---------------------- Carpet/CarpetLib/src/dh.hh | 13 +++++------- Carpet/CarpetLib/src/gdata.cc | 8 ++++---- Carpet/CarpetLib/src/gdata.hh | 5 ++--- Carpet/CarpetLib/src/ggf.cc | 13 ++++++------ Carpet/CarpetLib/src/ggf.hh | 7 +++---- Carpet/CarpetLib/src/gh.cc | 46 +++++++++++++++++++++---------------------- Carpet/CarpetLib/src/gh.hh | 19 ++++++++---------- Carpet/CarpetLib/src/th.cc | 16 +++++++-------- Carpet/CarpetLib/src/th.hh | 4 +--- 11 files changed, 90 insertions(+), 101 deletions(-) diff --git a/Carpet/CarpetLib/src/defs.cc b/Carpet/CarpetLib/src/defs.cc index 0bc1e5d48..7776a3ab8 100644 --- a/Carpet/CarpetLib/src/defs.cc +++ b/Carpet/CarpetLib/src/defs.cc @@ -340,26 +340,31 @@ template CCTK_REAL ipow (CCTK_REAL x, int y); //template vect ipow (vect x, int y); template vect ipow (vect x, int y); +template size_t memoryof (rvect const & v); //template size_t memoryof (list const & l); //template size_t memoryof (list const & l); -template size_t memoryof (list const & l); -template size_t memoryof (list const & l); -template size_t memoryof (list const & l); -template size_t memoryof (list const & l); -template size_t memoryof (list const & l); +template size_t memoryof (set const & l); +template size_t memoryof (set const & l); +template size_t memoryof (set const & l); +template size_t memoryof (set const & l); +template size_t memoryof (set const & l); template size_t memoryof (stack const & s); template size_t memoryof (vector const & v); template size_t memoryof (vector const & v); //template size_t memoryof (vector const & v); +template size_t memoryof (vector const & v); +template size_t memoryof (vector const & v); template size_t memoryof (vector > const & v); template size_t memoryof (vector > const & v); template size_t memoryof (vector > const & v); +template size_t memoryof (vector const & v); template size_t memoryof (vector > const & v); #ifdef CARPET_ENABLE_BBOXSET2 template size_t memoryof (vector > const & v); #endif template size_t memoryof (vector const & v); template size_t memoryof (vector const & v); +template size_t memoryof (vector const & v); template size_t memoryof (vector*> const & f); //template size_t memoryof (vector const & v); //template size_t memoryof (vector const & v); @@ -367,6 +372,7 @@ template size_t memoryof (vector const & v); template size_t memoryof (vector > const & v); template size_t memoryof (vector > const & v); template size_t memoryof (vector > const & v); +template size_t memoryof (vector > const & v); template size_t memoryof (vector > const & v); //template size_t memoryof (vector > const & v); template size_t memoryof (vector > const & v); diff --git a/Carpet/CarpetLib/src/dh.cc b/Carpet/CarpetLib/src/dh.cc index 5eaa49cf9..44a87c0fd 100644 --- a/Carpet/CarpetLib/src/dh.cc +++ b/Carpet/CarpetLib/src/dh.cc @@ -23,7 +23,7 @@ using namespace CarpetLib; -list dh::alldh; +set dh::alldh; @@ -120,8 +120,8 @@ dh (gh & h_, assert (prolongation_orders_space.AT(rl) >= 0); } - alldhi = alldh.insert(alldh.end(), this); - gh_handle = h.add (this); + alldh.insert(this); + h.insert (this); CHECKPOINT; regrid (false); for (int rl = 0; rl < h.reflevels(); ++ rl) { @@ -137,8 +137,9 @@ dh:: ~dh () { CHECKPOINT; - h.erase (gh_handle); - alldh.erase(alldhi); + assert (gfs.empty()); + h.erase (this); + alldh.erase (this); } @@ -2114,8 +2115,7 @@ regrid (bool const do_init) cout << "memoryof(dh.fast_boxes)=" << memoryof(fast_boxes) << eol; int gfcount = 0; size_t gfmemory = 0; - for (list::const_iterator - gfi = gfs.begin(); gfi != gfs.end(); ++ gfi) + for (set::const_iterator gfi = gfs.begin(); gfi != gfs.end(); ++ gfi) { ++ gfcount; gfmemory += memoryof(**gfi); @@ -2200,39 +2200,39 @@ recompose (int const rl, bool const do_prolongate) static Carpet::Timer timer ("CarpetLib::dh::recompose"); timer.start (); - for (list::iterator f=gfs.begin(); f!=gfs.end(); ++f) { + for (set::iterator f=gfs.begin(); f!=gfs.end(); ++f) { (*f)->recompose_crop (); } if (combine_recompose) { // Recompose all grid functions of this refinement levels at once. // This may be faster, but requires more memory. - for (list::iterator f=gfs.begin(); f!=gfs.end(); ++f) { + for (set::iterator f=gfs.begin(); f!=gfs.end(); ++f) { (*f)->recompose_allocate (rl); } // TODO: If this works, rename do_prolongate to do_init here, and // remove the do_prolongate parameter from ggf::recompose_fill #if 0 for (comm_state state; not state.done(); state.step()) { - for (list::iterator f=gfs.begin(); f!=gfs.end(); ++f) { + for (set::iterator f=gfs.begin(); f!=gfs.end(); ++f) { (*f)->recompose_fill (state, rl, do_prolongate); } } #endif if (do_prolongate) { for (comm_state state; not state.done(); state.step()) { - for (list::iterator f=gfs.begin(); f!=gfs.end(); ++f) { + for (set::iterator f=gfs.begin(); f!=gfs.end(); ++f) { (*f)->recompose_fill (state, rl, true); } } } - for (list::iterator f=gfs.begin(); f!=gfs.end(); ++f) { + for (set::iterator f=gfs.begin(); f!=gfs.end(); ++f) { (*f)->recompose_free_old (rl); } } else { // Recompose the grid functions sequentially. This may be slower, // but requires less memory. This is the default. - for (list::iterator f=gfs.begin(); f!=gfs.end(); ++f) { + for (set::iterator f=gfs.begin(); f!=gfs.end(); ++f) { (*f)->recompose_allocate (rl); #if 0 for (comm_state state; not state.done(); state.step()) { @@ -2254,20 +2254,20 @@ recompose (int const rl, bool const do_prolongate) // Grid function management -dh::ggf_handle +void dh:: -add (ggf * const f) +insert (ggf * const f) { CHECKPOINT; - return gfs.insert (gfs.end(), f); + gfs.insert (f); } void dh:: -erase (ggf_handle const fi) +erase (ggf * const f) { CHECKPOINT; - gfs.erase (fi); + gfs.erase (f); } @@ -2397,9 +2397,6 @@ memory () const { return - sizeof alldhi + // memoryof (alldhi) + - sizeof & h + // memoryof (& h) + - sizeof gh_handle + // memoryof (gh_handle) + memoryof (ghost_widths) + memoryof (buffer_widths) + memoryof (overlap_widths) + @@ -2416,8 +2413,7 @@ dh:: allmemory () { size_t mem = memoryof(alldh); - for (list::const_iterator - dhi = alldh.begin(); dhi != alldh.end(); ++ dhi) + for (set::const_iterator dhi = alldh.begin(); dhi != alldh.end(); ++ dhi) { mem += memoryof(**dhi); } @@ -2754,7 +2750,7 @@ output (ostream & os) << "gfs={"; { bool isfirst = true; - for (list::const_iterator + for (set::const_iterator f = gfs.begin(); f != gfs.end(); ++ f, isfirst = false) { if (not isfirst) os << ","; diff --git a/Carpet/CarpetLib/src/dh.hh b/Carpet/CarpetLib/src/dh.hh index 2a03ceccc..b558b013f 100644 --- a/Carpet/CarpetLib/src/dh.hh +++ b/Carpet/CarpetLib/src/dh.hh @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -29,8 +29,7 @@ class dh; // A data hierarchy (grid hierarchy plus ghost zones) class dh { - static list alldh; - list::iterator alldhi; + static set alldh; // Types public: @@ -232,7 +231,6 @@ public: // should be readonly // Fields gh & h; // hierarchy - gh::dh_handle gh_handle; #if 0 i2vect ghost_width; // number of ghost zones @@ -250,8 +248,7 @@ public: // should be readonly level_mboxes level_boxes; // grid hierarchy [ml][rl] fast_mboxes fast_boxes; // grid hierarchy [ml][rl][p] - typedef list::iterator ggf_handle; - list gfs; // list of all grid functions + set gfs; // all grid functions public: @@ -288,8 +285,8 @@ private: public: // Grid function management - ggf_handle add (ggf * f); - void erase (ggf_handle fi); + void insert (ggf * f); + void erase (ggf * f); // Output size_t memory () const CCTK_MEMBER_ATTRIBUTE_PURE; diff --git a/Carpet/CarpetLib/src/gdata.cc b/Carpet/CarpetLib/src/gdata.cc index ecc8c4ba8..2226a5b07 100644 --- a/Carpet/CarpetLib/src/gdata.cc +++ b/Carpet/CarpetLib/src/gdata.cc @@ -79,7 +79,7 @@ template MPI_Datatype mpi_datatype (slab const&); -list gdata::allgdata; +set gdata::allgdata; @@ -96,7 +96,7 @@ gdata::gdata (const int varindex_, { DECLARE_CCTK_PARAMETERS; - allgdatai = allgdata.insert(allgdata.end(), this); + allgdata.insert(this); if (barriers) { dist::barrier (dist::comm(), 783988953, "CarpetLib::gdata::gdata"); @@ -108,7 +108,7 @@ gdata::~gdata () { DECLARE_CCTK_PARAMETERS; - allgdata.erase(allgdatai); + allgdata.erase(this); if (barriers) { dist::barrier (dist::comm(), 109687805, "CarpetLib::gdata::~gdata"); @@ -463,7 +463,7 @@ gdata:: allmemory () { size_t mem = memoryof(allgdata); - for (list::const_iterator + for (set::const_iterator gdatai = allgdata.begin(); gdatai != allgdata.end(); ++ gdatai) { mem += memoryof(**gdatai); diff --git a/Carpet/CarpetLib/src/gdata.hh b/Carpet/CarpetLib/src/gdata.hh index 230a6583c..086d84b28 100644 --- a/Carpet/CarpetLib/src/gdata.hh +++ b/Carpet/CarpetLib/src/gdata.hh @@ -51,9 +51,8 @@ namespace dist { // A generic data storage without type information class gdata { - static list allgdata; - list::iterator allgdatai; - + static set allgdata; + protected: // should be readonly // Fields diff --git a/Carpet/CarpetLib/src/ggf.cc b/Carpet/CarpetLib/src/ggf.cc index 0f5015897..ebc81cb6d 100644 --- a/Carpet/CarpetLib/src/ggf.cc +++ b/Carpet/CarpetLib/src/ggf.cc @@ -21,7 +21,7 @@ using namespace CarpetLib; -list ggf::allggf; +set ggf::allggf; @@ -50,15 +50,14 @@ ggf::ggf (const int varindex_, const operator_type transport_operator_, timelevels_.AT(ml).resize(d.h.reflevels(), 0); } - allggfi = allggf.insert(allggf.end(), this); - - dh_handle = d.add(this); + allggf.insert (this); + d.insert (this); } // Destructors ggf::~ggf () { - d.erase(dh_handle); - allggf.erase(allggfi); + d.erase (this); + allggf.erase (this); } // Comparison @@ -663,7 +662,7 @@ ggf:: allmemory () { size_t mem = memoryof(allggf); - for (list::const_iterator + for (set::const_iterator ggfi = allggf.begin(); ggfi != allggf.end(); ++ ggfi) { mem += memoryof(**ggfi); diff --git a/Carpet/CarpetLib/src/ggf.hh b/Carpet/CarpetLib/src/ggf.hh index 2e8b9f4ad..d55deb270 100644 --- a/Carpet/CarpetLib/src/ggf.hh +++ b/Carpet/CarpetLib/src/ggf.hh @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -29,9 +30,8 @@ ostream& operator<< (ostream& os, const ggf& f); // A generic grid function without type information class ggf { - static list allggf; - list::iterator allggfi; - + static set allggf; + // Types typedef vector pvect; typedef vector srpvect; @@ -53,7 +53,6 @@ public: // should be readonly const gh &h; // grid hierarchy dh &d; // data hierarchy - dh::ggf_handle dh_handle; protected: vector > timelevels_; // time levels [ml][rl] diff --git a/Carpet/CarpetLib/src/gh.cc b/Carpet/CarpetLib/src/gh.cc index 3659f977c..5c13d0b6a 100644 --- a/Carpet/CarpetLib/src/gh.cc +++ b/Carpet/CarpetLib/src/gh.cc @@ -19,7 +19,7 @@ using namespace std; -list gh::allgh; +set gh::allgh; @@ -70,14 +70,14 @@ gh (vector const & reffacts_, centering const refcent_, } } - allghi = allgh.insert(allgh.end(), this); + allgh.insert (this); } // Destructors gh:: ~gh () { - allgh.erase(allghi); + allgh.erase (this); } @@ -233,11 +233,11 @@ regrid (rregs const & superregs, mregs const & regs, bool const do_init) // Regrid the other hierarchies - for (list::iterator t=ths.begin(); t!=ths.end(); ++t) { + for (set::iterator t=ths.begin(); t!=ths.end(); ++t) { (*t)->regrid(); } - for (list::iterator d=dhs.begin(); d!=dhs.end(); ++d) { + for (set::iterator d=dhs.begin(); d!=dhs.end(); ++d) { (*d)->regrid(do_init); } @@ -254,11 +254,11 @@ regrid_free (bool const do_init) old_global_components_.clear(); old_local_components_.clear(); - for (list::iterator t=ths.begin(); t!=ths.end(); ++t) { + for (set::iterator t=ths.begin(); t!=ths.end(); ++t) { (*t)->regrid_free(); } - for (list::iterator d=dhs.begin(); d!=dhs.end(); ++d) { + for (set::iterator d=dhs.begin(); d!=dhs.end(); ++d) { (*d)->regrid_free(do_init); } } @@ -275,7 +275,7 @@ recompose (int const rl, if (do_recompose) { // Recompose the other hierarchies - for (list::iterator d=dhs.begin(); d!=dhs.end(); ++d) { + for (set::iterator d=dhs.begin(); d!=dhs.end(); ++d) { (*d)->recompose (rl, do_prolongate); } @@ -454,7 +454,7 @@ locate_position (rvect const & rpos, // Find associated dh assert (dhs.size() == 1); - dh const& dd = *dhs.front(); + dh const& dd = **dhs.begin(); // Try finer levels first for (rl = maxrl-1; rl >= minrl; --rl) { @@ -515,7 +515,7 @@ locate_position (ivect const & ipos, // Find associated dh assert (dhs.size() == 1); - dh const& dd = *dhs.front(); + dh const& dd = **dhs.begin(); // Try finer levels first for (rl = maxrl-1; rl >= minrl; --rl) { @@ -566,36 +566,36 @@ locate_position (ivect const & ipos, // Time hierarchy management -gh::th_handle +void gh:: -add (th * const t) +insert (th * const t) { - return ths.insert(ths.end(), t); + ths.insert(t); } void gh:: -erase (th_handle const ti) +erase (th * const t) { - ths.erase(ti); + ths.erase(t); } // Data hierarchy management -gh::dh_handle +void gh:: -add (dh * const d) +insert (dh * const d) { - return dhs.insert(dhs.end(), d); + dhs.insert(d); } void gh:: -erase (dh_handle di) +erase (dh * const d) { - dhs.erase (di); + dhs.erase(d); } @@ -608,7 +608,6 @@ memory () const { return - sizeof allghi + // memoryof (allghi) + memoryof (reffacts) + memoryof (refcent) + memoryof (mgfact) + @@ -630,8 +629,7 @@ gh:: allmemory () { size_t mem = memoryof(allgh); - for (list::const_iterator - ghi = allgh.begin(); ghi != allgh.end(); ++ ghi) + for (set::const_iterator ghi = allgh.begin(); ghi != allgh.end(); ++ ghi) { mem += memoryof(**ghi); } @@ -692,7 +690,7 @@ output (ostream & os) << "dhs={"; { bool isfirst = true; - for (list::const_iterator + for (set::const_iterator d = dhs.begin(); d != dhs.end(); ++ d, isfirst = false) { if (not isfirst) os << ","; diff --git a/Carpet/CarpetLib/src/gh.hh b/Carpet/CarpetLib/src/gh.hh index ef6198e0f..8c59c7073 100644 --- a/Carpet/CarpetLib/src/gh.hh +++ b/Carpet/CarpetLib/src/gh.hh @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include "bbox.hh" @@ -28,8 +28,7 @@ class gh; // level. The extents do not include ghost zones. class gh { - static list allgh; - list::iterator allghi; + static set allgh; public: @@ -64,10 +63,8 @@ public: mregs regions; // extents and properties of all grids mregs oldregions; // extents and properties of all grids - typedef list::iterator th_handle; - list ths; // list of all time hierarchies - typedef list::iterator dh_handle; - list dhs; // list of all data hierarchies + set ths; // all time hierarchies + set dhs; // all data hierarchies public: @@ -179,12 +176,12 @@ public: CCTK_MEMBER_ATTRIBUTE_PURE; // Time hierarchy management - th_handle add (th * t); - void erase (th_handle ti); + void insert (th * t); + void erase (th * t); // Data hierarchy management - dh_handle add (dh * d); - void erase (dh_handle di); + void insert (dh * d); + void erase (dh * d); // Output size_t memory () const CCTK_MEMBER_ATTRIBUTE_PURE; diff --git a/Carpet/CarpetLib/src/th.cc b/Carpet/CarpetLib/src/th.cc index 9817e77bb..33c748e51 100644 --- a/Carpet/CarpetLib/src/th.cc +++ b/Carpet/CarpetLib/src/th.cc @@ -14,7 +14,7 @@ using namespace std; -list th::allth; +set th::allth; @@ -27,8 +27,8 @@ th::th (gh& h_, timelevels(0) { reffacts.resize(1, 1); - allthi = allth.insert(allth.end(), this); - gh_handle = h.add(this); + allth.insert(this); + h.insert(this); } th::th (gh& h_, int const timelevels_, vector const& reffacts_, @@ -44,15 +44,15 @@ th::th (gh& h_, int const timelevels_, vector const& reffacts_, assert (reffacts.AT(n) >= reffacts.AT(n-1)); assert (reffacts.AT(n) % reffacts.AT(n-1) == 0); } - allthi = allth.insert(allth.end(), this); - gh_handle = h.add(this); + allth.insert(this); + h.insert(this); } // Destructors th::~th () { - h.erase(gh_handle); - allth.erase(allthi); + h.erase(this); + allth.erase(this); } // Modifiers @@ -187,7 +187,7 @@ th:: allmemory () { size_t mem = memoryof(allth); - for (list::const_iterator + for (set::const_iterator thi = allth.begin(); thi != allth.end(); ++ thi) { mem += memoryof(**thi); diff --git a/Carpet/CarpetLib/src/th.hh b/Carpet/CarpetLib/src/th.hh index d925aeab4..12c7733b9 100644 --- a/Carpet/CarpetLib/src/th.hh +++ b/Carpet/CarpetLib/src/th.hh @@ -28,14 +28,12 @@ ostream& operator<< (ostream& os, const th& t); // The time hierarchy (information about the current time) class th { - static list allth; - list::iterator allthi; + static set allth; public: // should be readonly // Fields gh& h; // hierarchy - gh::th_handle gh_handle; bool const time_interpolation_during_regridding; -- cgit v1.2.3