diff --git a/src/opt/mpi/include/rrange.cc.h b/src/opt/mpi/include/rrange.cc.h new file mode 100644 index 0000000..d3152fa --- /dev/null +++ b/src/opt/mpi/include/rrange.cc.h @@ -0,0 +1,243 @@ +// -*- C++ -*- +/** + + @file opt/mpi/include/rrange.cc.h + @brief RRange and RIndex declaration. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + +**/ + +#ifndef __cxz_mpi_rrange_cc_h__ +#define __cxz_mpi_rrange_cc_h__ + +#include "rrange.h" + +namespace CNORXZ +{ + namespace mpi + { + + template + RIndex::RIndex(const RIndex& in) : + mRange(in.mRange), + mI(std::make_shared(mRange->local())), + mK(std::make_shared(mRange->geom())) + { + *this = in.lex(); + } + + template + RIndex& RIndex::operator=(const RIndex& in) + { + mRange = in.mRange; + mI = std::make_shared(mRange->local()); + mK = std::make_shared(mRange->geom()); + *this = in.lex(); + return *this; + } + + template + RIndex::RIndex(const RangePtr& global, SizeT lexpos = 0) : + mRange(rangeCast(global)), + mI(std::make_shared(mRange->local())), + mK(std::make_shared(mRange->geom())) + { + *this = lexpos; + } + + template + RIndex::RIndex(const Sptr& local) : + { + //!!! + } + + template + RIndex& RIndex::operator=(SizeT pos) + { + // pos is the lexicographic position of the global range. + // Hence, have to consider the rank geometry. + if constexpr(has_static_sub::value or has_static_sub::value){ + + } + else { + + } + return *this; + } + + template + RIndex& RIndex::operator++() + { + + return *this; + } + + template + RIndex& RIndex::operator--() + { + + return *this; + } + + template + RIndex RIndex::operator+(Int n) const + { + + } + + template + RIndex RIndex::operator-(Int n) const + { + + } + + template + SizeT RIndex::operator-(const RIndex& i) const + { + + } + + template + RIndex& RIndex::operator+=(Int n) + { + + return *this; + } + + template + RIndex& RIndex::operator-=(Int n) + { + + return *this; + } + + template + SizeT RIndex::lex() const + { + + } + + template + constexpr RIndex::decltype(auto) pmax() const + { + + } + + + template + constexpr RIndex::decltype(auto) lmax() const + { + + } + + template + IndexId<0> RIndex::id() const + { + + } + + template + MetaType RIndex::operator*() const + { + + } + + template + constexpr SizeT RIndex::dim() const + { + + } + + template + Sptr RIndex::range() const + { + + } + + template + template + decltype(auto) RIndex::stepSize(const IndexId& id) const + { + + } + + template + String RIndex::stringMeta() const + { + + } + + template + MetaType RIndex::meta() const + { + + } + + template + RIndex& RIndex::at(const MetaType& metaPos) + { + + } + + template + RangePtr RIndex::prange(const RIndex& last) const + { + + } + + template + auto RIndex::deepFormat() const + { + + } + + template + auto RIndex::deepMax() const + { + + } + + template + RIndex& RIndex::reformat(const Vector& f, const Vector& s) + { + + } + + template + template + constexpr decltype(auto) RIndex::ifor(const Xpr& xpr, F&& f) const + { + + } + + template + bool RIndex::formatIsTrivial() const + { + + } + + template + decltype(auto) RIndex::xpr(const Sptr>& _this) const + { + + } + + template + int RIndex::rank() const + { + + } + + template + Sptr RIndex::local() const + { + + } + + + } // namespace mpi +} // namespace CNORXZ + +#endif diff --git a/src/opt/mpi/include/rrange.h b/src/opt/mpi/include/rrange.h index df8c11e..7b0caf0 100644 --- a/src/opt/mpi/include/rrange.h +++ b/src/opt/mpi/include/rrange.h @@ -1,7 +1,7 @@ // -*- C++ -*- /** - @file opt/include/rrange.h + @file opt/mpi/include/rrange.h @brief RRange and RIndex declaration. Copyright (c) 2024 Christian Zimmermann. All rights reserved. @@ -16,179 +16,217 @@ namespace CNORXZ { - - /** **** - Specific index for RRange. - @tparam Index Local index type. - */ - template - class RIndex : public IndexInterface,typename Index::MetaType> + namespace mpi { - public: - typedef IndexInterface,typename Index::MetaType> IB; - typedef typename Index::MetaType MetaType; - typedef RRange RangeType; - INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType); + /** **** + Specific index for RRange. + Every call on an instance of this class has to be done on each rank. + @tparam IndexI Index type used to indicate local position. + @tparam IndexK Index type used to indicate the rank. + */ + template + class RIndex : public IndexInterface,typename Index::MetaType> + { + public: + typedef IndexInterface,typename Index::MetaType> IB; + typedef typename Index::MetaType MetaType; + typedef RRange RangeType; - // constructors!!! + INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType); + + // constructors!!! + /** Default constructor. */ + RIndex() = default; + + /** Move constructor (default). */ + RIndex(RIndex&& in) = default; + + /** Move assignment (default). */ + RIndex& operator=(RIndex&& in) = default; + + /** Copy constructor (no default, copy local index instance). */ + RIndex(const RIndex& in); + + /** Copy assignment (no default, copy local index instance). */ + RIndex& operator=(const RIndex& in); + + /** Construct from global range and format. + @param global Pointer to global range; this can be a RRange or the bare range (will be converted to a RRange). + @param lexpos Start position. + */ + RIndex(const RangePtr& global, SizeT lexpos = 0); + + /** Construct from local index. */ + RIndex(const Sptr& local); + + /** @copydoc IndexInterface::operator=(SizeT) */ + RIndex& operator=(SizeT pos); + + /** @copydoc IndexInterface::operator++() */ + RIndex& operator++(); + + /** @copydoc IndexInterface::operator--() */ + RIndex& operator--(); + + /** @copydoc IndexInterface::operator+() */ + RIndex operator+(Int n) const; + + /** @copydoc IndexInterface::operator-() */ + RIndex operator-(Int n) const; + + /** @copydoc IndexInterface::operator-(CIndex) */ + SizeT operator-(const RIndex& i) const; + + /** @copydoc IndexInterface::operator+=() */ + RIndex& operator+=(Int n); + + /** @copydoc IndexInterface::operator-=() */ + RIndex& operator-=(Int n); + + /** @copydoc IndexInterface::lex() */ + SizeT lex() const; + + /** @copydoc IndexInterface::pmax() */ + constexpr decltype(auto) pmax() const; + + /** @copydoc IndexInterface::lmax() */ + constexpr decltype(auto) lmax() const; + + /** @copydoc IndexInterface::id() */ + IndexId<0> id() const; + + /** @copydoc IndexInterface::operator*() */ + MetaType operator*() const; - /** @copydoc IndexInterface::operator=(SizeT) */ - RIndex& operator=(SizeT pos); + /** @copydoc IndexInterface::dim() */ + constexpr SizeT dim() const; - /** @copydoc IndexInterface::operator++() */ - RIndex& operator++(); + /** @copydoc IndexInterface::range() */ + Sptr range() const; - /** @copydoc IndexInterface::operator--() */ - RIndex& operator--(); + /** @copydoc IndexInterface::stepSize() */ + template + decltype(auto) stepSize(const IndexId& id) const; - /** @copydoc IndexInterface::operator+() */ - RIndex operator+(Int n) const; + /** @copydoc IndexInterface::stringMeta() */ + String stringMeta() const; - /** @copydoc IndexInterface::operator-() */ - RIndex operator-(Int n) const; + /** @copydoc IndexInterface::meta() */ + MetaType meta() const; - /** @copydoc IndexInterface::operator-(CIndex) */ - SizeT operator-(const RIndex& i) const; + /** @copydoc IndexInterface::at() */ + RIndex& at(const MetaType& metaPos); - /** @copydoc IndexInterface::operator+=() */ - RIndex& operator+=(Int n); + /** @copydoc IndexInterface::prange() */ + RangePtr prange(const RIndex& last) const; - /** @copydoc IndexInterface::operator-=() */ - RIndex& operator-=(Int n); + /** @copydoc IndexInterface::deepFormat() */ + auto deepFormat() const; - /** @copydoc IndexInterface::lex() */ - SizeT lex() const; + /** @copydoc IndexInterface::deepMax() */ + auto deepMax() const; - /** @copydoc IndexInterface::pmax() */ - constexpr decltype(auto) pmax() const; + /** @copydoc IndexInterface::reformat() */ + RIndex& reformat(const Vector& f, const Vector& s); - /** @copydoc IndexInterface::lmax() */ - constexpr decltype(auto) lmax() const; + /** @copydoc IndexInterface::ifor() */ + template + constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; - /** @copydoc IndexInterface::id() */ - IndexId<0> id() const; + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; - /** @copydoc IndexInterface::operator*() */ - MetaType operator*() const; + /** @copydoc IndexInterface::xpr() */ + decltype(auto) xpr(const Sptr>& _this) const; + + /** Get the current rank. */ + int rank() const; + + /** Get the local index on THIS rank. */ + Sptr local() const; + //!!! - /** @copydoc IndexInterface::dim() */ - constexpr SizeT dim() const; + private: + Sptr mRange; /**< RRange. */ + Sptr mJ; /**< Index on the local range of the THIS rank. */ + Sptr mK; /**< Multi-index indicating the current rank. */ + //!!! + }; - /** @copydoc IndexInterface::range() */ - Sptr range() const; + // Factory!!! - /** @copydoc IndexInterface::stepSize() */ - template - decltype(auto) stepSize(const IndexId& id) const; + /** **** + Range-Wrapper for ranges that are distributed on MPI ranks. + @tparam Range Local range type. + */ + template + class RRange : public RangeInterface> + { + public: + typedef RangeBase RB; + typedef RIndex IndexType; + typedef typename Range::MetaType MetaType; - /** @copydoc IndexInterface::stringMeta() */ - String stringMeta() const; + friend RRangeFactory; - /** @copydoc IndexInterface::meta() */ - MetaType meta() const; + virtual RangePtr sub(SizeT num) const override final; + virtual MArray sub() const override final; + virtual SizeT size() const override final; + virtual SizeT dim() const override final; + virtual String stringMeta(SizeT pos) const override final; + virtual const TypeInfo& type() const override final; + virtual const TypeInfo& metaType() const override final; + virtual RangePtr extend(const RangePtr& r) const override final; - /** @copydoc IndexInterface::at() */ - RIndex& at(const MetaType& metaPos); + /** Get local range. */ + Sptr local() const; - /** @copydoc IndexInterface::prange() */ - RangePtr prange(const RIndex& last) const; + /** Get range of the rank geometry. */ + Sptr geom() const; + + /** Get meta data for given lexicographic position. + @param pos Lexicographic position. + */ + const MetaType get(SizeT pos) const; - /** @copydoc IndexInterface::deepFormat() */ - auto deepFormat() const; + /** Get lexicographic position according to the given meta data value. + @param metaPos Meta data value. + */ + SizeT getMeta(const MetaType& metaPos) const; - /** @copydoc IndexInterface::deepMax() */ - auto deepMax() const; + /** Get rank from lexicographic meta data position. + @param pos Lexicographic meta data position. + */ + int getRank(SizeT pos) const; - /** @copydoc IndexInterface::reformat() */ - RIndex& reformat(const Vector& f, const Vector& s); + protected: - /** @copydoc IndexInterface::ifor() */ - template - constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; + /** Dafault constructor */ + RRange() = default; - /** @copydoc IndexInterface::formatIsTrivial() */ - bool formatIsTrivial() const; + RRange(const RRange& in) = delete; + RRange& operator=(const RRange& in) = delete; - /** @copydoc IndexInterface::xpr() */ - decltype(auto) xpr(const Sptr>& _this) const; - - //!!! + /** Construct from local range and geometry. + @param loc Local range. + @param geom Rank geometry range. + */ + RRange(const Sptr& loc, const Sptr& geom); - private: - Sptr mRange; - Sptr mLocalI; - //!!! - }; - - // Factory!!! - - /** **** - Range-Wrapper for ranges that are distributed on MPI ranks. - @tparam Range Local range type. - */ - template - class RRange : public RangeInterface> - { - public: - typedef RangeBase RB; - typedef RIndex IndexType; - typedef typename Range::MetaType MetaType; - - friend RRangeFactory; - - virtual RangePtr sub(SizeT num) const override final; - virtual MArray sub() const override final; - virtual SizeT size() const override final; - virtual SizeT dim() const override final; - virtual String stringMeta(SizeT pos) const override final; - virtual const TypeInfo& type() const override final; - virtual const TypeInfo& metaType() const override final; - virtual RangePtr extend(const RangePtr& r) const override final; - - /** Get local range. */ - Sptr local() const; + Sptr mLocal; /**< Local range of THIS rank. */ + Sptr mGeom; /**< Rank geometry range. */ - /** Get meta data for given lexicographic position. - @param pos Lexicographic position. - */ - const MetaType get(SizeT pos) const; + }; - /** Get lexicographic position according to the given meta data value. - @param metaPos Meta data value. - */ - SizeT getMeta(const MetaType& metaPos) const; - - /** Get rank from lexicographic meta data position. - @param pos Lexicographic meta data position. - */ - int getRank(SizeT pos) const; - - protected: - - /** Dafault constructor */ - RRange() = default; - - RRange(const RRange& in) = delete; - RRange& operator=(const RRange& in) = delete; - - /** Construct from local range and geometry. - @param loc Local range. - @param geom Rank geometry range. - */ - RRange(const Sptr& loc, const Sptr& geom); + /** Create RRange from global range and given rank geometry. + @param global Global range. + @param geom Rank geometry. + */ + template + RangePtr rrange(const Sptr& global, const Sptr& geom); - Sptr mLocal; /**< Local range of THIS rank. */ - Sptr mGeom; /**< Rank geometry range. */ - - }; - - /** Create RRange from global range and given rank geometry. - @param global Global range. - @param geom Rank geometry. - */ - template - RangePtr rrange(const Sptr& global, const Sptr& geom); -} + } // namespace mpi +} // namespace CNORXZ #endif