mpi: raindex: fixes + hdf5_mpi: improve unit test

This commit is contained in:
Christian Zimmermann 2025-01-01 16:11:29 -08:00
parent 54028c58b1
commit ffec135eec
4 changed files with 30 additions and 10 deletions

View file

@ -92,10 +92,10 @@ namespace CNORXZ
void RDataset::readbase(void* dest, RangePtr readRange, Sptr<YIndex> beg) const
{
RangePtr dr = readRange;
bool parallel = dr->stype() == "R";
if(not dr){
dr = mFileRange;
}
bool parallel = dr->stype() == "R";
if(parallel){
dr = readRange->sub(1);
}

View file

@ -39,15 +39,19 @@ namespace
mFilename = "parallel_test_file.h5";
Vector<RangePtr> grv(4);
grv[0] = CRangeFactory(5).create();
grv[1] = CRangeFactory(14).create();
grv[1] = CRangeFactory(16).create();
grv[2] = CRangeFactory(10).create();
grv[3] = CRangeFactory(3).create();
const RangePtr g1 = CRangeFactory(1).create();
const RangePtr g2 = CRangeFactory(2).create();
const RangePtr g4 = CRangeFactory(4).create();
mGeom = yrange(Vector<RangePtr>{g1,g2,g2,g1});
mGeom2 = yrange(Vector<RangePtr>{g1,g4,g1,g1});
const RangePtr gr = yrange(grv);
const RangePtr rr = rrange(gr,mGeom);
mLR = rr->sub(1);
const RangePtr rr2 = rrange(gr,mGeom2);
mLR2 = rr2->sub(1);
Vector<Double> vec = Numbers::get(14,gr->size()+10);
Vector<Double> loc(mLR->size());
for(auto k = CIndex(mGeom); k.lex() != k.lmax().val(); ++k){
@ -57,11 +61,24 @@ namespace
}
auto locarr = MArray<Double>( mLR, loc );
mA = RArray<Double>( locarr, mGeom );
auto rr2x = std::dynamic_pointer_cast<RRange<YRange,YRange>>(rr2);
assert(rr2x);
mA2 = RArray<Double>( rr2x );
auto i1 = mA.begin();
auto i2 = mA2.begin();
assert(i1.lmax().val() == i2.lmax().val());
for(i1 = 0; i1.lex() != i1.lmax().val(); ++i1){
i2 = i1.lex();
i2.set( *i1 );
}
}
RArray<Double> mA;
RangePtr mGeom;
RangePtr mLR;
RArray<Double> mA2;
RangePtr mGeom2;
RangePtr mLR2;
String mFilename;
};
@ -88,11 +105,11 @@ namespace
//{ (*i)->close(); auto dset = std::make_shared<SRDataset<Double>>(name, par); *i = dset;
// return dset; } );
auto dat = getRDataset<Double>(h5f.open().getGroup("dir")->open(),"dat");
auto a = dat->read(mGeom);
auto a = dat->read(mGeom2);
h5f.close();
auto i = std::make_shared<CIndex>(mLR);
i->ifor( operation( [](Double a, Double b) { EXPECT_EQ(a,b); }, mA(i), a(i) ), NoF{} )();
auto i = std::make_shared<CIndex>(mLR2);
i->ifor( operation( [](Double a, Double b) { EXPECT_EQ(a,b); }, mA2(i), a(i) ), NoF{} )();
}
}

View file

@ -34,6 +34,7 @@ namespace CNORXZ
{
public:
typedef typename RIndex<YIndex,YIndex>::IB IB;
using RIndex<YIndex,YIndex>::operator=;
DEFAULT_MEMBERS(RAIndex);
RAIndex(const T* loc, const RangePtr& range, SizeT lexpos = 0);
@ -47,17 +48,18 @@ namespace CNORXZ
const T* operator->() const;
void setBufferSize();
private:
void setBuffer() const;
private:
const T* mLoc = nullptr;
mutable Vector<T> mBuf; // used if iterating over content on different rank
mutable SizeT mMin; // current global minimum position in the buffer
mutable SizeT mMax; // current global maximum position in the buffer
SizeT mBufSize;
protected:
SizeT mThisRank;
void setBuffer() const;
};
template <typename T>
@ -66,6 +68,7 @@ namespace CNORXZ
public:
typedef RAIndex<T> AI;
typedef typename AI::IB IB;
using typename AI::operator=;
DEFAULT_MEMBERS(RBIndex);
RBIndex(T* loc, const RangePtr& range, SizeT lexpos = 0);

View file

@ -32,7 +32,7 @@ namespace CNORXZ
YIndex ke(geom, geom->size());
auto mu = std::make_shared<CIndex>(geom->sub().range());
MArray<MArray<RangePtr>> rs(geom->sub().range());
rs(mu) = operation( [&](const SizeT i) { return rsplit(global->sub(i), geom->sub(i)); } , xpr(mu) );
rs(mu) = operation( [&](const SizeT i) { return rsplit(global->savesub(i), geom->savesub(i)); } , xpr(mu) );
Vector<RangePtr> elem(geom->dim());
for(; k != ke; ++k){
mu->ifor( operation( [&](const SizeT i, const MArray<RangePtr>& el){