diff --git a/src/include/map_range.h b/src/include/map_range.h index 6831cc6..1181a70 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -57,6 +57,7 @@ namespace MultiArrayTools //typedef SingleIndex OIType; static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE + Op::SIZE; + static constexpr size_t NHLAYER = Expr::NHLAYER + 1; private: OpExpr() = default; diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index dea6150..ab0f068 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -346,7 +346,7 @@ namespace MultiArrayTools template inline const V& ConstOperationRoot::vget(ET pos) const { - VCHECK(pos.val()); + //VCHECK(pos.val()); return *(reinterpret_cast(mDataPtr+pos.val())); } @@ -665,7 +665,7 @@ namespace MultiArrayTools template inline V& OperationRoot::vget(ET pos) const { - VCHECK(pos.val()); + //VCHECK(pos.val()); return *(reinterpret_cast(mDataPtr+pos.val())); } @@ -740,12 +740,12 @@ namespace MultiArrayTools template auto ParallelOperationRoot::asx(const OpClass& in) const -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in)))) + (mOrigDataPtr,*this,in))).template vec()) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return mIndex.pifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))); + (mOrigDataPtr,*this,in))).template vec(); } template @@ -763,11 +763,11 @@ namespace MultiArrayTools template auto ParallelOperationRoot::asx(const OpClass& in, const std::shared_ptr& i) const -> decltype(i->pifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in)))) + (mOrigDataPtr,*this,in))).template vec()) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return i->pifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))); + (mOrigDataPtr,*this,in))).template vec(); } template @@ -814,7 +814,7 @@ namespace MultiArrayTools template ParallelOperationRoot& ParallelOperationRoot::operator=(const OpClass& in) { - assign(in)(); + VExec::template exec(*this,in); return *this; } @@ -822,7 +822,7 @@ namespace MultiArrayTools template ParallelOperationRoot& ParallelOperationRoot::operator+=(const OpClass& in) { - plus(in)(); + VExec::template exec(*this,in); return *this; } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 3ac063e..bb84e8a 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -259,7 +259,7 @@ namespace MultiArrayTools template static inline void f(T*& t, size_t pos, const Op& op, ExtType e) { - VCHECK(pos); + //VCHECK(pos); VFunc::selfApply(*reinterpret_cast(t+pos),op.template vget(e)); } }; @@ -332,6 +332,7 @@ namespace MultiArrayTools public: static constexpr size_t LAYER = 0; + static constexpr size_t NHLAYER = 0; static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE; typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType; @@ -371,7 +372,8 @@ namespace MultiArrayTools public: static constexpr size_t LAYER = 0; - static constexpr size_t SIZE = RootSum::SIZE; + static constexpr size_t NHLAYER = 0; + static constexpr size_t SIZE = RootSum::SIZE; typedef decltype(RootSumN::rootSteps(mOps,0) ) ExtType; MOp(const Ops&... exprs); @@ -410,6 +412,7 @@ namespace MultiArrayTools public: static constexpr size_t LAYER = 0; + static constexpr size_t NHLAYER = 0; static constexpr size_t SIZE = OpClass::SIZE + NextExpr::SIZE; typedef decltype(mSec.rootSteps(0).extend( mNExpr.rootSteps(0) ) ) ExtType; @@ -699,7 +702,7 @@ namespace MultiArrayTools template auto asx(const OpClass& in) const -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in)))); + (mOrigDataPtr,*this,in))).template vec()); template auto asxExpr(const OpClass& in) const @@ -708,7 +711,7 @@ namespace MultiArrayTools template auto asx(const OpClass& in, const std::shared_ptr& i) const -> decltype(i->pifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in)))); + (mOrigDataPtr,*this,in))).template vec()); template auto assign(const OpClass& in) const diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index d7b7e1e..372c334 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -271,6 +271,7 @@ namespace MultiArrayHelper static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE; + static constexpr size_t NHLAYER = Expr::NHLAYER + 1; SingleExpression(const SingleExpression& in) = default; SingleExpression& operator=(const SingleExpression& in) = default; @@ -326,6 +327,7 @@ namespace MultiArrayHelper static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE + 1; + static constexpr size_t NHLAYER = Expr::NHLAYER + 1; SubExpr(const SubExpr& in) = default; SubExpr& operator=(const SubExpr& in) = default; @@ -410,6 +412,36 @@ namespace MultiArrayHelper } }; + template + struct NHLayer + { + template + static constexpr size_t get() + { + return Expr::NHLAYER + 1; + } + }; + + template + struct NHLayer + { + template + static constexpr size_t get() + { + return 0; + } + }; + + template <> + struct NHLayer + { + template + static constexpr size_t get() + { + return Expr::LAYER; + } + }; + template class For : public ExpressionBase { @@ -430,11 +462,12 @@ namespace MultiArrayHelper public: typedef ExpressionBase EB; - + static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE; static constexpr size_t MAX = RangeType::SIZE / DIV; - + static constexpr size_t NHLAYER = (FT == ForType::HIDDEN) ? 0 : Expr::NHLAYER + 1; + For(const For& in) = default; For& operator=(const For& in) = default; For(For&& in) = default; @@ -455,8 +488,10 @@ namespace MultiArrayHelper virtual std::intptr_t vI() const override final { - if(mStep == 1 and LAYER == 1 and mMax % DIV == 0){ - VCHECK(LAYER); + if(mStep == 1 and NHLAYER == 1 and mMax % DIV == 0){ + //if(mStep == 1 and mMax % DIV == 0){ + //VCHECK(LAYER); + //VCHECK(NHLAYER); return reinterpret_cast(mIndPtr); } return mExpr.vI(); @@ -465,9 +500,9 @@ namespace MultiArrayHelper template auto vec() const { - typedef typename MkVFor(-1)>:: - template type::template mk(mExpr)),FT> oType; - return oType(mIndPtr,mStep,MkVExpr::template mk(mExpr)); + typedef typename MkVFor(-1)>:: + template type::template mk(mExpr)),FT> oType; + return oType(mIndPtr,mStep,MkVExpr::template mk(mExpr)); } inline void operator()(size_t mlast, DExt last) override final; @@ -509,6 +544,7 @@ namespace MultiArrayHelper static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE; static constexpr size_t MAX = RangeType::SIZE / DIV; + static constexpr size_t NHLAYER = Expr::NHLAYER + 1; PFor(const PFor& in) = default; PFor& operator=(const PFor& in) = default; @@ -524,8 +560,10 @@ namespace MultiArrayHelper //virtual size_t divResid() const override final { return mMax % DIV + MkVExpr::divResid(mExpr); } virtual std::intptr_t vI() const override final { - if(mStep == 1 and LAYER == 1 and mMax % DIV == 0){ - VCHECK(LAYER); + if(mStep == 1 and NHLAYER == 1 and mMax % DIV == 0){ + //if(mStep == 1 and mMax % DIV == 0){ + //VCHECK(LAYER); + //VCHECK(LAYER); return reinterpret_cast(mIndPtr); } return mExpr.vI(); @@ -534,9 +572,9 @@ namespace MultiArrayHelper template auto vec() const { - typedef typename MkVFor(-1)>:: - template ptype::template mk(mExpr))> oType; - return oType(mIndPtr,mStep,MkVExpr::template mk(mExpr)); + typedef typename MkVFor(-1)>:: + template ptype::template mk(mExpr))> oType; + return oType(mIndPtr,mStep,MkVExpr::template mk(mExpr)); } virtual std::shared_ptr deepCopy() const override final @@ -574,6 +612,7 @@ namespace MultiArrayHelper static constexpr size_t LAYER = 0; static constexpr size_t SIZE = 0; + static constexpr size_t NHLAYER = 0; DynamicExpression(const DynamicExpression& in) : mThreadId(omp_get_thread_num()), @@ -649,6 +688,7 @@ namespace MultiArrayHelper static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE; + static constexpr size_t NHLAYER = Expr::NHLAYER + 1; ExpressionHolder(const ExpressionHolder& in) = default; ExpressionHolder(ExpressionHolder&& in) = default; diff --git a/src/tests/op_perf_test.cc b/src/tests/op_perf_test.cc index 131db7e..90c711d 100644 --- a/src/tests/op_perf_test.cc +++ b/src/tests/op_perf_test.cc @@ -174,8 +174,8 @@ namespace { auto beta = MAT::getIndex(); auto gamma = MAT::getIndex(); auto delta = MAT::getIndex(); - //auto deltap = MAT::getIndex(); - auto deltap = MAT::getIndex>(); + auto deltap = MAT::getIndex(); + //auto deltap = MAT::getIndex>(); auto mix = MAT::mkMIndex( jj, alpha, beta, gamma ); @@ -217,8 +217,8 @@ namespace { auto begin = std::chrono::system_clock::now(); //for(size_t i = 0; i != os; ++i){ - //res1(ii ,delta, deltap).par() += ma(ii, delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); - tcast(res1)(ii ,delta, deltap).par() += tcast(ma)(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); + res1(ii ,delta, deltap).par() += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); + //tcast(res1)(ii ,delta, deltap).par() += tcast(ma)(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); //} auto end = std::chrono::system_clock::now(); std::cout << "MultiArray time: " << std::chrono::duration(end-begin).count()