From 236a5b1b818bfc4b3e80e4114cdb27074bc2ac5c Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 23 Mar 2024 20:46:49 +0100 Subject: [PATCH] fix/implement missing broadcasts + fix at() for mrange/rrange --- src/include/ranges/mrange.cc.h | 14 ++++++++++---- src/opt/mpi/include/rrange.cc.h | 16 +++++++++------- src/opt/mpi/include/typemap.h | 23 +++++++++++++++++++++++ src/opt/mpi/tests/rrange_unit_test.cc | 11 ++--------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 82d1d6f..6d03ff2 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -60,8 +60,12 @@ namespace CNORXZ template inline void GMIndex::mkPos() { + bool outOfScope = false; mLex = iter<0,NI> - ([&](auto i) { return mIPack[i]->lex() * mLexFormat[i].val(); }, + ([&](auto i) { + outOfScope |= mIPack[i]->lex() >= mIPack[i]->lmax().val(); + return mIPack[i]->lex() * mLexFormat[i].val(); + }, [](const auto&... e) { return (e + ...); }); if constexpr(not std::is_same::value){ IB::mPos = iter<0,NI> @@ -71,6 +75,10 @@ namespace CNORXZ else { IB::mPos = mLex; } + if(outOfScope){ + IB::mPos = pmax().val(); + mLex = lmax().val(); + } } template @@ -433,9 +441,7 @@ namespace CNORXZ GMIndex& GMIndex::at(const MetaType& metaPos) { iter<0,NI>( [&](auto i) { mIPack[i]->at( std::get(metaPos) ); }, NoF {} ); - IB::mPos = iter<0,NI> - ( [&](auto i) { return mIPack[i]->pos()*format()[i].val(); }, - [](const auto&... xs) { return (xs + ...); }); + mkPos(); return *this; } diff --git a/src/opt/mpi/include/rrange.cc.h b/src/opt/mpi/include/rrange.cc.h index 41cf1f4..18c0c5f 100644 --- a/src/opt/mpi/include/rrange.cc.h +++ b/src/opt/mpi/include/rrange.cc.h @@ -221,24 +221,24 @@ namespace CNORXZ } bcast(o, r); } + else { + // TODO: In general don't allow RIndices if broadcast for MetaType + // does not exitst (once DType broadcast is implemented)!!! + CXZ_ERROR("no broadcast implementation for given meta type (" + << typeid(MetaType).name() << ") available"); + } return o; } template RIndex& RIndex::at(const MetaType& metaPos) { - //VCHECK(toString(metaPos)); - //VCHECK(toString(mI->meta())); mI->at(metaPos); - //VCHECK(toString(mI->meta())); const size_t lex = mI->lex(); - //VCHECK(lex); Vector lexs(mK->lmax().val()); MPI_Allgather(&lex, 1, MPI_UNSIGNED_LONG, lexs.data(), 1, MPI_UNSIGNED_LONG, MPI_COMM_WORLD); - VCHECK(toString(lexs)); SizeT root = 0; - VCHECK(mI->lmax().val()); for(; root != lexs.size() and lexs[root] == mI->lmax().val(); ++root) {} if(root == lexs.size()){ // metaPos not in rrange *this = lmax().val(); @@ -247,7 +247,6 @@ namespace CNORXZ else { *mK = root; *mI = lexs[root]; - VCHECK(lexs[root]); (*this)(); } return *this; @@ -302,6 +301,9 @@ namespace CNORXZ template RIndex& RIndex::operator()() { + if(mI->lex() >= mI->lmax().val()){ + IB::mPos = lmax().val(); + } if constexpr(has_static_sub::value){ constexpr SizeT NI = index_dim::value; IB::mPos = iter<0,NI> diff --git a/src/opt/mpi/include/typemap.h b/src/opt/mpi/include/typemap.h index f5c66ee..20d96fb 100644 --- a/src/opt/mpi/include/typemap.h +++ b/src/opt/mpi/include/typemap.h @@ -12,6 +12,7 @@ namespace CNORXZ struct Typemap { static constexpr bool exists = false; + static MPI_Datatype value() { return MPI_BYTE; } }; template <> @@ -56,6 +57,28 @@ namespace CNORXZ static MPI_Datatype value() { return MPI_FLOAT; } }; + template + struct Typemap> + { + static constexpr bool exists = Typemap::exists; + static MPI_Datatype value() { return Typemap::value(); } + }; + + template + struct Typemap> + { + static constexpr bool exists = Typemap::exists; + static MPI_Datatype value() { return Typemap::value(); } + }; + + template + struct Typemap> + { + static constexpr bool exists = ( Typemap::exists and ... ); + static MPI_Datatype value() { return MPI_BYTE; } + }; + + // further !!! } // namespace mpi diff --git a/src/opt/mpi/tests/rrange_unit_test.cc b/src/opt/mpi/tests/rrange_unit_test.cc index b7f4e2e..c5ab685 100644 --- a/src/opt/mpi/tests/rrange_unit_test.cc +++ b/src/opt/mpi/tests/rrange_unit_test.cc @@ -134,17 +134,11 @@ namespace EXPECT_EQ(s1 ,s2); } rgi = 0; - gi = 0; - auto xi = gi; - gi = 10; - xi.at( gi.meta() ); - EXPECT_EQ( xi.lex(), gi.lex() ); - //VCHECK(toString(rgi.local()->meta())); - VCHECK(rgi.local()->at( gi.meta() ).lex()); - /* auto j = rgi; for(auto i = rgi; i.lex() != i.lmax().val(); ++i){ j.at( i.meta() ); + //const auto imeta = toString(i.meta()); + //const auto jmeta = toString(j.meta()); if(getRankNumber() == 0){ EXPECT_EQ(i.lex(), j.lex()); EXPECT_EQ(i.rank(), j.rank()); @@ -154,7 +148,6 @@ namespace break; } } - */ } }