rindex: distinguish between lex and pos

This commit is contained in:
Christian Zimmermann 2024-03-24 02:42:45 +01:00
parent d9a546a5cc
commit 5d76ae6e36
4 changed files with 128 additions and 118 deletions

View file

@ -3,85 +3,89 @@
namespace CNORXZ namespace CNORXZ
{ {
/*================+ namespace mpi
| CROpRoot |
+================*/
template <typename T, class IndexT>
template <class PosT>
constexpr decltype(auto) CROpRoot<T,IndexT>::operator()(const PosT& pos) const
{
const SizeT L = mIndex->lmax().val();
const SizeT m = mIndex->myrank()
const SizeT dst = ( m + pos.val() ) % L;
const SizeT src = ( m - pos.val() + L ) % L;
}
template <typename T, class IndexT>
constexpr decltype(auto) CROpRoot<T,IndexT>::operator()() const
{ {
} /*================+
| CROpRoot |
+================*/
template <typename T, class IndexT> template <typename T, class IndexT>
template <SizeT I> template <class PosT>
constexpr decltype(auto) CROpRoot<T,IndexT>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) CROpRoot<T,IndexT>::operator()(const PosT& pos) const
{ {
const SizeT L = mIndex->lmax().val();
const SizeT m = mIndex->myrank();
const SizeT dst = ( m + pos.val() ) % L;
const SizeT src = ( m - pos.val() + L ) % L;
} }
/*===============+ template <typename T, class IndexT>
| ROpRoot | constexpr decltype(auto) CROpRoot<T,IndexT>::operator()() const
+===============*/ {
template <typename T, class IndexT> }
template <class PosT>
constexpr decltype(auto) ROpRoot<T,IndexT>::operator()(const PosT& pos) const
{
} template <typename T, class IndexT>
template <SizeT I>
constexpr decltype(auto) CROpRoot<T,IndexT>::rootSteps(const IndexId<I>& id) const
{
template <typename T, class IndexT> }
constexpr decltype(auto) ROpRoot<T,IndexT>::operator()() const
{
} /*===============+
| ROpRoot |
+===============*/
template <typename T, class IndexT> template <typename T, class IndexT>
template <SizeT I> template <class PosT>
constexpr decltype(auto) ROpRoot<T,IndexT>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) ROpRoot<T,IndexT>::operator()(const PosT& pos) const
{ {
} }
/*====================+ template <typename T, class IndexT>
| RContraction | constexpr decltype(auto) ROpRoot<T,IndexT>::operator()() const
+====================*/ {
template <class CXpr> }
constexpr RContraction<CXpr>::RContraction(CXpr&& cxpr) :
mCXpr(std::forward<CXpr>(cxpr))
{}
template <class CXpr> template <typename T, class IndexT>
template <class PosT> template <SizeT I>
constexpr decltype(auto) RContraction<CXpr>::operator()(const PosT& pos) const constexpr decltype(auto) ROpRoot<T,IndexT>::rootSteps(const IndexId<I>& id) const
{ {
} }
template <class CXpr> /*====================+
constexpr decltype(auto) RContraction<CXpr>::operator()() const | RContraction |
{ +====================*/
} template <class CXpr>
constexpr RContraction<CXpr>::RContraction(CXpr&& cxpr) :
mCXpr(std::forward<CXpr>(cxpr))
{}
template <class CXpr> template <class CXpr>
template <SizeT I> template <class PosT>
constexpr decltype(auto) RContraction<CXpr>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) RContraction<CXpr>::operator()(const PosT& pos) const
{ {
} }
} template <class CXpr>
constexpr decltype(auto) RContraction<CXpr>::operator()() const
{
}
template <class CXpr>
template <SizeT I>
constexpr decltype(auto) RContraction<CXpr>::rootSteps(const IndexId<I>& id) const
{
}
} // namespace mpi
} // namespace CNORXZ

View file

