This commit is contained in:
Christian Zimmermann 2024-03-11 19:11:38 +01:00
parent 5db90864c7
commit 6bfba5cdd9
2 changed files with 423 additions and 142 deletions

View file

@ -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 <class IndexI, class IndexK>
RIndex<IndexI,IndexK>::RIndex(const RIndex& in) :
mRange(in.mRange),
mI(std::make_shared<Index>(mRange->local())),
mK(std::make_shared<YIndex>(mRange->geom()))
{
*this = in.lex();
}
template <class IndexI, class IndexK>
RIndex& RIndex<IndexI,IndexK>::operator=(const RIndex& in)
{
mRange = in.mRange;
mI = std::make_shared<Index>(mRange->local());
mK = std::make_shared<YIndex>(mRange->geom());
*this = in.lex();
return *this;
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>::RIndex(const RangePtr& global, SizeT lexpos = 0) :
mRange(rangeCast<RangeType>(global)),
mI(std::make_shared<Index>(mRange->local())),
mK(std::make_shared<YIndex>(mRange->geom()))
{
*this = lexpos;
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>::RIndex(const Sptr<Index>& local) :
{
//!!!
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator=(SizeT pos)
{
// pos is the lexicographic position of the global range.
// Hence, have to consider the rank geometry.
if constexpr(has_static_sub<IndexI>::value or has_static_sub<IndexK>::value){
}
else {
}
return *this;
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator++()
{
return *this;
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator--()
{
return *this;
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK> RIndex<IndexI,IndexK>::operator+(Int n) const
{
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK> RIndex<IndexI,IndexK>::operator-(Int n) const
{
}
template <class IndexI, class IndexK>
SizeT RIndex<IndexI,IndexK>::operator-(const RIndex& i) const
{
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator+=(Int n)
{
return *this;
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator-=(Int n)
{
return *this;
}
template <class IndexI, class IndexK>
SizeT RIndex<IndexI,IndexK>::lex() const
{
}
template <class IndexI, class IndexK>
constexpr RIndex<IndexI,IndexK>::decltype(auto) pmax() const
{
}
template <class IndexI, class IndexK>
constexpr RIndex<IndexI,IndexK>::decltype(auto) lmax() const
{
}
template <class IndexI, class IndexK>
IndexId<0> RIndex<IndexI,IndexK>::id() const
{
}
template <class IndexI, class IndexK>
MetaType RIndex<IndexI,IndexK>::operator*() const
{
}
template <class IndexI, class IndexK>
constexpr SizeT RIndex<IndexI,IndexK>::dim() const
{
}
template <class IndexI, class IndexK>
Sptr<RangeType> RIndex<IndexI,IndexK>::range() const
{
}
template <class IndexI, class IndexK>
template <SizeT I>
decltype(auto) RIndex<IndexI,IndexK>::stepSize(const IndexId<I>& id) const
{
}
template <class IndexI, class IndexK>
String RIndex<IndexI,IndexK>::stringMeta() const
{
}
template <class IndexI, class IndexK>
MetaType RIndex<IndexI,IndexK>::meta() const
{
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::at(const MetaType& metaPos)
{
}
template <class IndexI, class IndexK>
RangePtr RIndex<IndexI,IndexK>::prange(const RIndex<IndexI,IndexK>& last) const
{
}
template <class IndexI, class IndexK>
auto RIndex<IndexI,IndexK>::deepFormat() const
{
}
template <class IndexI, class IndexK>
auto RIndex<IndexI,IndexK>::deepMax() const
{
}
template <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s)
{
}
template <class IndexI, class IndexK>
template <class Xpr, class F>
constexpr decltype(auto) RIndex<IndexI,IndexK>::ifor(const Xpr& xpr, F&& f) const
{
}
template <class IndexI, class IndexK>
bool RIndex<IndexI,IndexK>::formatIsTrivial() const
{
}
template <class IndexI, class IndexK>
decltype(auto) RIndex<IndexI,IndexK>::xpr(const Sptr<RIndex<IndexI,IndexK>>& _this) const
{
}
template <class IndexI, class IndexK>
int RIndex<IndexI,IndexK>::rank() const
{
}
template <class IndexI, class IndexK>
Sptr<Index> RIndex<IndexI,IndexK>::local() const
{
}
} // namespace mpi
} // namespace CNORXZ
#endif

View file

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
/** /**
@file opt/include/rrange.h @file opt/mpi/include/rrange.h
@brief RRange and RIndex declaration. @brief RRange and RIndex declaration.
Copyright (c) 2024 Christian Zimmermann. All rights reserved. Copyright (c) 2024 Christian Zimmermann. All rights reserved.
@ -16,179 +16,217 @@
namespace CNORXZ namespace CNORXZ
{ {
namespace mpi
/** ****
Specific index for RRange.
@tparam Index Local index type.
*/
template <class Index>
class RIndex : public IndexInterface<RIndex<Index>,typename Index::MetaType>
{ {
public:
typedef IndexInterface<RIndex<Index>,typename Index::MetaType> IB;
typedef typename Index::MetaType MetaType;
typedef RRange<typename Index::RangeType> 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 IndexI, class IndexK>
class RIndex : public IndexInterface<RIndex<IndexI,IndexK>,typename Index::MetaType>
{
public:
typedef IndexInterface<RIndex<IndexI,IndexK>,typename Index::MetaType> IB;
typedef typename Index::MetaType MetaType;
typedef RRange<typename Index::RangeType> RangeType;
// constructors!!! INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType);
/** @copydoc IndexInterface::operator=(SizeT) */ // constructors!!!
RIndex& operator=(SizeT pos); /** Default constructor. */
RIndex() = default;
/** @copydoc IndexInterface::operator++() */ /** Move constructor (default). */
RIndex& operator++(); RIndex(RIndex&& in) = default;
/** @copydoc IndexInterface::operator--() */ /** Move assignment (default). */
RIndex& operator--(); RIndex& operator=(RIndex&& in) = default;
/** @copydoc IndexInterface::operator+() */ /** Copy constructor (no default, copy local index instance). */
RIndex operator+(Int n) const; RIndex(const RIndex& in);
/** @copydoc IndexInterface::operator-() */ /** Copy assignment (no default, copy local index instance). */
RIndex operator-(Int n) const; RIndex& operator=(const RIndex& in);
/** @copydoc IndexInterface::operator-(CIndex) */ /** Construct from global range and format.
SizeT operator-(const RIndex& i) const; @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);
/** @copydoc IndexInterface::operator+=() */ /** Construct from local index. */
RIndex& operator+=(Int n); RIndex(const Sptr<IndexI,IndexK>& local);
/** @copydoc IndexInterface::operator-=() */ /** @copydoc IndexInterface::operator=(SizeT) */
RIndex& operator-=(Int n); RIndex& operator=(SizeT pos);
/** @copydoc IndexInterface::lex() */ /** @copydoc IndexInterface::operator++() */
SizeT lex() const; RIndex& operator++();
/** @copydoc IndexInterface::pmax() */ /** @copydoc IndexInterface::operator--() */
constexpr decltype(auto) pmax() const; RIndex& operator--();
/** @copydoc IndexInterface::lmax() */ /** @copydoc IndexInterface::operator+() */
constexpr decltype(auto) lmax() const; RIndex operator+(Int n) const;
/** @copydoc IndexInterface::id() */ /** @copydoc IndexInterface::operator-() */
IndexId<0> id() const; RIndex operator-(Int n) const;
/** @copydoc IndexInterface::operator*() */ /** @copydoc IndexInterface::operator-(CIndex) */
MetaType operator*() const; SizeT operator-(const RIndex& i) const;
/** @copydoc IndexInterface::dim() */ /** @copydoc IndexInterface::operator+=() */
constexpr SizeT dim() const; RIndex& operator+=(Int n);
/** @copydoc IndexInterface::range() */ /** @copydoc IndexInterface::operator-=() */
Sptr<RangeType> range() const; RIndex& operator-=(Int n);
/** @copydoc IndexInterface::stepSize() */ /** @copydoc IndexInterface::lex() */
template <SizeT I> SizeT lex() const;
decltype(auto) stepSize(const IndexId<I>& id) const;
/** @copydoc IndexInterface::stringMeta() */ /** @copydoc IndexInterface::pmax() */
String stringMeta() const; constexpr decltype(auto) pmax() const;
/** @copydoc IndexInterface::meta() */ /** @copydoc IndexInterface::lmax() */
MetaType meta() const; constexpr decltype(auto) lmax() const;
/** @copydoc IndexInterface::at() */ /** @copydoc IndexInterface::id() */
RIndex& at(const MetaType& metaPos); IndexId<0> id() const;
/** @copydoc IndexInterface::prange() */ /** @copydoc IndexInterface::operator*() */
RangePtr prange(const RIndex<Index>& last) const; MetaType operator*() const;
/** @copydoc IndexInterface::deepFormat() */ /** @copydoc IndexInterface::dim() */
auto deepFormat() const; constexpr SizeT dim() const;
/** @copydoc IndexInterface::deepMax() */ /** @copydoc IndexInterface::range() */
auto deepMax() const; Sptr<RangeType> range() const;
/** @copydoc IndexInterface::reformat() */ /** @copydoc IndexInterface::stepSize() */
RIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s); template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const;
/** @copydoc IndexInterface::ifor() */ /** @copydoc IndexInterface::stringMeta() */
template <class Xpr, class F> String stringMeta() const;
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
/** @copydoc IndexInterface::formatIsTrivial() */ /** @copydoc IndexInterface::meta() */
bool formatIsTrivial() const; MetaType meta() const;
/** @copydoc IndexInterface::xpr() */ /** @copydoc IndexInterface::at() */
decltype(auto) xpr(const Sptr<MIndex<Indices...>>& _this) const; RIndex& at(const MetaType& metaPos);
//!!! /** @copydoc IndexInterface::prange() */
RangePtr prange(const RIndex<IndexI,IndexK>& last) const;
private: /** @copydoc IndexInterface::deepFormat() */
Sptr<RangeType> mRange; auto deepFormat() const;
Sptr<Index> mLocalI;
//!!!
};
// Factory!!! /** @copydoc IndexInterface::deepMax() */
auto deepMax() const;
/** **** /** @copydoc IndexInterface::reformat() */
Range-Wrapper for ranges that are distributed on MPI ranks. RIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
@tparam Range Local range type.
*/
template <class Range>
class RRange : public RangeInterface<RRange<Range>>
{
public:
typedef RangeBase RB;
typedef RIndex<typename Range::IndexType> IndexType;
typedef typename Range::MetaType MetaType;
friend RRangeFactory<Range>; /** @copydoc IndexInterface::ifor() */
template <class Xpr, class F>
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
virtual RangePtr sub(SizeT num) const override final; /** @copydoc IndexInterface::formatIsTrivial() */
virtual MArray<RangePtr> sub() const override final; bool formatIsTrivial() const;
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. */ /** @copydoc IndexInterface::xpr() */
Sptr<Range> local() const; decltype(auto) xpr(const Sptr<RIndex<IndexI,IndexK>>& _this) const;
/** Get meta data for given lexicographic position. /** Get the current rank. */
@param pos Lexicographic position. int rank() const;
*/
const MetaType get(SizeT pos) const;
/** Get lexicographic position according to the given meta data value. /** Get the local index on THIS rank. */
@param metaPos Meta data value. Sptr<IndexI,IndexK> local() const;
*/ //!!!
SizeT getMeta(const MetaType& metaPos) const;
/** Get rank from lexicographic meta data position. private:
@param pos Lexicographic meta data position. Sptr<RangeType> mRange; /**< RRange. */
*/ Sptr<IndexI> mJ; /**< Index on the local range of the THIS rank. */
int getRank(SizeT pos) const; Sptr<IndexK> mK; /**< Multi-index indicating the current rank. */
//!!!
};
protected: // Factory!!!
/** Dafault constructor */ /** ****
RRange() = default; Range-Wrapper for ranges that are distributed on MPI ranks.
@tparam Range Local range type.
*/
template <class Range>
class RRange : public RangeInterface<RRange<Range>>
{
public:
typedef RangeBase RB;
typedef RIndex<typename Range::IndexType> IndexType;
typedef typename Range::MetaType MetaType;
RRange(const RRange& in) = delete; friend RRangeFactory<Range>;
RRange& operator=(const RRange& in) = delete;
/** Construct from local range and geometry. virtual RangePtr sub(SizeT num) const override final;
@param loc Local range. virtual MArray<RangePtr> sub() const override final;
@param geom Rank geometry range. virtual SizeT size() const override final;
*/ virtual SizeT dim() const override final;
RRange(const Sptr<Range>& loc, const Sptr<YRange>& geom); 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;
Sptr<Range> mLocal; /**< Local range of THIS rank. */ /** Get local range. */
Sptr<YRange> mGeom; /**< Rank geometry range. */ Sptr<Range> local() const;
}; /** Get range of the rank geometry. */
Sptr<YRange> geom() const;
/** Create RRange from global range and given rank geometry. /** Get meta data for given lexicographic position.
@param global Global range. @param pos Lexicographic position.
@param geom Rank geometry. */
*/ const MetaType get(SizeT pos) const;
template <class GRange>
RangePtr rrange(const Sptr<GRange>& global, const Sptr<YRange>& geom); /** 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<Range>& loc, const Sptr<YRange>& geom);
Sptr<Range> mLocal; /**< Local range of THIS rank. */
Sptr<YRange> mGeom; /**< Rank geometry range. */
};
/** Create RRange from global range and given rank geometry.
@param global Global range.
@param geom Rank geometry.
*/
template <class GRange>
RangePtr rrange(const Sptr<GRange>& global, const Sptr<YRange>& geom);
} // namespace mpi
} // namespace CNORXZ
#endif #endif