diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index 9e93c0c..41efa29 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -380,6 +380,7 @@ namespace CNORXZ static_assert(std::is_fundamental::value, "got non-fundamental type"); CXZ_ASSERT(r->dim() == 1, "range cast into URange: source range must have dim = 1, got " << r->dim()); Sptr> o = nullptr; + // TODO: cast from CRange!!! o = transform(r); if(o) return o; o = transform(r); if(o) return o; o = transform(r); if(o) return o; diff --git a/src/opt/mpi/include/rrange.cc.h b/src/opt/mpi/include/rrange.cc.h index d8c4063..18e9bfe 100644 --- a/src/opt/mpi/include/rrange.cc.h +++ b/src/opt/mpi/include/rrange.cc.h @@ -72,8 +72,8 @@ namespace CNORXZ if constexpr(has_static_sub::value){ constexpr SizeT NI = index_dim::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::value){ constexpr SizeT NI = index_dim::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::exists){ - auto x = mI->meta(); const SizeT r = mK->lex(); - bcast(x, r); + if(r == getRankNumber()){ + o = mI->meta(); + } + bcast(o, r); } return o; } diff --git a/src/opt/mpi/tests/CMakeLists.txt b/src/opt/mpi/tests/CMakeLists.txt index eba47b0..3edd335 100644 --- a/src/opt/mpi/tests/CMakeLists.txt +++ b/src/opt/mpi/tests/CMakeLists.txt @@ -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}) diff --git a/src/opt/mpi/tests/rrange_unit_test.cc b/src/opt/mpi/tests/rrange_unit_test.cc index dc134b8..6f2b6ce 100644 --- a/src/opt/mpi/tests/rrange_unit_test.cc +++ b/src/opt/mpi/tests/rrange_unit_test.cc @@ -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 UI; MIndex mi(mRRange->sub(1)); + MIndex 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(xi.lex()) - s + static_cast(max*rx)); + } + }, NoF {} ); + } + + TEST_F(RRange_Test, Global) + { + RIndex 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(); }