@ -14,67 +14,70 @@
namespace CNORXZ namespace CNORXZ
{ {
template <typename T, class IndexT> namespace mpi
class CROpRoot : public COpInterface<CROpRoot<T,IndexT>>
{ {
public: template <typename T, class IndexT>
typedef COpInterface<CROpRoot<T,IndexT>> OI; class CROpRoot : public COpInterface<CROpRoot<T,IndexT>>
{
public:
typedef COpInterface<CROpRoot<T,IndexT>> OI;
constexpr CROpRoot() = default; constexpr CROpRoot() = default;
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const; constexpr decltype(auto) operator()(const PosT& pos) const;
constexpr decltype(auto) operator()() const; constexpr decltype(auto) operator()() const;
template <SizeT I> template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const; constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
private: private:
const T* mData; const T* mData;
COpRoot COpRoot
}; };
template <typename T, class IndexT> template <typename T, class IndexT>
class ROpRoot : public OpInterface<ROpRoot<T,IndexT>> class ROpRoot : public OpInterface<ROpRoot<T,IndexT>>
{ {
public: public:
typedef OpInterface<ROpRoot<T,IndexT>> OI; typedef OpInterface<ROpRoot<T,IndexT>> OI;
constexpr ROpRoot() = default; constexpr ROpRoot() = default;
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const; constexpr decltype(auto) operator()(const PosT& pos) const;
constexpr decltype(auto) operator()() const; constexpr decltype(auto) operator()() const;
template <SizeT I> template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const; constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
private: private:
}; };
template <class CXpr> template <class CXpr>
class RContraction : public OpInterfacte<RContraction<CXpr>> class RContraction : public OpInterfacte<RContraction<CXpr>>
{ {
public: public:
typedef OpInterfacte<RContraction<CXpr>> OI; typedef OpInterfacte<RContraction<CXpr>> OI;
constexpr RContraction() = default; constexpr RContraction() = default;
constexpr RContraction(CXpr&& cxpr); constexpr RContraction(CXpr&& cxpr);
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const; constexpr decltype(auto) operator()(const PosT& pos) const;
constexpr decltype(auto) operator()() const; constexpr decltype(auto) operator()() const;
template <SizeT I> template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const; constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
private: private:
CXpr mCXpr; CXpr mCXpr;
}; };
} } // namespace mpi
} // namespace CNORXZ
#endif #endif

View file

