From f47fa0b9210b9a39db69beb03a51fb70271d6531 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 16 May 2024 18:32:03 +0200 Subject: [PATCH] mpi: fix / adapt setbuf_unit_test to recent changes in the lib --- src/opt/mpi/include/rarray.cc.h | 47 ++++++----------------- src/opt/mpi/include/rarray.h | 24 ++++-------- src/opt/mpi/tests/roperation_unit_test.cc | 6 ++- src/opt/mpi/tests/setbuf_unit_test.cc | 12 +++--- 4 files changed, 31 insertions(+), 58 deletions(-) diff --git a/src/opt/mpi/include/rarray.cc.h b/src/opt/mpi/include/rarray.cc.h index a3fadb0..d154346 100644 --- a/src/opt/mpi/include/rarray.cc.h +++ b/src/opt/mpi/include/rarray.cc.h @@ -237,27 +237,17 @@ namespace CNORXZ { return mMap; } - + template - template - void RCArray::load(const Sptr& lpi, const Sptr>& ai, - const Sptr& i, const Sptr>& imap) const + template + void RCArray::load(const Sptr>& ai, + const Sptr& i, const Vector& required) const { mA->checkFormatCompatibility(mindex(ai->local()*i)); const SizeT blocks = i->pmax().val(); - setupBuffer(lpi, ai, imap, *mA, mBuf, mMap, blocks); + setupBuffer(ai, required, *mA, mBuf, mMap, blocks); } - - template - template - Sptr> RCArray::load(const Sptr& i, const F& f) const - { - Sptr> imap = std::make_shared>(); - CXZ_ERROR("!!!"); - //load(i, /**/, imap); - return imap; - } - + /*==============+ | RArray | +==============*/ @@ -427,14 +417,14 @@ namespace CNORXZ | non-member functions | +============================*/ - template - void setupBuffer(const Sptr& lpi, const Sptr>& rgj, - const Sptr>& imap, const CArrayBase& data, + template + void setupBuffer(const Sptr>& rgj, + const Vector& required, const CArrayBase& data, Vector& buf, Vector& map, const SizeT blocks) { const SizeT myrank = getRankNumber(); const SizeT Nranks = getNumRanks(); - + const SizeT locsz = rgj->local()->lmax().val(); const SizeT mapsize = rgj->range()->size(); map = Vector(mapsize,nullptr); Vector> sendbuf(Nranks); @@ -442,22 +432,7 @@ namespace CNORXZ sb.reserve(data.size()); } Vector> request(Nranks); - const SizeT locsz = rgj->local()->lmax().val(); - // ==== new ==== - - // First loop: Find out what's needed - Vector required(rgj->lmax().val(),false); - lpi->ifor( mapXpr(rgj, lpi, imap, - operation - ( [&](SizeT j) { - const SizeT r = j / locsz; - if(myrank != r){ - required[j] = true; - } - } , posop(rgj) ) ), - NoF {} )(); - // Second loop: setup send buffer auto mi = mindexPtr(rgj->rankI(), rgj->local()); mi->ifor( operation @@ -540,8 +515,8 @@ namespace CNORXZ map[mpidx] = data.data() + l*blocks; } } , posop(mi) ), NoF {} )(); - } + } } // namespace mpi } // namespace CNORXZ diff --git a/src/opt/mpi/include/rarray.h b/src/opt/mpi/include/rarray.h index 34d57d0..20b0eb7 100644 --- a/src/opt/mpi/include/rarray.h +++ b/src/opt/mpi/include/rarray.h @@ -122,25 +122,17 @@ namespace CNORXZ The buffer needs to be initialized before according to required range. */ const Vector& buffermap() const; - + /** Load all data from other ranks that is accessed by ai in a loop over lpi. imap indicates the global (!) position of ai for a given (local) position of lpi. - @param lpi Loop rank index. @param ai Access rank index. @param i Index for non-ranked dimensions. - @param imap Index position map. + @param required Vector of booleans indicating global positions to load. */ - template - void load(const Sptr& lpi, const Sptr>& ai, - const Sptr& i, const Sptr>& imap) const; + template + void load(const Sptr>& ai, + const Sptr& i, const Vector& required) const; - /** Load all data from other ranks that is accessed by f(i). - @param lpi Loop index. - @param f Map function. - @return Index position map. - */ - template - Sptr> load(const Sptr& lpi, const F& f) const; protected: ObjHandle> mA; @@ -255,9 +247,9 @@ namespace CNORXZ }; - template - void setupBuffer(const Sptr& lpi, const Sptr>& rgj, - const Sptr>& imap, const CArrayBase& data, + template + void setupBuffer(const Sptr>& rgj, + const Vector& required, const CArrayBase& data, Vector& buf, Vector& map, const SizeT blocks); diff --git a/src/opt/mpi/tests/roperation_unit_test.cc b/src/opt/mpi/tests/roperation_unit_test.cc index 64482a9..1a1f50d 100644 --- a/src/opt/mpi/tests/roperation_unit_test.cc +++ b/src/opt/mpi/tests/roperation_unit_test.cc @@ -129,7 +129,11 @@ namespace imap1 = setupMap(xp, x, [&](const auto& vec) { return std::make_tuple((std::get<0>(vec)+1)%T, (std::get<1>(vec)+1)%L, (std::get<2>(vec)+1)%L, (std::get<3>(vec)+1)%L); } ); - mM1.load(x, xp, AB, imap1); + Vector req(xp->range()->size(), false); + for(const auto& r: *imap1){ + req[r] = true; + } + mM1.load(xp, AB, req); res.rop(x*A*B) = mapXpr(xp,x,imap1, mM1(xp*A*B) - mM1(x*A*B) ); for(SizeT x0 = 0; x0 != T; ++x0) { diff --git a/src/opt/mpi/tests/setbuf_unit_test.cc b/src/opt/mpi/tests/setbuf_unit_test.cc index f9dfcb7..94be2a3 100644 --- a/src/opt/mpi/tests/setbuf_unit_test.cc +++ b/src/opt/mpi/tests/setbuf_unit_test.cc @@ -110,8 +110,13 @@ namespace return o; }; - const Sptr> fmap = setupMap(rgj, rgi, shift); - setupBuffer(rgj, rgi, fmap, data, buf, map, mSRange->size()); + Vector req(mRRange->size(), false); + for(auto ii = *rgi; ii.lex() != ii.lmax().val(); ++ii){ + auto jj = ii; + jj.at( shift( ii.meta() ) ); + req[jj.pos()] = true; + } + setupBuffer(rgi, req, data, buf, map, mSRange->size()); EXPECT_EQ(mRRange->sub(1)->size(), 16*12*12*12/4); const SizeT locsz = rgj->local()->lmax().val(); @@ -128,10 +133,7 @@ namespace if(rgi->rank() == myrank){ const SizeT mpidx = (rgj->pos() - myrankoff + mapsize) % mapsize; - VCHECK(mpidx); - assert(mpidx < map.size()); EXPECT_TRUE(map.data()[mpidx] != nullptr); - if(map.data()[mpidx] == nullptr) continue; const Double vn = *map[mpidx]/blocks; const SizeT xp = static_cast(vn);