diff --git a/src/include/base/obj_handle.cc.h b/src/include/base/obj_handle.cc.h index 1d11ee9..8288de4 100644 --- a/src/include/base/obj_handle.cc.h +++ b/src/include/base/obj_handle.cc.h @@ -69,6 +69,18 @@ namespace CNORXZ return &*mC; } + template + T* ObjHandle::get() + { + return &*mC; + } + + template + const T* ObjHandle::get() const + { + return &*mC; + } + } #endif diff --git a/src/include/base/obj_handle.h b/src/include/base/obj_handle.h index 02b2b19..ada4e2f 100644 --- a/src/include/base/obj_handle.h +++ b/src/include/base/obj_handle.h @@ -77,6 +77,12 @@ namespace CNORXZ /** get pointer to data (const) */ const T* operator->() const; + + /** get object. */ + T* get(); + + /** get object. */ + const T* get() const; }; } diff --git a/src/opt/mpi/include/rarray.cc.h b/src/opt/mpi/include/rarray.cc.h index e94c6e5..054837e 100644 --- a/src/opt/mpi/include/rarray.cc.h +++ b/src/opt/mpi/include/rarray.cc.h @@ -21,6 +21,10 @@ namespace CNORXZ namespace mpi { + /*===============+ + | RCArray | + +===============*/ + template RCArray::RCArray(const RCArray& a) : mA(a.mA->copy()), @@ -43,6 +47,14 @@ namespace CNORXZ mGlobal(RRangeFactory(rangeCast(a.range()),rangeCast(mGeom)).create()) {} + template + template + RCArray::RCArray(const RRange& range) : + mA(std::make_unique(range->local())), + mGeom(range->geom()), + mGlobal(range) + {} + template template T RCArray::operator[](const IndexInterface& i) const @@ -241,11 +253,146 @@ namespace CNORXZ Sptr> RCArray::load(const Sptr& i, const F& f) const { Sptr> imap = std::make_shared>(); - + CXZ_ERROR("!!!"); //load(i, /**/, imap); return imap; } + /*===============+ + | RCArray | + +===============*/ + + template + RArray::RArray(const RArray& a) : + RCArray(a), + mB(dynamic_cast*>(RCA::mA.get())) + {} + + template + RArray& RArray::operator=(const RArray& a) + { + RCArray::operator=(a); + mB = dynamic_cast*>(RCA::mA.get()); + return *this; + } + + template + template + RArray::RArray(const RRange& range) : + RCArray(range), + mB(dynamic_cast*>(RCA::mA.get())) + {} + + template + RArray::RArray(const ArrayBase& a, const RangePtr& geom) : + RCArray(a, geom), + mB(dynamic_cast*>(RCA::mA.get())) + {} + + template + template + RArray& RArray::set(const IndexInterface& i, const T& val) + { + auto it = begin() + i.lex(); + it.set(val); + return *this; + } + + template + template + RArray& RArray::set(const SPack& pack, const T& val) + { + auto it = begin() + pack.lex(); + it.set(val); + return *this; + } + + template + RArray& RArray::set(const DPack& pack, const T& val) + { + auto it = begin() + pack.lex(); + it.set(val); + return *this; + } + + template + template + Sptr> RArray::sl(const IndexInterface& begin, + const IndexInterface& end) + { + if constexpr(is_rank_index::value){ + CXZ_ERROR("not implemented"); + return nullptr; + } + else { + return mB->sl(begin, end); + } + } + + template + template + OpRoot RArray::operator()(const Sptr& i) + { + CXZ_ERROR("not implemented"); + return OpRoot(); + } + + template + template + inline decltype(auto) RArray::operator()(const SPack& pack) + { + typedef typename std::remove_reference{}])>::type I0; + if constexpr(is_rank_index::value){ + // preliminary: + CXZ_ASSERT(this->formatIsTrivial(), + "array has non-trivial format, rank operations require trivial format"); + auto ri = pack[CSizeT<0>{}]; + auto li = iter<1,sizeof...(Indices)> + ( [&](auto i) { return pack[CSizeT{}]; }, + [](const auto&... x) { return mindexPtr( (x * ...) ); } ); + return croproot(*this, ri, li); + } + else { + return (*mB)(pack); + } + } + + template + inline decltype(auto) RArray::operator()(const DPack& pack) + { + // TODO: assert that none of the indices is rank index + return (*mB)(pack); + } + + template + T* RArray::data() + { + return mB->data(); + } + + template + typename RArray::iterator RArray::begin() + { + return iterator(mB->data(), RCA::mGlobal); + } + + template + typename RArray::iterator RArray::end() + { + return iterator(mB->data(), RCA::mGlobal, RCA::mGlobal->size()); + } + + template + ArrayBase& RArray::local() + { + return *mB; + } + + + /*============================+ + | non-member functions | + +============================*/ + template void setupBuffer(const Sptr>& rgi, const Sptr>& rgj, const Sptr>& imap, const CArrayBase& data, diff --git a/src/opt/mpi/include/rarray.h b/src/opt/mpi/include/rarray.h index 0ec4451..62c9cd3 100644 --- a/src/opt/mpi/include/rarray.h +++ b/src/opt/mpi/include/rarray.h @@ -33,6 +33,12 @@ namespace CNORXZ DEFAULT_MOVE(RCArray); RCArray(const RCArray& a); RCArray& operator=(const RCArray& a); + + /** Construct from a rank range. + @param range The range. + */ + template + RCArray(const RRange& range); /** Construct from local array object. @param a Local array. @@ -153,6 +159,8 @@ namespace CNORXZ { public: typedef RCArray RCA; + typedef typename RCA::const_iterator const_iterator; + typedef RBIndex iterator; using RCA::operator[]; using RCA::operator(); @@ -164,9 +172,74 @@ namespace CNORXZ using RCA::cend; using RCA::sl; - DEFAULT_MEMBERS(RArray); + DEFAULT_C(RArray); + DEFAULT_MOVE(RArray); + RArray(const RArray& a); + RArray& operator=(const RArray& a); + + /** Construct from a rank range. + @param range The range. + */ + template + RArray(const RRange& range); + + /** Construct from local array object. + @param a Local array. + @param geom Rank geometry. + */ + RArray(const ArrayBase& a, const RangePtr& geom); + + /** Assign value at a position indicated by an index. + @param i Index indicating the position. + @param val Value. + */ + template + RArray& set(const IndexInterface& i, const T& val); + + /** Assign value at a position indicated by an index pack. + @param pack Index pack indicating the position. + @param val Value. + */ + template + RArray& set(const SPack& pack, const T& val); + + /** Assign value at a position indicated by an index pack. + @param pack Index pack indicating the position. + @param val Value. + */ + RArray& set(const DPack& pack, const T& val); + + /** @copydoc ArrayBase::sl() */ + template + Sptr> sl(const IndexInterface& begin, + const IndexInterface& end); + + /** @copydoc ArrayBase::operator() */ + template + OpRoot operator()(const Sptr& i); + + /** @copydoc ArrayBase::operator() */ + template + inline decltype(auto) operator()(const SPack& pack); + + /** @copydoc ArrayBase::operator() */ + inline decltype(auto) operator()(const DPack& pack); + + /** @copydoc ArrayBase::data() */ + T* data(); + + /** @copydoc ArrayBase::begin() */ + iterator begin(); + + /** @copydoc ArrayBase::end() */ + iterator end(); + + /** Get local array object. */ + ArrayBase& local(); + + private: + ArrayBase* mB = nullptr; - }; template