URange cast for PRanges + fix mpi test

This commit is contained in:
Christian Zimmermann 2024-03-16 17:25:37 +01:00
parent f55c38cc65
commit bd8970ae33
3 changed files with 19 additions and 3 deletions

View file

@ -359,7 +359,10 @@ namespace CNORXZ
template <typename T> template <typename T>
static inline Sptr<URange<MetaT>> transform(const RangePtr& r) static inline Sptr<URange<MetaT>> transform(const RangePtr& r)
{ {
if(r->type() == typeid(URange<T>)){ if(r->type() == typeid(PRange<URange<T>>)){
return transform<T>( std::dynamic_pointer_cast<PRange<URange<T>>>(r)->derive() );
}
else if(r->type() == typeid(URange<T>)){
auto rr = std::dynamic_pointer_cast<URange<T>>(r); auto rr = std::dynamic_pointer_cast<URange<T>>(r);
Vector<MetaT> v(rr->size()); Vector<MetaT> v(rr->size());
std::transform(rr->begin(), rr->end(), v.begin(), std::transform(rr->begin(), rr->end(), v.begin(),

View file

@ -51,7 +51,9 @@ namespace CNORXZ
auto jb = global->begin(); auto jb = global->begin();
auto je = global->begin(); auto je = global->begin();
MArray<RangePtr> o(geom); MArray<RangePtr> o(geom);
o(k) = operation( [&](const SizeT x){ jb = n*x; je = n*(x+1)-1; return jb.prange(je); } , xpr(k) ); o(k) = operation( [&](const SizeT x){
jb = n*x; je = n*(x+1)-1; return jb.prange(je);
} , xpr(k) );
return o; return o;
} }
} }
@ -66,7 +68,7 @@ namespace CNORXZ
} }
} }
assert(o); assert(o);
auto loc = rangeCast<YRange>(global); auto loc = rangeCast<YRange>(o);
auto geo = rangeCast<YRange>(geom); auto geo = rangeCast<YRange>(geom);
RRangeFactory<YRange,YRange> xx(loc, geo); RRangeFactory<YRange,YRange> xx(loc, geo);
return RRangeFactory<YRange,YRange>(loc, geo).create(); return RRangeFactory<YRange,YRange>(loc, geo).create();

View file

@ -34,6 +34,14 @@ namespace
CXZ_ASSERT(getNumRanks() == 4, "exptected 4 ranks"); CXZ_ASSERT(getNumRanks() == 4, "exptected 4 ranks");
Vector<Int> xs(12); Vector<Int> xs(12);
Vector<Int> ts(16); Vector<Int> ts(16);
for(SizeT i = 0; i != xs.size(); ++i){
const Int x = static_cast<Int>(i) - static_cast<Int>(xs.size()/2);
xs[i] = x;
}
for(SizeT i = 0; i != ts.size(); ++i){
const Int t = static_cast<Int>(i) - static_cast<Int>(ts.size()/2);
ts[i] = t;
}
mXRange = URangeFactory<Int>(xs).create(); mXRange = URangeFactory<Int>(xs).create();
mTRange = URangeFactory<Int>(ts).create(); mTRange = URangeFactory<Int>(ts).create();
Vector<RangePtr> rs { mTRange, mXRange, mXRange, mXRange }; Vector<RangePtr> rs { mTRange, mXRange, mXRange, mXRange };
@ -55,6 +63,9 @@ namespace
TEST_F(RRange_Test, Basics) TEST_F(RRange_Test, Basics)
{ {
EXPECT_EQ(mRRange->size(), mGRange->size()); EXPECT_EQ(mRRange->size(), mGRange->size());
typedef UIndex<Int> UI;
MIndex<UI,UI,UI,UI> mi(mRRange->sub(1));
EXPECT_EQ(mi.lmax().val(), mGRange->size()/mRRange->sub(0)->size());
} }
} }