fixes + rrange/rindex: remove constraint geo-extension == nranks

This commit is contained in:
Christian Zimmermann 2024-10-13 00:41:50 -07:00
parent d3358d71d6
commit 8586fa074a
5 changed files with 36 additions and 16 deletions

View file

@ -69,12 +69,17 @@ namespace CNORXZ
{ {
const String blim = "("; const String blim = "(";
const String elim = ")"; const String elim = ")";
const String dlim = ","; if constexpr(sizeof...(Ts) == 1){
return iter<1,sizeof...(Ts)> return blim + toString(std::get<0>(t)) + elim;
( [&](auto i) { return toString(std::get<i>(t)); }, }
[&](const auto&... xs) { else {
return blim + toString(std::get<0>(t)) + ( (dlim + xs) + ... ) + elim; const String dlim = ",";
} ); return iter<1,sizeof...(Ts)>
( [&](auto i) { return toString(std::get<i>(t)); },
[&](const auto&... xs) {
return blim + toString(std::get<0>(t)) + ( (dlim + xs) + ... ) + elim;
} );
}
} }
template <typename T, typename S> template <typename T, typename S>

View file

@ -145,6 +145,12 @@ namespace CNORXZ
return Concat<T1,T2>::cat(a1, a2); return Concat<T1,T2>::cat(a1, a2);
} }
template <typename T>
decltype(auto) concat(const T& a)
{
return a;
}
template <typename T1, typename T2, typename... Ts> template <typename T1, typename T2, typename... Ts>
decltype(auto) concat(const T1& a1, const T2& a2, const Ts&... as) decltype(auto) concat(const T1& a1, const T2& a2, const Ts&... as)
{ {

View file

@ -61,14 +61,16 @@ namespace CNORXZ
RAIndex<T> RAIndex<T>::operator+(Int n) const RAIndex<T> RAIndex<T>::operator+(Int n) const
{ {
RAIndex<T> o = *this; RAIndex<T> o = *this;
return o += n; o += n;
return o;
} }
template <typename T> template <typename T>
RAIndex<T> RAIndex<T>::operator-(Int n) const RAIndex<T> RAIndex<T>::operator-(Int n) const
{ {
RAIndex<T> o = *this; RAIndex<T> o = *this;
return o -= n; o -= n;
return o;
} }
template <typename T> template <typename T>

View file

@ -29,7 +29,8 @@ namespace CNORXZ
RIndex<IndexI,IndexK>::RIndex(const RIndex& in) : RIndex<IndexI,IndexK>::RIndex(const RIndex& in) :
mRange(in.mRange), mRange(in.mRange),
mI(std::make_shared<IndexI>(mRange->local())), mI(std::make_shared<IndexI>(mRange->local())),
mK(std::make_shared<IndexK>(mRange->geom())) mK(std::make_shared<IndexK>(mRange->geom())),
mNRanks(getNumRanks())
{ {
*this = in.lex(); *this = in.lex();
} }
@ -40,6 +41,7 @@ namespace CNORXZ
mRange = in.mRange; mRange = in.mRange;
mI = std::make_shared<IndexI>(mRange->local()); mI = std::make_shared<IndexI>(mRange->local());
mK = std::make_shared<IndexK>(mRange->geom()); mK = std::make_shared<IndexK>(mRange->geom());
mNRanks = getNumRanks();
*this = in.lex(); *this = in.lex();
return *this; return *this;
} }
@ -48,7 +50,8 @@ namespace CNORXZ
RIndex<IndexI,IndexK>::RIndex(const RangePtr& global, SizeT lexpos) : RIndex<IndexI,IndexK>::RIndex(const RangePtr& global, SizeT lexpos) :
mRange(rangeCast<RangeType>(global)), mRange(rangeCast<RangeType>(global)),
mI(std::make_shared<IndexI>(mRange->local())), mI(std::make_shared<IndexI>(mRange->local())),
mK(std::make_shared<IndexK>(mRange->geom())) mK(std::make_shared<IndexK>(mRange->geom())),
mNRanks(getNumRanks())
{ {
*this = lexpos; *this = lexpos;
} }
@ -57,7 +60,8 @@ namespace CNORXZ
RIndex<IndexI,IndexK>::RIndex(const Sptr<IndexI>& i, const Sptr<IndexK>& k) : RIndex<IndexI,IndexK>::RIndex(const Sptr<IndexI>& i, const Sptr<IndexK>& k) :
mRange(rangeCast<RangeType>( RRangeFactory(i->range(), k->range()).create() )), mRange(rangeCast<RangeType>( RRangeFactory(i->range(), k->range()).create() )),
mI(i), mI(i),
mK(k) mK(k),
mNRanks(getNumRanks())
{ {
(*this)(); (*this)();
} }
@ -264,7 +268,7 @@ namespace CNORXZ
{ {
mI->at(metaPos); mI->at(metaPos);
const size_t lex = mI->lex(); const size_t lex = mI->lex();
Vector<size_t> lexs(mK->lmax().val()); Vector<size_t> lexs(mNRanks);
MPI_Allgather(&lex, 1, MPI_UNSIGNED_LONG, lexs.data(), 1, MPI_UNSIGNED_LONG, MPI_Allgather(&lex, 1, MPI_UNSIGNED_LONG, lexs.data(), 1, MPI_UNSIGNED_LONG,
MPI_COMM_WORLD); MPI_COMM_WORLD);
SizeT root = 0; SizeT root = 0;
@ -418,9 +422,12 @@ namespace CNORXZ
{ {
int s = 0; int s = 0;
MPI_Comm_size(MPI_COMM_WORLD, &s); MPI_Comm_size(MPI_COMM_WORLD, &s);
CXZ_ASSERT(rk->size() == static_cast<SizeT>(s), //CXZ_ASSERT(rk->size() == static_cast<SizeT>(s),
"geometry rank size ( = " << rk->size() // "geometry rank size ( = " << rk->size()
<< ") does not match number of ranks ( = " << s << ")"); // << ") does not match number of ranks ( = " << s << ")");
CXZ_ASSERT(static_cast<SizeT>(s) % rk->size() == 0,
"geometry dimension (" << rk->size()
<< ") does not divide number of ranks (" << s << ")");
if constexpr(has_static_sub<typename RangeI::IndexType>::value and if constexpr(has_static_sub<typename RangeI::IndexType>::value and
has_static_sub<typename RangeK::IndexType>::value) { has_static_sub<typename RangeK::IndexType>::value) {
constexpr SizeT NRI = RangeI::NR; constexpr SizeT NRI = RangeI::NR;

View file

@ -164,7 +164,7 @@ namespace CNORXZ
Sptr<RangeType> mRange; /**< RRange. */ Sptr<RangeType> mRange; /**< RRange. */
Sptr<IndexI> mI; /**< Index on the local range of the THIS rank. */ Sptr<IndexI> mI; /**< Index on the local range of the THIS rank. */
Sptr<IndexK> mK; /**< Multi-index indicating the current rank. */ Sptr<IndexK> mK; /**< Multi-index indicating the current rank. */
SizeT mNRanks; /**< Number of ranks; in general different from but dividable by mK's maximum. */
}; };
template <class IndexI, class IndexK> template <class IndexI, class IndexK>