From 21a2ca0b72ed9f392a515c23f57d6579e5be6da3 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 13 Mar 2024 01:38:13 +0100 Subject: [PATCH] WIP: rrange --- src/opt/mpi/include/rrange.cc.h | 154 ++++++++++++++++++++++++++++++-- src/opt/mpi/include/rrange.h | 15 ++-- 2 files changed, 151 insertions(+), 18 deletions(-) diff --git a/src/opt/mpi/include/rrange.cc.h b/src/opt/mpi/include/rrange.cc.h index 50a815c..7ace931 100644 --- a/src/opt/mpi/include/rrange.cc.h +++ b/src/opt/mpi/include/rrange.cc.h @@ -46,19 +46,12 @@ namespace CNORXZ template RIndex::RIndex(const RangePtr& global, SizeT lexpos = 0) : mRange(rangeCast(global)), - mI(std::make_shared(mRange->local())), - mK(std::make_shared(mRange->geom())) + mI(std::make_shared(mRange->local())), + mK(std::make_shared(mRange->geom())) { *this = lexpos; } - template - RIndex::RIndex(const Sptr& local) : - { - CXZ_ERROR("not implemented"); - //!!! - } - template RIndex& RIndex::operator=(SizeT pos) { @@ -299,6 +292,11 @@ namespace CNORXZ mRI(ri), mRK(rk) { + int s = 0; + MPI_Comm_size(MPI_COMM_WORLD, &s); + CXZ_ASSERT(rk->size() == static_cast(s), + "geometry rank size ( = " << rk->size() + << ") does not match number of ranks ( = " << s << ")"); if constexpr(has_static_sub::value and has_static_sub::value) { static_assert(typename RangeI::NR == typename RangeK::NR, @@ -323,6 +321,144 @@ namespace CNORXZ } } + /*==============+ + | RRange | + +==============*/ + + template + RangePtr RRange::sub(SizeT num) const + { + if(num == 0){ + return mGeom; + } + else if(num == 1){ + return mLocal; + } + else { + CXZ_ERROR("out of range: " << num); + return nullptr; + } + } + + template + MArray RRange::sub() const + { + RangePtr sr = SRangeFactory( Arr { 0, 1 } ).create(); + return MArray( sr, Vector( { mGeom, mLocal } ) ); + } + + template + SizeT RRange::size() const + { + return mGeom->size() * mLocal->size(); + } + + template + SizeT RRange::dim() const + { + return mGeom->dim() + mLocal->dim(); + } + + template + String RRange::stringMeta(SizeT pos) const + { + return (this->begin()+pos).stringMeta(); + } + + template + const TypeInfo& RRange::type() const + { + return typeid(RRange); + } + + template + const TypeInfo& RRange::metaType() const + { + return typeid(MetaType); + } + + template + RangePtr RRange::extend(const RangePtr& r) const + { + CXZ_ERROR("not implemented"); + return nullptr; + } + + template + Sptr RRange::local() const + { + return mLocal; + } + + template + Sptr RRange::geom() const + { + return mGeom; + } + + template + const MetaType RRange::get(SizeT pos) const + { + return (this->begin()+pos)->meta(); + } + + template + SizeT RRange::getMeta(const MetaType& metaPos) const + { + auto i = this->begin(); + return i.at(metaPos).pos(); + } + + template + SizeT RRange::getRank(SizeT pos) const + { + return (this->begin()+pos)->rank(); + } + + /*=========================+ + | RRange (protected) | + +=========================*/ + + template + RRange::RRange(const Sptr& loc, const Sptr& geom) : + mLocal(loc), + mGeom(geom) + {} + + /*===========================+ + | non-member functions | + +===========================*/ + + template + RangePtr rrange(const Sptr& global, const Sptr& geom) + { + if constexpr(has_static_sub::value and + has_static_sub::value) { + static_assert(typename RangeI::NR == typename RangeK::NR, + "ranges have to be of same dimension"); + + constexpr SizeT N = typename RangeI::NR; + auto mr = ifor<0,N>( [&](auto mu) { + return split( global->space()[CSizeT{}], geom->space()[CSizeT{}] ); + }, [](const auto&... r) { return xplMrange(r,...); } ); + typedef std::remove_reference::type RangeI; + return RRangeFactory(mr, geom).create(); // explicit range type!!! + } + // other cases!!! + else { + CXZ_ASSERT(global->dim() == geom->dim(), + "ranges have to be of same dimension, got " + << global->dim() << " and " << geom->dim()); + Vector o(global->dim()); + for(SizeT mu = 0; mu != global->dim(); ++mu){ + o[mu] = split( global->space()[mu], geom->space()[mu] ); + } + const Sptr yr = xplYrange(o); + return RRangeFactory(yr, geom).create(); + } + } + + } // namespace mpi } // namespace CNORXZ diff --git a/src/opt/mpi/include/rrange.h b/src/opt/mpi/include/rrange.h index 03ebae3..cab6b30 100644 --- a/src/opt/mpi/include/rrange.h +++ b/src/opt/mpi/include/rrange.h @@ -51,14 +51,11 @@ namespace CNORXZ 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 global Pointer to global range (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); @@ -191,7 +188,7 @@ namespace CNORXZ typedef RIndex IndexType; typedef typename RangeI::MetaType MetaType; - friend RRangeFactory; + friend RRangeFactory; virtual RangePtr sub(SizeT num) const override final; virtual MArray sub() const override final; @@ -221,7 +218,7 @@ namespace CNORXZ /** Get rank from lexicographic meta data position. @param pos Lexicographic meta data position. */ - int getRank(SizeT pos) const; + SizeT getRank(SizeT pos) const; protected: @@ -235,7 +232,7 @@ namespace CNORXZ @param loc Local range. @param geom Rank geometry range. */ - RRange(const Sptr& loc, const Sptr& geom); + RRange(const Sptr& loc, const Sptr& geom); Sptr mLocal; /**< Local range of THIS rank. */ Sptr mGeom; /**< Rank geometry range. */ @@ -246,8 +243,8 @@ namespace CNORXZ @param global Global range. @param geom Rank geometry. */ - template - RangePtr rrange(const Sptr& global, const Sptr& geom); + template + RangePtr rrange(const Sptr& global, const Sptr& geom); } // namespace mpi } // namespace CNORXZ