From 194cc4ebad53c94a2e3c1f74a3afefaddc638575 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 4 Mar 2024 23:55:11 +0100 Subject: [PATCH] WIP: add rrange --- src/opt/mpi/include/rrange.h | 100 +++++++++++++++++++++++ src/opt/mpi/tests/l_unit_test.cc | 136 +++++++++++++++++++++++++++++++ src/tests/l_unit_test.cc | 2 +- 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 src/opt/mpi/include/rrange.h create mode 100644 src/opt/mpi/tests/l_unit_test.cc diff --git a/src/opt/mpi/include/rrange.h b/src/opt/mpi/include/rrange.h new file mode 100644 index 0000000..4b4fb1d --- /dev/null +++ b/src/opt/mpi/include/rrange.h @@ -0,0 +1,100 @@ +// -*- C++ -*- +/** + + @file opt/mpi/include/rrange.h + @brief RRange and RIndex declaration + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + +**/ + +#ifndef __cxz_mpi_rrange_h__ +#define __cxz_mpi_rrange_h__ + +namespace CNORXZ +{ + /** **** + Specific index for RRanges. + */ + class RIndex : public IndexInterface>> + { + public: + typedef IndexInterface>> IB; + typedef RRange RangeType; + typedef Vector MetaType; + + private: + Sptr mRange; + Vector> mIs; // -> CPack!!! + YFormat mLexFormat; // = mFormat (rank geometry is fixed and unique) + UPos mPMax = 0; // = mLMax (same reason) + } + + /** **** + Specialization: RIndex is a multi-index. + @see index_is_multi + */ + template <> + struct index_is_multi + { static constexpr bool value = true; }; + + /** **** + Specialization: RIndex has sub-indices. + @see has_sub + */ + template <> + struct has_sub + { static constexpr bool value = true; }; + + /** **** + Specific factory for RRange. + */ + class RRangeFactory : public RangeFactoryBase + { + public: + /** Construct and setup factory. + @param geom SizeT vector specifying the rank geometry + */ + RRangeFactory(const Vector& geom); + + private: + RRangeFactory() = default; + virtual void make() override final; + + Vector mGeom; + }; + + /** **** + Multi-dimensional range specifying the rank coordinate system + */ + class RRange : public RangeInterface + { + public: + typedef RangeBase RB; + typedef RIndex IndexType; + + friend RRangeFactory; + + virtual RangePtr sub(SizeT i) const override final; + virtual MArray sub() const override final; + virtual SizeT size() const override final; + virtual SizeT dim() const override final; + virtual String stringMeta(SizeT pos) const override final; + virtual const TypeInfo& type() const override final; + virtual const TypeInfo& metaType() const override final; + virtual RangePtr extend(const RangePtr& r) const override final; + + private: + + RRange() = default; + RRange(const RRange& a) = delete; + RRange(const Vector& rvec); + + Vector mRVec; + + virtual Vector key() const override final; + }; +} + +#endif diff --git a/src/opt/mpi/tests/l_unit_test.cc b/src/opt/mpi/tests/l_unit_test.cc new file mode 100644 index 0000000..cb03af3 --- /dev/null +++ b/src/opt/mpi/tests/l_unit_test.cc @@ -0,0 +1,136 @@ +// -*- C++ -*- +/** + + @file opt/mpi/tests/l_unit_test.cc + @brief L unit tests. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + +**/ + +#include +#include + +#include "gtest/gtest.h" + +#include "cnorxz.h" +#include "test_numbers.h" + +namespace +{ + using namespace CNORXZ; + using Test::Numbers; + + class L_Test : public ::testing::Test + { + protected: + + L_Test() + { + auto a4 = Arr { 0,1,2,3 }; + auto a3 = Arr { 0,1,2 }; + mSpinR = std::dynamic_pointer_cast> ( SRangeFactory(a4).create() ); + mColorR = std::dynamic_pointer_cast> ( SRangeFactory(a3).create() ); + mSpatialR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); + mTemporalR = std::dynamic_pointer_cast ( CRangeFactory(24).create() ); + mLocSR = std::dynamic_pointer_cast ( CRangeFactory(4).create() ); + mLocTR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); + mRaSR = std::dynamic_pointer_cast ( CRangeFactory(2).create() ); + mRaTR = std::dynamic_pointer_cast ( CRangeFactory(3).create() ); + mData = MArray>(yrange({mRaTR,mRaSR,mRaSR,mRaSR,mLocTR,mLocSR,mLocSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR})); + mDataFormat = mData.begin().format(); + auto vf = mDataFormat.all(); + vf[0] = mDataFormat[0]; + vf[1] = mDataFormat[4]; + vf[2] = mDataFormat[1]; + vf[3] = mDataFormat[5]; + vf[4] = mDataFormat[2]; + vf[5] = mDataFormat[6]; + vf[6] = mDataFormat[3]; + vf[7] = mDataFormat[7]; + mViewFormat = YFormat(vf); + mView = Slice>(yrange({mRaTR,mLocTR,mRaSR,mLocSR,mRaSR,mLocSR,mRaSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR}), &mData, mViewFormat, 0); + mLocSI = CIndex(mLocSR); + mLocTI = CIndex(mLocTR); + mRaSI = CIndex(mRaSR); + mRaTI = CIndex(mRaTR); + mSpinI = SIndex(mSpinR); + mColorI = SIndex(mColorR); + } + + Sptr> mSpinR; + Sptr> mColorR; + Sptr mSpatialR; + Sptr mTemporalR; + Sptr mLocSR; + Sptr mLocTR; + Sptr mRaSR; + Sptr mRaTR; + + MArray> mData; + Slice> mView; + YFormat mDataFormat; + YFormat mViewFormat; + + CIndex mLocSI; + CIndex mLocTI; + CIndex mRaSI; + CIndex mRaTI; + SIndex mSpinI; + SIndex mColorI; + MIndex mSpatialI; + MIndex mTemporalI; + //GMIndex,CIndex,CIndex> mSpatialDI; + //GMIndex,CIndex,CIndex> mTemporalDI; + }; + + TEST_F(L_Test, Basic) + { + EXPECT_EQ(mData.size(), mView.size()); + } + + TEST_F(L_Test, Assign) + { + auto x0l = std::make_shared(mLocTI); + auto x0r = std::make_shared(mRaTI); + auto x0 = gmindexPtr(x0r*x0l); + auto x0a = gmindexPtr(x0r*x0l); + auto x1l = std::make_shared(mLocSI); + auto x1r = std::make_shared(mRaSI); + auto x1 = gmindexPtr(x1r*x1l); + auto x1a = gmindexPtr(x1r*x1l); + auto x2l = std::make_shared(mLocSI); + auto x2r = std::make_shared(mRaSI); + auto x2 = gmindexPtr(x2r*x2l); + auto x2a = gmindexPtr(x2r*x2l); + auto x3l = std::make_shared(mLocSI); + auto x3r = std::make_shared(mRaSI); + auto x3 = gmindexPtr(x3r*x3l); + auto x3a = gmindexPtr(x3r*x3l); + auto x = gmindexPtr(x0*x1*x2*x3); + auto xx = gmindexPtr(x0a*x1a*x2a*x3a); + auto al = std::make_shared>(mSpinI); + auto be = std::make_shared>(mSpinI); + auto a = std::make_shared>(mColorI); + auto b = std::make_shared>(mColorI); + + EXPECT_TRUE(x0->formatIsTrivial()); + EXPECT_TRUE(x1->formatIsTrivial()); + EXPECT_TRUE(x2->formatIsTrivial()); + EXPECT_TRUE(x3->formatIsTrivial()); + EXPECT_TRUE(x->formatIsTrivial()); + + auto fs = [&](SizeT i) { return i >= mSpatialR->size()/2 ? static_cast(i - mSpatialR->size()) : static_cast(i); }; + auto ft = [&](SizeT i) { return i >= mTemporalR->size()/2 ? static_cast(i - mTemporalR->size()) : static_cast(i); }; + EXPECT_TRUE(mindexPtr(xx*al*a*be*b)->formatIsTrivial()); + + mView(gmindexPtr(xx*al*a*be*b)) = operation( [](Int a0, Int a1, Int a2, Int a3) { Arr x{a0,a1,a2,a3}; return x; }, + mapop(x0, ft), mapop(x1, fs), mapop(x2, fs), mapop(x3, fs) ); + EXPECT_FALSE(xx->formatIsTrivial()); + for(*x = 0; x->lex() != x->lmax().val(); ++(*x)){ + Arr m{ ft(x0->lex()), fs(x1->lex()), fs(x2->lex()), fs(x3->lex()) }; + EXPECT_EQ( mView[x*al*a*be*b], m ); + } + } +} diff --git a/src/tests/l_unit_test.cc b/src/tests/l_unit_test.cc index ae7db0f..d4576bb 100644 --- a/src/tests/l_unit_test.cc +++ b/src/tests/l_unit_test.cc @@ -127,7 +127,7 @@ namespace mView(gmindexPtr(xx*al*a*be*b)) = operation( [](Int a0, Int a1, Int a2, Int a3) { Arr x{a0,a1,a2,a3}; return x; }, mapop(x0, ft), mapop(x1, fs), mapop(x2, fs), mapop(x3, fs) ); - EXPECT_TRUE(x->formatIsTrivial()); + EXPECT_FALSE(xx->formatIsTrivial()); for(*x = 0; x->lex() != x->lmax().val(); ++(*x)){ Arr m{ ft(x0->lex()), fs(x1->lex()), fs(x2->lex()), fs(x3->lex()) }; EXPECT_EQ( mView[x*al*a*be*b], m );