MPI: RRange unit test works

This commit is contained in:
Christian Zimmermann 2024-03-16 23:30:35 +01:00
parent bd8970ae33
commit ef5b0ac456
4 changed files with 71 additions and 15 deletions

View file

@ -380,6 +380,7 @@ namespace CNORXZ
static_assert(std::is_fundamental<MetaT>::value, "got non-fundamental type");
CXZ_ASSERT(r->dim() == 1, "range cast into URange<Int>: source range must have dim = 1, got " << r->dim());
Sptr<URange<MetaT>> o = nullptr;
// TODO: cast from CRange!!!
o = transform<SizeT>(r); if(o) return o;
o = transform<Int>(r); if(o) return o;
o = transform<LInt>(r); if(o) return o;

View file

@ -72,8 +72,8 @@ namespace CNORXZ
if constexpr(has_static_sub<IndexI>::value){
constexpr SizeT NI = index_dim<IndexI>::value;
iter<0,NI>( [&](auto mu) {
const SizeT jmu = (IB::mPos / ilf[mu].val()*klf[mu].val()) %
i[mu]->lmax().val()*k[mu]->lmax().val();
const SizeT jmu = (IB::mPos / (ilf[mu].val()*klf[mu].val())) %
(i[mu]->lmax().val() * k[mu]->lmax().val());
r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val();
l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val();
}, NoF{} );
@ -81,8 +81,8 @@ namespace CNORXZ
else if constexpr( has_static_sub<IndexK>::value){
constexpr SizeT NI = index_dim<IndexK>::value;
iter<0,NI>( [&](auto mu) {
const SizeT jmu = (IB::mPos / ilf[mu].val()*klf[mu].val()) %
i[mu]->lmax().val()*k[mu]->lmax().val();
const SizeT jmu = (IB::mPos / (ilf[mu].val()*klf[mu].val())) %
(i[mu]->lmax().val() * k[mu]->lmax().val());
r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val();
l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val();
}, NoF{} );
@ -90,8 +90,8 @@ namespace CNORXZ
else {
const SizeT NI = mI->dim();
for(SizeT mu = 0; mu != NI; ++mu){
const SizeT jmu = (IB::mPos / ilf[mu].val()*klf[mu].val()) %
i[mu]->lmax().val()*k[mu]->lmax().val();
const SizeT jmu = (IB::mPos / (ilf[mu].val()*klf[mu].val())) %
(i[mu]->lmax().val() * k[mu]->lmax().val());
r += ( jmu / i[mu]->lmax().val() ) * klf[mu].val();
l += ( jmu % i[mu]->lmax().val() ) * ilf[mu].val();
}
@ -203,8 +203,10 @@ namespace CNORXZ
{
const SizeT r = mK->lex();
String o;
auto x = mI->stringMeta();
bcast(x, r);
if(r == getRankNumber()){
o = mI->stringMeta();
}
bcast(o, r);
return o;
}
@ -213,9 +215,11 @@ namespace CNORXZ
{
MetaType o;
if constexpr(Typemap<MetaType>::exists){
auto x = mI->meta();
const SizeT r = mK->lex();
bcast(x, r);
if(r == getRankNumber()){
o = mI->meta();
}
bcast(o, r);
}
return o;
}

View file

@ -4,4 +4,5 @@ include_directories(${CMAKE_SOURCE_DIR}/src/tests)
add_executable(mpirrutest rrange_unit_test.cc)
add_dependencies(mpirrutest cnorxz cnorxzmpi test_lib)
target_link_libraries(mpirrutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${MPI_LIBS} cnorxz cnorxzmpi test_lib)
add_test(NAME mpirrutest COMMAND mpirrutest)
set(MPI_TEST_COMMAND mpirun -n 4 mpirrutest)
add_test(NAME mpirrutest COMMAND ${MPI_TEST_COMMAND})

View file

@ -25,6 +25,29 @@ namespace
using Test::Numbers;
using namespace CNORXZ::mpi;
class MPIEnv : public ::testing::Environment
{
public:
MPIEnv(int argc, char** argv) : mArgc(argc), mArgv(argv) {}
virtual ~MPIEnv() override {}
virtual void SetUp() override
{
MPI_Init(&mArgc, &mArgv);
}
virtual void TearDown() override
{
MPI_Finalize();
}
protected:
int mArgc;
char** mArgv;
};
class RRange_Test : public ::testing::Test
{
protected:
@ -63,9 +86,38 @@ namespace
TEST_F(RRange_Test, Basics)
{
EXPECT_EQ(mRRange->size(), mGRange->size());
}
TEST_F(RRange_Test, Local)
{
typedef UIndex<Int> UI;
MIndex<UI,UI,UI,UI> mi(mRRange->sub(1));
MIndex<CIndex,CIndex,CIndex,CIndex> ri(mRRange->sub(0));
EXPECT_EQ(mi.lmax().val(), mGRange->size()/mRRange->sub(0)->size());
EXPECT_EQ(ri.lmax().val(), getNumRanks());
const SizeT rank = getRankNumber();
ri = rank;
iter<0,4>( [&](auto i) {
UI xi = *mi.pack()[i];
const SizeT max = xi.lmax().val();
const Int s = mGRange->sub(i)->size()/2;
const SizeT rx = ri.pack()[i]->lex();
for(; xi.lex() != max; ++xi){
EXPECT_EQ(*xi, static_cast<Int>(xi.lex()) - s + static_cast<Int>(max*rx));
}
}, NoF {} );
}
TEST_F(RRange_Test, Global)
{
RIndex<YIndex,YIndex> rgi(mRRange);
YIndex gi(mGRange);
for(SizeT c = 0; gi.lex() != gi.lmax().val(); ++gi, ++rgi, ++c) {
const String s1 = gi.stringMeta();
const String s2 = rgi.stringMeta();
EXPECT_EQ(rgi.lex(), c);
EXPECT_EQ(s1 ,s2);
}
}
}
@ -73,8 +125,6 @@ namespace
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
MPI_Init(&argc, &argv);
const int ret = RUN_ALL_TESTS();
MPI_Finalize();
return ret;
::testing::AddGlobalTestEnvironment( new MPIEnv(argc, argv) );
return RUN_ALL_TESTS();
}