diff --git a/src/opt/mpi/include/raindex.h b/src/opt/mpi/include/raindex.h index 2992c0d..737662d 100644 --- a/src/opt/mpi/include/raindex.h +++ b/src/opt/mpi/include/raindex.h @@ -24,181 +24,23 @@ namespace CNORXZ @tparam T data type. */ template - class RAIndex : public IndexInterface>> + class RAIndex : public RIndex { public: - typedef IndexInterface>> IB; - typedef MRange RangeType; - typedef Tuple> MetaType; + typedef typename RIndex::IB IB; - INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType); + DEFAULT_MEMBERS(RAIndex); + RAIndex(const T* loc, const RangePtr& range, SizeT lexpos = 0); + RAIndex(const T* loc, const RIndex& i); + RAIndex(const T* loc, const RAIndex& i); - /** Default constructor. */ - RAIndex() = default; - - /** Move constructor. */ - RAIndex(RAIndex&& i) = default; - - /** Move assignment. */ - RAIndex& operator=(RAIndex&& i) = default; - - /** Copy constructor. - No default copy: Have to copy sub-index instances - */ - RAIndex(const RAIndex& i); - - /** Copy assigment. - No default copy: Have to copy sub-index instances - */ - RAIndex& operator=(const RAIndex& i); - - /** Construct from sub-index pointers. - @param is Vector of XIndex pointers. - @param geom Rank geometry. - */ - RAIndex(const Vector& is, const Vector& geom); - - /** Construct from sub-index pointers, specify index format. - @param bs Index format (YFormat). - @param is Vector of XIndex pointers. - @param geom Rank geometry. - */ - RAIndex(const YFormat& bs, const Vector& is, const Vector& geom); - - /** Construct from a range and an initial lexicographic position - @param range Range to iterate over. - @param geom Rank geometry. - @param lexpos Initial lexicographic position. - */ - RAIndex(const RangePtr& range, const Vector& geom, SizeT lexpos = 0); - - /** Construct from a range and an initial lexicographic position, specify format. - @param range Range to iterate over. - @param bs Index format. - @param geom Rank geometry. - @param lexpos Initial lexicographic position. - */ - RAIndex(const RangePtr& range, const YFormat& bs, const Vector& geom, SizeT lexpos = 0); - - /** @copydoc IndexInterface::operator=(SizeT) */ - RAIndex& operator=(SizeT lexpos); - - /** @copydoc IndexInterface::operator++() */ - RAIndex& operator++(); - - /** @copydoc IndexInterface::operator--() */ - RAIndex& operator--(); - - /** @copydoc IndexInterface::operator+() */ RAIndex operator+(Int n) const; - - /** @copydoc IndexInterface::operator-() */ RAIndex operator-(Int n) const; - /** @copydoc IndexInterface::operator-(CIndex) */ - SizeT operator-(const RAIndex& i) const; - - /** @copydoc IndexInterface::operator+=() */ - RAIndex& operator+=(Int n); - - /** @copydoc IndexInterface::operator-=() */ - RAIndex& operator-=(Int n); - - /** @copydoc IndexInterface::lex() */ - SizeT lex() const; - - /** @copydoc IndexInterface::pmax() */ - UPos pmax() const; - - /** @copydoc IndexInterface::lmax() */ - UPos lmax() const; - - /** @copydoc IndexInterface::id() */ - IndexId<0> id() const; - const T& operator*() const; - - const T* operator->() const; - - /** @copydoc IndexInterface::dim() */ - SizeT dim() const; - - /** @copydoc IndexInterface::range() */ - Sptr range() const; - - /** @copydoc IndexInterface::stepSize() */ - UPos stepSize(const IndexId<0> id) const; - - /** @copydoc IndexInterface::stringMeta() */ - String stringMeta() const; - - /** @copydoc IndexInterface::meta() */ - Vector meta() const; - - /** @copydoc IndexInterface::at() */ - RAIndex& at(const Vector& meta); - - /** @copydoc IndexInterface::prange() */ - RangePtr prange(const RAIndex& last) const; - - /** @copydoc IndexInterface::deepFormat() */ - Vector deepFormat() const; - - /** @copydoc IndexInterface::deepMax() */ - Vector deepMax() const; - - /** @copydoc IndexInterface::reformat() */ - RAIndex& reformat(const Vector& f, const Vector& s); - - /** @copydoc IndexInterface::ifor() */ - DXpr ifor(const DXpr& xpr, NoF&& f) const; - - /** @copydoc IndexInterface::formatIsTrivial() */ - bool formatIsTrivial() const; - - /** Replace sub-index instances. - All linearized positions are updated accordingly. - @param i DPack which provides the new sub-index instance - */ - RAIndex& operator()(const DPack& i); - - /** Update all linearized positions. */ - RAIndex& operator()(); - - /** Get all sub-indices - @return Pack of sub-indices - */ - const DPack& pack() const; - - /** Get index format. - @return The format. - */ - const YFormat& format() const; - - /** Get lexicographic (trivial) index format. - @return The lexicographic format. - */ - const YFormat& lexFormat() const; - - /** Set the index format. - @param bs The new format. - */ - RAIndex& setFormat(const YFormat& bs); - - /** Set position of given sub index and update total index position. - @param ind Sub-index number [0,dim()-1]. - @param lex Lexicographic position to be assigned to the index. - */ - RAIndex& setSub(SizeT ind, SizeT lex); - + const T& operator->() const; + private: - Sptr mRange; - MIndex mI; - MFormat<2> mFormat; - MFormat<2> mLexFormat; - SizeT mLex = 0; - UPos mPMax = 0; - UPos mLMax = 0; const T* mLoc = nullptr; Vector mBuf; // used if iterating over content on different rank }; diff --git a/src/opt/mpi/include/rarray.cc.h b/src/opt/mpi/include/rarray.cc.h new file mode 100644 index 0000000..d6dc04c --- /dev/null +++ b/src/opt/mpi/include/rarray.cc.h @@ -0,0 +1,152 @@ +// -*- C++ -*- +/** + + @file opt/mpi/include/rarray.cc.h + @brief RArray template implementations. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + +**/ + +#ifndef __cxz_mpi_rarray_cc_h__ +#define __cxz_mpi_rarray_cc_h__ + +namespace CNORXZ +{ + namespace mpi + { + + template + RCArray::RCArray(const Sptr> a, const RangePtr& geom) : + mA(a), + mGeom(geom) + {} + + template + template + T RCArray::operator[](const IndexInterface& i) const + { + if constexpr(is_rank_index::value){ + return *(begin() + i.lex()); + } + else { + return (*mA)[i]; + } + } + + template + template + T RCArray::at(const IndexInterface& i) const + { + if constexpr(is_rank_index::value){ + CXZ_ASSERT(i.rank() == getNumRanks(), "rank number out of scope"); + // consistency checks!!! + return *(begin() + i.lex()); + } + else { + return mA->at(i); + } + } + + template + template + T RCArray::operator[](const SPack& pack) const + { + } + + template + template + T RCArray::at(const SPack& pack) const + { + } + + template + T RCArray::operator[](const DPack& pack) const + { + } + + template + T RCArray::at(const DPack& pack) const + { + } + + template + template + Sptr> RCArray::sl(const IndexInterface& begin, + const IndexInterface& end) const + { + } + + template + template + COpRoot RCArray::operator()(const Sptr& i) const + { + } + + template + template + inline decltype(auto) RCArray::operator()(const SPack& pack) const + { + } + + template + inline decltype(auto) RCArray::operator()(const DPack& pack) const + { + } + + template + const T* RCArray::data() const + { + return mA->data(); + } + + template + SizeT RCArray::size() const + { + return mA->size() * mGeom->size(); + } + + template + RangePtr RCArray::range() const + { + return RRangeFactory(mA->range(),mGeom).create(); + } + + template + const_iterator RCArray::begin() const + { + } + + template + const_iterator RCArray::end() const + { + } + + template + const_iterator RCArray::cbegin() const + { + } + + template + const_iterator RCArray::cend() const + { + } + + template + bool RCArray::isView() const + { + return mA->isView(); + } + + template + const CArrayBase& RCArray::local() const + { + return *mA; + } + + + } // namespace mpi +} // namespace CNORXZ + +#endif diff --git a/src/opt/mpi/include/rarray.h b/src/opt/mpi/include/rarray.h index 4f743bb..70ca945 100644 --- a/src/opt/mpi/include/rarray.h +++ b/src/opt/mpi/include/rarray.h @@ -16,35 +16,123 @@ namespace CNORXZ { - /** **** - Multi-dimensional multi-rank array. - @tparam T data type. - */ - template - class RArray : public ArrayBase + namespace mpi { - public: - typedef CArrayBase AB; - typedef typename RAIndex const_iterator; + /** **** + Wrapper for cnorxz array types for handling MPI ranks. + @tparam T data type. + */ + template + class RCArray + { + public: + typedef RAIndex const_iterator; - using CArrayBase::operator[]; - using ArrayBase::operator[]; + DEFAULT_MEMBERS(RCArray); + + /** Construct from local array object. + @param a Local array. + @param geom Rank geometry. + */ + RCArray(const Sptr> a, const RangePtr& geom); - DEFAULT_MEMBERS(RArray); + /** @copydoc CArrayBase::operator[] */ + template + T operator[](const IndexInterface& i) const; + + /** @copydoc CArrayBase::at() + Return copy instead of reference. + */ + template + T at(const IndexInterface& i) const; + + /** @copydoc CArrayBase::operator[] */ + template + T operator[](const SPack& pack) const; + + /** @copydoc CArrayBase::at() */ + template + T at(const SPack& pack) const; + + /** @copydoc CArrayBase::operator[] */ + T operator[](const DPack& pack) const; + + /** @copydoc CArrayBase::at() */ + T at(const DPack& pack) const; + + /** @copydoc CArrayBase::sl() */ + template + Sptr> sl(const IndexInterface& begin, + const IndexInterface& end) const; + + /** @copydoc CArrayBase::operator() */ + template + COpRoot operator()(const Sptr& i) const; + + /** @copydoc CArrayBase::operator() */ + template + inline decltype(auto) operator()(const SPack& pack) const; + + /** @copydoc CArrayBase::operator() */ + inline decltype(auto) operator()(const DPack& pack) const; + + /** @copydoc CArrayBase::data() */ + const T* data() const; + + /** @copydoc CArrayBase::size() */ + SizeT size() const; + + /** @copydoc CArrayBase:range() */ + RangePtr range() const; + + /** @copydoc CArrayBase::begin() */ + const_iterator begin() const; + + /** @copydoc CArrayBase::end() */ + const_iterator end() const; + + /** @copydoc CArrayBase::cbegin() */ + const_iterator cbegin() const; + + /** @copydoc CArrayBase::cend() */ + const_iterator cend() const; + + /** @copydoc CArrayBase::isView() */ + bool isView() const; + + /** Get local array object. */ + const CArrayBase& local() const; - virtual const T* data() const override; - virtual T* data() override; - virtual const_iterator cbegin() const override; - virtual const_iterator cend() const override; - virtual bool isView() const override; + private: + ObjHandle> mA; + RangePtr mGeom; + }; - protected: - virtual bool formatIsTrivial() const override final; + /** **** + Wrapper for cnorxz array types for handling MPI ranks. + @tparam T data type. + */ + template + class RArray : public RCArray + { + public: + typedef RCArray RCA; - private: - Vector mCont; - RangePtr mRRange; - }; -} + using RCA::operator[]; + using RCA::operator(); + using RCA::at; + using RCA::data; + using RCA::begin; + using RCA::end; + using RCA::cbegin; + using RCA::cend; + using RCA::sl; + + DEFAULT_MEMBERS(RArray); + + + }; + } // namespace mpi +} // namespace CNORXZ #endif diff --git a/src/opt/mpi/include/rrange.h b/src/opt/mpi/include/rrange.h index 522111c..a95d192 100644 --- a/src/opt/mpi/include/rrange.h +++ b/src/opt/mpi/include/rrange.h @@ -141,16 +141,25 @@ namespace CNORXZ /** Get the local index on THIS rank. */ Sptr local() const; - //!!! private: Sptr mRange; /**< RRange. */ Sptr mI; /**< Index on the local range of the THIS rank. */ Sptr mK; /**< Multi-index indicating the current rank. */ - //!!! }; // Traits!!! + template + struct is_rank_index + { + constexpr bool value = false; + }; + + template + struct is_rank_index + { + constexpr bool value = true; + }; /** **** Specific factory for RRange.