fix/implement missing broadcasts + fix at() for mrange/rrange

This commit is contained in:
Christian Zimmermann 2024-03-23 20:46:49 +01:00
parent 9b2b1be170
commit 236a5b1b81
4 changed files with 44 additions and 20 deletions

View file

@ -60,8 +60,12 @@ namespace CNORXZ
template <class FormatT, class... Indices>
inline void GMIndex<FormatT,Indices...>::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<FormatT,None>::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 <class FormatT, class... Indices>
@ -433,9 +441,7 @@ namespace CNORXZ
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::at(const MetaType& metaPos)
{
iter<0,NI>( [&](auto i) { mIPack[i]->at( std::get<i>(metaPos) ); }, NoF {} );
IB::mPos = iter<0,NI>
( [&](auto i) { return mIPack[i]->pos()*format()[i].val(); },
[](const auto&... xs) { return (xs + ...); });
mkPos();
return *this;
}

View file

@ -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 <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::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<size_t> 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 <class IndexI, class IndexK>
RIndex<IndexI,IndexK>& RIndex<IndexI,IndexK>::operator()()
{
if(mI->lex() >= mI->lmax().val()){
IB::mPos = lmax().val();
}
if constexpr(has_static_sub<IndexI>::value){
constexpr SizeT NI = index_dim<IndexI>::value;
IB::mPos = iter<0,NI>

View file

@ -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 <typename T, SizeT N>
struct Typemap<Arr<T,N>>
{
static constexpr bool exists = Typemap<T>::exists;
static MPI_Datatype value() { return Typemap<T>::value(); }
};
template <typename T>
struct Typemap<Vector<T>>
{
static constexpr bool exists = Typemap<T>::exists;
static MPI_Datatype value() { return Typemap<T>::value(); }
};
template <typename... Ts>
struct Typemap<Tuple<Ts...>>
{
static constexpr bool exists = ( Typemap<Ts>::exists and ... );
static MPI_Datatype value() { return MPI_BYTE; }
};
// further !!!
} // namespace mpi

View file

@ -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;
}
}
*/
}
}