@ -56,9 +56,9 @@ namespace CNORXZ
template <class IndexI, class IndexK> template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator=(SizeT pos) RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator=(SizeT pos)
{ {
IB::mPos = pos; // = lex mLex = pos; // = lex
if(pos >= lmax().val()){ if(mLex >= lmax().val()){
IB::mPos = pmax().val(); mLex = lmax().val();
return *this; return *this;
} }
// pos is the lexicographic position of the global range. // pos is the lexicographic position of the global range.
@ -72,7 +72,7 @@ namespace CNORXZ
if constexpr(has_static_sub<IndexI>::value){ if constexpr(has_static_sub<IndexI>::value){
constexpr SizeT NI = index_dim<IndexI>::value; constexpr SizeT NI = index_dim<IndexI>::value;
iter<0,NI>( [&](auto mu) { iter<0,NI>( [&](auto mu) {
const SizeT jmu = (IB::mPos / (ilf[mu].val()*klf[mu].val())) % const SizeT jmu = (mLex / (ilf[mu].val()*klf[mu].val())) %
(i[mu]->lmax().val() * k[mu]->lmax().val()); (i[mu]->lmax().val() * k[mu]->lmax().val());
r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val(); r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val();
l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val(); l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val();
@ -81,7 +81,7 @@ namespace CNORXZ
else if constexpr( has_static_sub<IndexK>::value){ else if constexpr( has_static_sub<IndexK>::value){
constexpr SizeT NI = index_dim<IndexK>::value; constexpr SizeT NI = index_dim<IndexK>::value;
iter<0,NI>( [&](auto mu) { iter<0,NI>( [&](auto mu) {
const SizeT jmu = (IB::mPos / (ilf[mu].val()*klf[mu].val())) % const SizeT jmu = (mLex / (ilf[mu].val()*klf[mu].val())) %
(i[mu]->lmax().val() * k[mu]->lmax().val()); (i[mu]->lmax().val() * k[mu]->lmax().val());
r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val(); r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val();
l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val(); l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val();
@ -90,7 +90,7 @@ namespace CNORXZ
else { else {
const SizeT NI = mI->dim(); const SizeT NI = mI->dim();
for(SizeT mu = 0; mu != NI; ++mu){ for(SizeT mu = 0; mu != NI; ++mu){
const SizeT jmu = (IB::mPos / (ilf[mu].val()*klf[mu].val())) % const SizeT jmu = (mLex / (ilf[mu].val()*klf[mu].val())) %
(i[mu]->lmax().val() * k[mu]->lmax().val()); (i[mu]->lmax().val() * k[mu]->lmax().val());
r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val(); r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val();
l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val(); l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val();
@ -98,6 +98,7 @@ namespace CNORXZ
} }
*mI = l; *mI = l;
*mK = r; *mK = r;
IB::mPos = mK->pos() * mI->pmax().val() + mI->pos();
return *this; return *this;
} }
@ -152,13 +153,13 @@ namespace CNORXZ
template <class IndexI, class IndexK> template <class IndexI, class IndexK>
SizeT RIndex<IndexI,IndexK>::lex() const SizeT RIndex<IndexI,IndexK>::lex() const
{ {
return IB::mPos; return mLex;
} }
template <class IndexI, class IndexK> template <class IndexI, class IndexK>
constexpr decltype(auto) RIndex<IndexI,IndexK>::pmax() const constexpr decltype(auto) RIndex<IndexI,IndexK>::pmax() const
{ {
return UPos(mK->lmax().val() * mI->lmax().val()); return UPos(mK->pmax().val() * mI->pmax().val());
} }
template <class IndexI, class IndexK> template <class IndexI, class IndexK>
@ -302,11 +303,11 @@ namespace CNORXZ
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator()() RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator()()
{ {
if(mI->lex() >= mI->lmax().val()){ if(mI->lex() >= mI->lmax().val()){
IB::mPos = lmax().val(); mLex = lmax().val();
} }
if constexpr(has_static_sub<IndexI>::value){ if constexpr(has_static_sub<IndexI>::value){
constexpr SizeT NI = index_dim<IndexI>::value; constexpr SizeT NI = index_dim<IndexI>::value;
IB::mPos = iter<0,NI> mLex = iter<0,NI>
([&](auto i) { ([&](auto i) {
return mK->pack()[i]->lex() * mK->lexFormat()[i].val() * return mK->pack()[i]->lex() * mK->lexFormat()[i].val() *
mI->lexFormat()[i].val() * mI->pack()[i]->lmax().val() + mI->lexFormat()[i].val() * mI->pack()[i]->lmax().val() +
@ -316,7 +317,7 @@ namespace CNORXZ
} }
else if constexpr( has_static_sub<IndexK>::value){ else if constexpr( has_static_sub<IndexK>::value){
constexpr SizeT NI = index_dim<IndexK>::value; constexpr SizeT NI = index_dim<IndexK>::value;
IB::mPos = iter<0,NI> mLex = iter<0,NI>
([&](auto i) { ([&](auto i) {
return mK->pack()[i]->lex() * mK->lexFormat()[i].val() * return mK->pack()[i]->lex() * mK->lexFormat()[i].val() *
mI->lexFormat()[i].val() * mI->pack()[i]->lmax().val() + mI->lexFormat()[i].val() * mI->pack()[i]->lmax().val() +
@ -326,14 +327,15 @@ namespace CNORXZ
} }
else { else {
const SizeT NI = mI->dim(); const SizeT NI = mI->dim();
IB::mPos = 0; mLex = 0;
for(SizeT i = 0; i != NI; ++i){ for(SizeT i = 0; i != NI; ++i){
IB::mPos += mK->pack()[i]->lex() * mK->lexFormat()[i].val() * mLex += mK->pack()[i]->lex() * mK->lexFormat()[i].val() *
mI->lexFormat()[i].val() * mI->pack()[i]->lmax().val() + mI->lexFormat()[i].val() * mI->pack()[i]->lmax().val() +
mI->pack()[i]->lex() * mI->lexFormat()[i].val() * mI->pack()[i]->lex() * mI->lexFormat()[i].val() *
mK->lexFormat()[i].val(); mK->lexFormat()[i].val();
} }
} }
IB::mPos = mK->pos() * mI->pmax().val() + mI->pos();
return *this; return *this;
} }

View file

@ -146,6 +146,7 @@ namespace CNORXZ
Sptr<IndexI> local() const; Sptr<IndexI> local() const;
private: private:
SizeT mLex = 0;
Sptr<RangeType> mRange; /**< RRange. */ Sptr<RangeType> mRange; /**< RRange. */
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. */