From 8586fa074a6445d35caad32cf5f84e4d651b9baa Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 13 Oct 2024 00:41:50 -0700 Subject: [PATCH] fixes + rrange/rindex: remove constraint geo-extension == nranks --- src/include/base/to_string.cc.h | 17 +++++++++++------ src/include/base/utils.h | 6 ++++++ src/opt/mpi/include/raindex.cc.h | 6 ++++-- src/opt/mpi/include/rrange.cc.h | 21 ++++++++++++++------- src/opt/mpi/include/rrange.h | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/include/base/to_string.cc.h b/src/include/base/to_string.cc.h index bf1f9d7..4cf09b4 100644 --- a/src/include/base/to_string.cc.h +++ b/src/include/base/to_string.cc.h @@ -69,12 +69,17 @@ namespace CNORXZ { const String blim = "("; const String elim = ")"; - const String dlim = ","; - return iter<1,sizeof...(Ts)> - ( [&](auto i) { return toString(std::get(t)); }, - [&](const auto&... xs) { - return blim + toString(std::get<0>(t)) + ( (dlim + xs) + ... ) + elim; - } ); + if constexpr(sizeof...(Ts) == 1){ + return blim + toString(std::get<0>(t)) + elim; + } + else { + const String dlim = ","; + return iter<1,sizeof...(Ts)> + ( [&](auto i) { return toString(std::get(t)); }, + [&](const auto&... xs) { + return blim + toString(std::get<0>(t)) + ( (dlim + xs) + ... ) + elim; + } ); + } } template diff --git a/src/include/base/utils.h b/src/include/base/utils.h index c7d84de..c33dd23 100644 --- a/src/include/base/utils.h +++ b/src/include/base/utils.h @@ -145,6 +145,12 @@ namespace CNORXZ return Concat::cat(a1, a2); } + template + decltype(auto) concat(const T& a) + { + return a; + } + template decltype(auto) concat(const T1& a1, const T2& a2, const Ts&... as) { diff --git a/src/opt/mpi/include/raindex.cc.h b/src/opt/mpi/include/raindex.cc.h index 1696558..cd582d8 100644 --- a/src/opt/mpi/include/raindex.cc.h +++ b/src/opt/mpi/include/raindex.cc.h @@ -61,14 +61,16 @@ namespace CNORXZ RAIndex RAIndex::operator+(Int n) const { RAIndex o = *this; - return o += n; + o += n; + return o; } template RAIndex RAIndex::operator-(Int n) const { RAIndex o = *this; - return o -= n; + o -= n; + return o; } template diff --git a/src/opt/mpi/include/rrange.cc.h b/src/opt/mpi/include/rrange.cc.h index 8867b4c..af387b2 100644 --- a/src/opt/mpi/include/rrange.cc.h +++ b/src/opt/mpi/include/rrange.cc.h @@ -29,7 +29,8 @@ namespace CNORXZ RIndex::RIndex(const RIndex& in) : mRange(in.mRange), mI(std::make_shared(mRange->local())), - mK(std::make_shared(mRange->geom())) + mK(std::make_shared(mRange->geom())), + mNRanks(getNumRanks()) { *this = in.lex(); } @@ -40,6 +41,7 @@ namespace CNORXZ mRange = in.mRange; mI = std::make_shared(mRange->local()); mK = std::make_shared(mRange->geom()); + mNRanks = getNumRanks(); *this = in.lex(); return *this; } @@ -48,7 +50,8 @@ namespace CNORXZ RIndex::RIndex(const RangePtr& global, SizeT lexpos) : mRange(rangeCast(global)), mI(std::make_shared(mRange->local())), - mK(std::make_shared(mRange->geom())) + mK(std::make_shared(mRange->geom())), + mNRanks(getNumRanks()) { *this = lexpos; } @@ -57,7 +60,8 @@ namespace CNORXZ RIndex::RIndex(const Sptr& i, const Sptr& k) : mRange(rangeCast( RRangeFactory(i->range(), k->range()).create() )), mI(i), - mK(k) + mK(k), + mNRanks(getNumRanks()) { (*this)(); } @@ -264,7 +268,7 @@ namespace CNORXZ { mI->at(metaPos); const size_t lex = mI->lex(); - Vector lexs(mK->lmax().val()); + Vector lexs(mNRanks); MPI_Allgather(&lex, 1, MPI_UNSIGNED_LONG, lexs.data(), 1, MPI_UNSIGNED_LONG, MPI_COMM_WORLD); SizeT root = 0; @@ -418,9 +422,12 @@ namespace CNORXZ { 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 << ")"); + //CXZ_ASSERT(rk->size() == static_cast(s), + // "geometry rank size ( = " << rk->size() + // << ") does not match number of ranks ( = " << s << ")"); + CXZ_ASSERT(static_cast(s) % rk->size() == 0, + "geometry dimension (" << rk->size() + << ") does not divide number of ranks (" << s << ")"); if constexpr(has_static_sub::value and has_static_sub::value) { constexpr SizeT NRI = RangeI::NR; diff --git a/src/opt/mpi/include/rrange.h b/src/opt/mpi/include/rrange.h index e82a6a6..4691585 100644 --- a/src/opt/mpi/include/rrange.h +++ b/src/opt/mpi/include/rrange.h @@ -164,7 +164,7 @@ namespace CNORXZ Sptr mRange; /**< RRange. */ Sptr mI; /**< Index on the local range of the THIS rank. */ Sptr mK; /**< Multi-index indicating the current rank. */ - + SizeT mNRanks; /**< Number of ranks; in general different from but dividable by mK's maximum. */ }; template