mpi: fix / adapt setbuf_unit_test to recent changes in the lib

This commit is contained in:
Christian Zimmermann 2024-05-16 18:32:03 +02:00
parent 72ca92a08c
commit f47fa0b921
4 changed files with 31 additions and 58 deletions

View file

@ -237,27 +237,17 @@ namespace CNORXZ
{
return mMap;
}
template <typename T>
template <class LoopI, class SrcI, class RSrcI, class I>
void RCArray<T>::load(const Sptr<LoopI>& lpi, const Sptr<RIndex<SrcI,RSrcI>>& ai,
const Sptr<I>& i, const Sptr<Vector<SizeT>>& imap) const
template <class SrcI, class RSrcI, class I>
void RCArray<T>::load(const Sptr<RIndex<SrcI,RSrcI>>& ai,
const Sptr<I>& i, const Vector<bool>& 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 <typename T>
template <class Index, class F>
Sptr<Vector<SizeT>> RCArray<T>::load(const Sptr<Index>& i, const F& f) const
{
Sptr<Vector<SizeT>> imap = std::make_shared<Vector<SizeT>>();
CXZ_ERROR("!!!");
//load(i, /**/, imap);
return imap;
}
/*==============+
| RArray |
+==============*/
@ -427,14 +417,14 @@ namespace CNORXZ
| non-member functions |
+============================*/
template <class LoopI, class SrcI, class RSrcI, typename T>
void setupBuffer(const Sptr<LoopI>& lpi, const Sptr<RIndex<SrcI,RSrcI>>& rgj,
const Sptr<Vector<SizeT>>& imap, const CArrayBase<T>& data,
template <class SrcI, class RSrcI, typename T>
void setupBuffer(const Sptr<RIndex<SrcI,RSrcI>>& rgj,
const Vector<bool>& required, const CArrayBase<T>& data,
Vector<T>& buf, Vector<const T*>& 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<const T*>(mapsize,nullptr);
Vector<Vector<T>> sendbuf(Nranks);
@ -442,22 +432,7 @@ namespace CNORXZ
sb.reserve(data.size());
}
Vector<Vector<SizeT>> request(Nranks);
const SizeT locsz = rgj->local()->lmax().val();
// ==== new ====
// First loop: Find out what's needed
Vector<bool> 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

View file

@ -122,25 +122,17 @@ namespace CNORXZ
The buffer needs to be initialized before according to required range.
*/
const Vector<const T*>& 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 <class LoopI, class SrcI, class RSrcI, class I>
void load(const Sptr<LoopI>& lpi, const Sptr<RIndex<SrcI,RSrcI>>& ai,
const Sptr<I>& i, const Sptr<Vector<SizeT>>& imap) const;
template <class SrcI, class RSrcI, class I>
void load(const Sptr<RIndex<SrcI,RSrcI>>& ai,
const Sptr<I>& i, const Vector<bool>& 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 <class Index, class F>
Sptr<Vector<SizeT>> load(const Sptr<Index>& lpi, const F& f) const;
protected:
ObjHandle<CArrayBase<T>> mA;
@ -255,9 +247,9 @@ namespace CNORXZ
};
template <class LoopI, class SrcI, class RSrcI, typename T>
void setupBuffer(const Sptr<LoopI>& lpi, const Sptr<RIndex<SrcI,RSrcI>>& rgj,
const Sptr<Vector<SizeT>>& imap, const CArrayBase<T>& data,
template <class SrcI, class RSrcI, typename T>
void setupBuffer(const Sptr<RIndex<SrcI,RSrcI>>& rgj,
const Vector<bool>& required, const CArrayBase<T>& data,
Vector<T>& buf, Vector<const T*>& map, const SizeT blocks);

View file

@ -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<bool> 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) {

View file

@ -110,8 +110,13 @@ namespace
return o;
};
const Sptr<Vector<SizeT>> fmap = setupMap(rgj, rgi, shift);
setupBuffer(rgj, rgi, fmap, data, buf, map, mSRange->size());
Vector<bool> 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<SizeT>(vn);