mpi: rindex: fixes

This commit is contained in:
Christian Zimmermann 2024-10-16 16:31:02 -07:00
parent 31e892005b
commit 82dcfbde2e
2 changed files with 18 additions and 7 deletions

View file

@ -31,8 +31,8 @@ namespace CNORXZ
mI(std::make_shared<IndexI>(mRange->local())), mI(std::make_shared<IndexI>(mRange->local())),
mK(std::make_shared<IndexK>(mRange->geom())), mK(std::make_shared<IndexK>(mRange->geom())),
mNRanks(getNumRanks()), mNRanks(getNumRanks()),
mRankOffset(in.mRankOffset), mRankFormat(in.mRankFormat),
mRankFormat(in.mRankFormat) mRankOffset(in.mRankOffset)
{ {
*this = in.lex(); *this = in.lex();
} }
@ -55,7 +55,9 @@ namespace CNORXZ
mRange(rangeCast<RangeType>(global)), mRange(rangeCast<RangeType>(global)),
mI(std::make_shared<IndexI>(mRange->local())), mI(std::make_shared<IndexI>(mRange->local())),
mK(std::make_shared<IndexK>(mRange->geom())), mK(std::make_shared<IndexK>(mRange->geom())),
mNRanks(getNumRanks()) mNRanks(getNumRanks()),
mRankFormat(1),
mRankOffset(0)
{ {
*this = lexpos; *this = lexpos;
} }
@ -65,7 +67,9 @@ namespace CNORXZ
mRange(rangeCast<RangeType>( RRangeFactory(i->range(), k->range()).create() )), mRange(rangeCast<RangeType>( RRangeFactory(i->range(), k->range()).create() )),
mI(i), mI(i),
mK(k), mK(k),
mNRanks(getNumRanks()) mNRanks(getNumRanks()),
mRankFormat(1),
mRankOffset(0)
{ {
(*this)(); (*this)();
} }
@ -329,8 +333,11 @@ namespace CNORXZ
template <class Xpr, class F> template <class Xpr, class F>
constexpr decltype(auto) RIndex<IndexI,IndexK>::ifor(const Xpr& xpr, F&& f) const constexpr decltype(auto) RIndex<IndexI,IndexK>::ifor(const Xpr& xpr, F&& f) const
{ {
return accxpr( mpi::getRankNumber(), mK->id(), mI->ifor(xpr, std::forward<F>(f)), const SizeT r = getRankNumber();
NoF {}); const SizeT off = r % mRankFormat;
//assert(off == mRankOffset);
const SizeT n = ( (r-off) / mRankFormat ) % mK->pmax().val();
return accxpr( n, mK->id(), mI->ifor(xpr, std::forward<F>(f)), NoF {});
} }
template <class IndexI, class IndexK> template <class IndexI, class IndexK>
@ -417,7 +424,11 @@ namespace CNORXZ
template <class IndexI, class IndexK> template <class IndexI, class IndexK>
void RIndex<IndexI,IndexK>::setRankFormat(SizeT rankFormat) void RIndex<IndexI,IndexK>::setRankFormat(SizeT rankFormat)
{ {
const SizeT nr = getRankNumber();
mRankFormat = rankFormat; mRankFormat = rankFormat;
const SizeT kmax = mK->pmax().val();
const SizeT nextblocks = kmax * mRankFormat;
mRankOffset = nr % mRankFormat + ( nr / nextblocks ) * nextblocks;
CXZ_ASSERT(mNRanks % mRankFormat == 0, "rankFormat (" << mRankFormat CXZ_ASSERT(mNRanks % mRankFormat == 0, "rankFormat (" << mRankFormat
<< ") does not divide total number of ranks (" << mNRanks << ")"); << ") does not divide total number of ranks (" << mNRanks << ")");
} }

View file

@ -171,8 +171,8 @@ namespace CNORXZ
Sptr<IndexI> mI; /**< Index on the local range of the THIS rank. */ Sptr<IndexI> mI; /**< Index on the local range of the THIS rank. */
Sptr<IndexK> mK; /**< Multi-index indicating the current rank. */ Sptr<IndexK> mK; /**< Multi-index indicating the current rank. */
SizeT mNRanks; /**< Number of ranks; in general different from but dividable by mK's maximum. */ SizeT mNRanks; /**< Number of ranks; in general different from but dividable by mK's maximum. */
SizeT mRankOffset = 0; /** < Offset in case this index only serves a sub-slice of ranks .*/
SizeT mRankFormat = 1; /**< Frequency of ranks to be served by this index. */ SizeT mRankFormat = 1; /**< Frequency of ranks to be served by this index. */
SizeT mRankOffset = 0; /** < Offset in case this index only serves a sub-slice of ranks .*/
}; };
template <class IndexI, class IndexK> template <class IndexI, class IndexK>