From 354a275c125dd9566e6817b9334296c77ce3d619 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 9 Jul 2020 11:52:40 +0200 Subject: [PATCH] distinguish target object call depending on the controll index owner --- src/include/multi_array_operation.cc.h | 120 ++++++++++++++++--------- src/include/multi_array_operation.h | 17 ++-- 2 files changed, 87 insertions(+), 50 deletions(-) diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 55e0bf9..5b1c483 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -138,88 +138,117 @@ namespace MultiArrayTools * AssignmentExpr * ************************/ - template - AssignmentExpr2::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : + template + struct OpIndexResolve + {}; + + template <> + struct OpIndexResolve + { + + template + static inline size_t get(size_t start, ExtType last) + { + return last.val(); + } + + }; + + template <> + struct OpIndexResolve + { + template + static inline size_t get(size_t start, ExtType last) + { + return start; + } + }; + + + template + AssignmentExpr2::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} - template - inline void AssignmentExpr2::operator()(size_t start) + template + inline void AssignmentExpr2::operator()(size_t start) { ExtType last; - mDataPtr[last.val()] = mSec.get(last.next()); + mDataPtr[OpIndexResolve::get(start,last)] = mSec.get(last.next()); + //mDataPtr[last.val()] = mSec.get(last.next()); } - template - inline void AssignmentExpr2::operator()(size_t start, ExtType last) + template + inline void AssignmentExpr2::operator()(size_t start, ExtType last) { - mDataPtr[last.val()] = mSec.get(last.next()); + mDataPtr[OpIndexResolve::get(start,last)] = mSec.get(last.next()); } - template - typename AssignmentExpr2::ExtType - AssignmentExpr2::rootSteps(std::intptr_t iPtrNum) const + template + typename AssignmentExpr2::ExtType + AssignmentExpr2::rootSteps(std::intptr_t iPtrNum) const { return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) ); } - template - inline void AssignmentExpr2::operator()(size_t mlast, DExt last) + template + inline void AssignmentExpr2::operator()(size_t mlast, DExt last) { (*this)(mlast, std::dynamic_pointer_cast>(last)->ext()); } - template - inline DExt AssignmentExpr2::dRootSteps(std::intptr_t iPtrNum) const + template + inline DExt AssignmentExpr2::dRootSteps(std::intptr_t iPtrNum) const { return std::make_shared>(rootSteps(iPtrNum)); } - template - inline DExt AssignmentExpr2::dExtension() const + template + inline DExt AssignmentExpr2::dExtension() const { CHECK; return nullptr; //???!!! } - template - AddExpr::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) : + template + AddExpr::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} - template - inline void AddExpr::operator()(size_t start, ExtType last) + template + inline void AddExpr::operator()(size_t start, ExtType last) { - mDataPtr[last.val()] += mSec.get(last.next()); + mDataPtr[OpIndexResolve::get(start,last)] += mSec.get(last.next()); + //mDataPtr[start] += mSec.get(last.next()); //mDataPtr[start] += mSec.template get(last); } - template - inline void AddExpr::operator()(size_t start) + template + inline void AddExpr::operator()(size_t start) { ExtType last; - mDataPtr[last.val()] += mSec.get(last.next()); + mDataPtr[OpIndexResolve::get(start,last)] += mSec.get(last.next()); } - template - typename AddExpr::ExtType AddExpr::rootSteps(std::intptr_t iPtrNum) const + template + typename AddExpr::ExtType AddExpr::rootSteps(std::intptr_t iPtrNum) const { return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) ); //return mSec.rootSteps(iPtrNum); } - template - inline void AddExpr::operator()(size_t mlast, DExt last) + template + inline void AddExpr::operator()(size_t mlast, DExt last) { (*this)(mlast, std::dynamic_pointer_cast>(last)->ext()); } - template - inline DExt AddExpr::dRootSteps(std::intptr_t iPtrNum) const + template + inline DExt AddExpr::dRootSteps(std::intptr_t iPtrNum) const { return std::make_shared>(rootSteps(iPtrNum)); } - template - inline DExt AddExpr::dExtension() const + template + inline DExt AddExpr::dExtension() const { CHECK; return nullptr; //???!!! @@ -368,7 +397,6 @@ namespace MultiArrayTools template inline MetaOperationRoot& MetaOperationRoot::set(ET pos) { - assert(0); //(*mIndex) = pos.val(); return *this; } @@ -417,22 +445,24 @@ namespace MultiArrayTools template template auto OperationRoot::assign(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass> + -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass> + return mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in))); } template template auto OperationRoot::assignExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr2,OpClass>(mOrigDataPtr,*this,in))) + -> decltype(in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in))) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return in.loop(AssignmentExpr2,OpClass>(mOrigDataPtr,*this,in)); + return in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in)); } template @@ -449,10 +479,12 @@ namespace MultiArrayTools template template auto OperationRoot::plus(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AddExpr,OpClass>(mOrigDataPtr,*this,in)))) + -> decltype(mIndex.ifor(1,in.loop(AddExpr,OpClass,OpIndexAff::TARGET> + (mOrigDataPtr,*this,in)))) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return mIndex.ifor(1,in.loop(AddExpr,OpClass>(mOrigDataPtr,*this,in))); + return mIndex.ifor(1,in.loop(AddExpr,OpClass,OpIndexAff::TARGET> + (mOrigDataPtr,*this,in))); } template @@ -571,21 +603,21 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::assign(const OpClass& in) - -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass> + -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))) { - return mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass> + return mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in))); } template template auto ParallelOperationRoot::plus(const OpClass& in) - -> decltype(mIndex.pifor(1,in.loop(AddExpr,OpClass> + -> decltype(mIndex.pifor(1,in.loop(AddExpr,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))) { - return mIndex.pifor(1,in.loop(AddExpr,OpClass> + return mIndex.pifor(1,in.loop(AddExpr,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in))); } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 166d948..82303fd 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -107,7 +107,12 @@ namespace MultiArrayTools } }; - template + enum class OpIndexAff { + EXTERN = 0, + TARGET = 1 + }; + + template class AssignmentExpr2 : public ExpressionBase { private: @@ -138,7 +143,7 @@ namespace MultiArrayTools }; //template - template + template class AddExpr : public ExpressionBase { private: @@ -311,7 +316,7 @@ namespace MultiArrayTools template auto assign(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass> + -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))); template @@ -325,7 +330,7 @@ namespace MultiArrayTools template auto plus(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AddExpr,OpClass> + -> decltype(mIndex.ifor(1,in.loop(AddExpr,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))); template @@ -389,12 +394,12 @@ namespace MultiArrayTools template auto assign(const OpClass& in) - -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass> + -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))); template auto plus(const OpClass& in) - -> decltype(mIndex.pifor(1,in.loop(AddExpr,OpClass> + -> decltype(mIndex.pifor(1,in.loop(AddExpr,OpClass,OpIndexAff::TARGET> (mOrigDataPtr,*this,in)))); template