From df2b6892d9d903ade466eac1b04dbfac907ca846 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 22 Oct 2024 13:58:13 -0700 Subject: [PATCH] pos_type: auto -> decltype(auto) + rop_types: handle local index offsets --- src/include/xpr/pos_type.cc.h | 8 ++++---- src/include/xpr/pos_type.h | 8 ++++---- src/opt/mpi/include/rop_types.cc.h | 33 +++++++++++++++++++++++++----- src/opt/mpi/include/rop_types.h | 2 ++ 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/include/xpr/pos_type.cc.h b/src/include/xpr/pos_type.cc.h index 1f051e3..21fada7 100644 --- a/src/include/xpr/pos_type.cc.h +++ b/src/include/xpr/pos_type.cc.h @@ -151,7 +151,7 @@ namespace CNORXZ } template - constexpr UPos UPos::operator-(const PosT& in) const + constexpr decltype(auto) UPos::operator-(const PosT& in) const { return UPos(mExt - in.val()); } @@ -458,7 +458,7 @@ namespace CNORXZ template template - constexpr auto MPos::operator+(const PosT& a) const + constexpr decltype(auto) MPos::operator+(const PosT& a) const { typedef decltype(BPosT::operator+(a)) OBPosT; typedef decltype(mNext + a.next()) ONPosT; @@ -467,7 +467,7 @@ namespace CNORXZ template template - constexpr auto MPos::operator*(const PosT& a) const + constexpr decltype(auto) MPos::operator*(const PosT& a) const { typedef decltype(BPosT::operator*(a)) OBPosT; typedef decltype(mNext * a) ONPosT; @@ -476,7 +476,7 @@ namespace CNORXZ template template - constexpr auto MPos::operator()(const PosT& a) const + constexpr decltype(auto) MPos::operator()(const PosT& a) const { typedef decltype(BPosT::operator()(a)) OBPosT; typedef decltype(mNext(a)) ONPosT; diff --git a/src/include/xpr/pos_type.h b/src/include/xpr/pos_type.h index a0a71ad..6879f4f 100644 --- a/src/include/xpr/pos_type.h +++ b/src/include/xpr/pos_type.h @@ -66,7 +66,7 @@ namespace CNORXZ constexpr decltype(auto) operator+(const PosT& a) const; template - constexpr UPos operator-(const PosT& a) const; + constexpr decltype(auto) operator-(const PosT& a) const; //constexpr SPos<0> operator*(const SPos<0>& a) const; @@ -179,14 +179,14 @@ namespace CNORXZ constexpr const NPosT& next() const; template - constexpr auto operator+(const PosT& a) const; + constexpr decltype(auto) operator+(const PosT& a) const; template - constexpr auto operator*(const PosT& a) const; + constexpr decltype(auto) operator*(const PosT& a) const; // same as operator*, except for FPos/SFPos, where map is executed template - constexpr auto operator()(const PosT& a) const; + constexpr decltype(auto) operator()(const PosT& a) const; template constexpr decltype(auto) extend(const PosT& a) const; diff --git a/src/opt/mpi/include/rop_types.cc.h b/src/opt/mpi/include/rop_types.cc.h index 56010cb..2ad301a 100644 --- a/src/opt/mpi/include/rop_types.cc.h +++ b/src/opt/mpi/include/rop_types.cc.h @@ -18,7 +18,8 @@ namespace CNORXZ const Sptr& li) : mData(a.buffermap().data()), mRIndex(ri), - mIndex(li) + mIndex(li), + mLOff(mIndex->pos()) { CXZ_ASSERT(a.buffermap().size() == ri->lmax().val(), "data map not properly initialized: map size = " << a.buffermap().size() @@ -32,14 +33,21 @@ namespace CNORXZ //CXZ_ASSERT(pos.val() < mRIndex->pmax().val(), pos.val() << ">=" << mRIndex->pmax().val()); //CXZ_ASSERT(mData[pos.val()] != nullptr, "data[" << pos.val() << "] == null"); //CXZ_ASSERT(pos.next().val() < mIndex->pmax().val(), pos.val() << ">=" << mIndex->pmax().val()); - return (mData[pos.val()])[pos.next().val()]; + if constexpr(is_epos_type::value){ + // PRELIMINARY!!! + // discards potential vector entries in pos (only pos.next() is considered)!!! + return vreg(mData[pos.val()[0]]+mLOff,pos.next()); + } + else { + return (mData[pos.val()])[mLOff+pos.next().val()]; + } } template constexpr decltype(auto) CROpRoot::operator()() const { //CXZ_ASSERT(mData[0] != nullptr, "data[" << 0 << "] == null"); - return (mData[0])[0]; + return (mData[0])[mLOff]; } template @@ -66,7 +74,8 @@ namespace CNORXZ mLocal(&a.local()), mData(a.buffermap().data()), mRIndex(ri), - mIndex(li) + mIndex(li), + mLOff(mIndex->pos()) { CXZ_ASSERT(a.buffermap().size() == ri->lmax().val(), "data map not properly initialized: map size = " << a.buffermap().size() @@ -106,7 +115,21 @@ namespace CNORXZ //CXZ_ASSERT(pos.val() < mRIndex->pmax().val(), pos.val() << ">=" << mRIndex->pmax().val()); //CXZ_ASSERT(mData[pos.val()] != nullptr, "data[" << pos.val() << "] == null"); //CXZ_ASSERT(pos.next().val() < mIndex->pmax().val(), pos.val() << ">=" << mIndex->pmax().val()); - return (mData[pos.val()])[pos.next().val()]; + if constexpr(is_epos_type::value){ + // PRELIMINARY!!! + // discards potential vector entries in pos (only pos.next() is considered)!!! + if constexpr(pos_type_is_consecutive::value){ + return vreg(mData[pos.val()[0]]+mLOff,pos.next()); + } + else { + // non-consecutive data cannot be directly accessed + // so there is no non-const (write) access! + return vreg(const_cast(mData[pos.val()[0]]+mLOff),pos.next()); + } + } + else { + return (mData[pos.val()])[mLOff+pos.next().val()]; + } } template diff --git a/src/opt/mpi/include/rop_types.h b/src/opt/mpi/include/rop_types.h index 2c44259..0437d7a 100644 --- a/src/opt/mpi/include/rop_types.h +++ b/src/opt/mpi/include/rop_types.h @@ -41,6 +41,7 @@ namespace CNORXZ const T* const* mData; Sptr mRIndex; Sptr mIndex; + SizeT mLOff; // local index offset (position) }; @@ -80,6 +81,7 @@ namespace CNORXZ const T* const* mData; Sptr mRIndex; Sptr mIndex; + SizeT mLOff; // local index offset (position) }; template