partial fix in multi-threading relevant code
This commit is contained in:
parent
e08c477f0e
commit
4e7e57fcb9
6 changed files with 145 additions and 24 deletions
|
@ -50,9 +50,7 @@ namespace MultiArrayTools
|
|||
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
|
||||
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
|
||||
std::array<size_t,1>({1}), std::array<size_t,1>({0}))
|
||||
{
|
||||
*mMa = 0;
|
||||
}
|
||||
{}
|
||||
|
||||
template <typename T, class Operation, class... Ranges>
|
||||
OpH<OperationRoot<T,Ranges...>> DynamicOuterOp<T,Operation,Ranges...>::get(const DExtT& pos) const
|
||||
|
|
|
@ -75,11 +75,15 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<MultiArray<T,Ranges...>> mMa;
|
||||
OpH<OperationRoot<T,Ranges...>> mProto;
|
||||
|
||||
|
||||
|
||||
typedef ILoop<std::tuple<OperationRoot<T,Ranges...>,Operation>,
|
||||
std::tuple<std::shared_ptr<typename Ranges::IndexType>...>,
|
||||
std::tuple<std::shared_ptr<MultiArray<T,Ranges...>>>,
|
||||
std::tuple<decltype(mProto.mOp->assign( mOp, mkMIndex(std::shared_ptr<typename Ranges::IndexType>()...) ))>> LoopT;
|
||||
|
||||
|
||||
|
||||
mutable LoopT mL;
|
||||
|
||||
public:
|
||||
|
|
|
@ -131,6 +131,13 @@ namespace MultiArrayTools
|
|||
AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec);
|
||||
AssignmentExpr2(const AssignmentExpr2& in) = default;
|
||||
AssignmentExpr2(AssignmentExpr2&& in) = default;
|
||||
AssignmentExpr2& operator=(const AssignmentExpr2& in) = default;
|
||||
AssignmentExpr2& operator=(AssignmentExpr2&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<AssignmentExpr2<T,Target,OpClass,OIA>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
|
@ -160,6 +167,13 @@ namespace MultiArrayTools
|
|||
GetExpr(const OpClass& sec, const NextExpr& nexpr);
|
||||
GetExpr(const GetExpr& in) = default;
|
||||
GetExpr(GetExpr&& in) = default;
|
||||
GetExpr& operator=(const GetExpr& in) = default;
|
||||
GetExpr& operator=(GetExpr&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<GetExpr<OpClass,NextExpr>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
|
@ -201,6 +215,13 @@ namespace MultiArrayTools
|
|||
AddExpr(T* dataPtr, const Target& tar, const OpClass& sec);
|
||||
AddExpr(const AddExpr& in) = default;
|
||||
AddExpr(AddExpr&& in) = default;
|
||||
AddExpr& operator=(const AddExpr& in) = default;
|
||||
AddExpr& operator=(AddExpr&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<AddExpr<T,Target,OpClass,OIA>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
|
|
|
@ -126,6 +126,11 @@ namespace MultiArrayHelper
|
|||
const std::array<size_t,LTpSize>& umpos, const std::array<size_t,VarTpSize>& setzero) :
|
||||
mOpTp(opTp), mIndTp(indTp), mVarTp(varTp), mLTp(lTp), mUmpos(umpos), mSetzero(setzero) {}
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<ILoop<OpTp,IndTp,VarTp,LTp>>(*this);
|
||||
}
|
||||
|
||||
inline size_t operator()(size_t mpos, ExtType pos)
|
||||
{
|
||||
NN<VarTpSize-1>::zero(mVarTp, mSetzero);
|
||||
|
@ -229,7 +234,7 @@ namespace MultiArrayHelper
|
|||
// if instance copied to different thread, the "copy" will be newly created from this function
|
||||
// -> ensures that there is NO SHARED WORKSPACE
|
||||
template <class CF>
|
||||
class PILoop
|
||||
class PILoop : public ExpressionBase
|
||||
{
|
||||
private:
|
||||
size_t mThreadId = 0;
|
||||
|
@ -268,10 +273,25 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
PILoop(const CF& cf) : mThreadId(omp_get_thread_num()), mCF(cf), mL(mCF()) {}
|
||||
/*
|
||||
virtual void ensureThread() override final
|
||||
{
|
||||
VCHECK(omp_get_thread_num());
|
||||
//if(static_cast<int>(mThreadId) != omp_get_thread_num()){
|
||||
mThreadId = omp_get_thread_num();
|
||||
mL = mCF();
|
||||
//}
|
||||
}
|
||||
*/
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<PILoop<CF>>(*this);
|
||||
}
|
||||
|
||||
inline size_t operator()(size_t mpos, ExtType pos)
|
||||
{
|
||||
return mL(mpos, pos);
|
||||
mL(mpos, pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto rootSteps(std::intptr_t i = 0) const
|
||||
|
@ -284,6 +304,28 @@ namespace MultiArrayHelper
|
|||
{
|
||||
return mL.var();
|
||||
}
|
||||
|
||||
virtual void operator()(size_t mlast, DExt last) override final
|
||||
{
|
||||
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||
}
|
||||
|
||||
virtual void operator()(size_t mlast = 0) override final
|
||||
{
|
||||
ExtType last = rootSteps();
|
||||
last.zero();
|
||||
operator()(mlast, last);
|
||||
}
|
||||
|
||||
virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||
}
|
||||
|
||||
virtual DExt dExtension() const override final
|
||||
{
|
||||
return nullptr; //!!
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -112,8 +112,8 @@ namespace MultiArrayHelper
|
|||
DExtTX() { mDExt = std::make_shared<ExtT<None>>(); }
|
||||
DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
|
||||
DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
|
||||
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); }
|
||||
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); }
|
||||
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
|
||||
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
|
||||
explicit DExtTX(const DExt& in) : mDExt(in) {}
|
||||
/*
|
||||
template <class Y>
|
||||
|
@ -173,6 +173,8 @@ namespace MultiArrayHelper
|
|||
ExpressionBase& operator=(const ExpressionBase& in) = default;
|
||||
ExpressionBase& operator=(ExpressionBase&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const = 0;
|
||||
|
||||
virtual void operator()(size_t mlast, DExt last) = 0;
|
||||
virtual void operator()(size_t mlast = 0) = 0;
|
||||
|
||||
|
@ -264,6 +266,10 @@ namespace MultiArrayHelper
|
|||
SingleExpression(const IndexClass* indPtr,
|
||||
Expr expr);
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<SingleExpression<IndexClass,Expr>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
inline void operator()(size_t mlast, ExtType last);
|
||||
|
@ -313,6 +319,10 @@ namespace MultiArrayHelper
|
|||
SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
|
||||
const vector<size_t>* subset, Expr expr);
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<SubExpr<IndexClass,Expr>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
inline void operator()(size_t mlast, ExtType last) ;
|
||||
|
@ -362,6 +372,11 @@ namespace MultiArrayHelper
|
|||
For(const IndexClass* indPtr,
|
||||
size_t step, Expr expr);
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<For<IndexClass,Expr,FT>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
inline void operator()(size_t mlast, ExtType last) ;
|
||||
inline void operator()(size_t mlast = 0) override final;
|
||||
|
@ -410,6 +425,11 @@ namespace MultiArrayHelper
|
|||
PFor(const IndexClass* indPtr,
|
||||
size_t step, Expr expr);
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<PFor<IndexClass,Expr>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
inline void operator()(size_t mlast, ExtType last) ;
|
||||
inline void operator()(size_t mlast = 0) override final;
|
||||
|
@ -431,8 +451,9 @@ namespace MultiArrayHelper
|
|||
class DynamicExpression : public ExpressionBase
|
||||
{
|
||||
private:
|
||||
DynamicExpression() = default;
|
||||
DynamicExpression() : mThreadId(omp_get_thread_num()) {}
|
||||
|
||||
size_t mThreadId;
|
||||
std::shared_ptr<ExpressionBase> mNext;
|
||||
|
||||
public:
|
||||
|
@ -440,10 +461,29 @@ namespace MultiArrayHelper
|
|||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t SIZE = 0;
|
||||
|
||||
DynamicExpression(const DynamicExpression& in) = default;
|
||||
DynamicExpression(DynamicExpression&& in) = default;
|
||||
DynamicExpression& operator=(const DynamicExpression& in) = default;
|
||||
DynamicExpression& operator=(DynamicExpression&& in) = default;
|
||||
DynamicExpression(const DynamicExpression& in) :
|
||||
mThreadId(omp_get_thread_num()),
|
||||
mNext( (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
|
||||
in.mNext : in.mNext->deepCopy()) {}
|
||||
DynamicExpression(DynamicExpression&& in) :
|
||||
mThreadId(omp_get_thread_num()),
|
||||
mNext( (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
|
||||
in.mNext : in.mNext->deepCopy()) {}
|
||||
DynamicExpression& operator=(const DynamicExpression& in)
|
||||
{
|
||||
mThreadId = omp_get_thread_num();
|
||||
mNext = (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
|
||||
in.mNext : in.mNext->deepCopy();
|
||||
return *this;
|
||||
}
|
||||
|
||||
DynamicExpression& operator=(DynamicExpression&& in)
|
||||
{
|
||||
mThreadId = omp_get_thread_num();
|
||||
mNext = (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
|
||||
in.mNext : in.mNext->deepCopy();
|
||||
return *this;
|
||||
}
|
||||
|
||||
DynamicExpression(const std::shared_ptr<ExpressionBase>& next) :
|
||||
mNext(next)
|
||||
|
@ -457,6 +497,11 @@ namespace MultiArrayHelper
|
|||
template <class Expr>
|
||||
DynamicExpression(Expr ex) : mNext( std::make_shared<Expr>(ex) ) {}
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<DynamicExpression>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
inline void operator()(size_t mlast, DExtT last) { (*this)(mlast,last.get()); }
|
||||
inline void operator()(size_t mlast = 0) override final;
|
||||
|
@ -495,6 +540,11 @@ namespace MultiArrayHelper
|
|||
|
||||
ExpressionHolder(DynamicExpression expr);
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<ExpressionHolder<Expr>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
inline void operator()(size_t mlast, ExtType last) ;
|
||||
inline void operator()(size_t mlast = 0) override final;
|
||||
|
|
|
@ -137,15 +137,21 @@ namespace
|
|||
resx2(i1,di4) = mkDynOp(ma1(i1,di1) * ma2(i1,di2));
|
||||
resx3(i1,di4) = mkDynOp(mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2)));
|
||||
|
||||
auto op1 = mkDynOutOp((ma1(i1,di1) * ma2(i1,di2)), ci4_1, ci4_2);
|
||||
//auto op1 = mkDynOutOp((ma1(i1,di1) * ma2(i1,di2)), ci4_1, ci4_2);
|
||||
//auto opr = resx4(i1,di4);
|
||||
auto op1x = (ma1(i1,di1) * ma2(i1,di2));
|
||||
auto opr = resx4(i1,di4);
|
||||
|
||||
auto loop = mkILoop(std::make_tuple(opr,op1,*op1.data()->mOp), std::make_tuple(ci4_1, ci4_2),
|
||||
auto loop = mkPILoop
|
||||
( [&op1x,&opr,&xx,this](){
|
||||
auto op1 = mkDynOutOp(op1x, ci4_1, ci4_2);
|
||||
return mkGetExpr(op1,mkILoop(std::make_tuple(opr,op1,*op1.data()->mOp), std::make_tuple(ci4_1, ci4_2),
|
||||
std::make_tuple(xx),
|
||||
std::make_tuple(opr.assign( *op1.data()->mOp, mkMIndex(ci4_1, ci4_2) )),
|
||||
std::array<size_t,1>({1}), std::array<size_t,1>({0}));
|
||||
std::array<size_t,1>({1}), std::array<size_t,1>({0}))); } );
|
||||
|
||||
mi->ifor(1, mkGetExpr(op1,loop))();
|
||||
//loop.dummy();
|
||||
mi->pifor(1,loop)();
|
||||
|
||||
auto i2_1 = imap.at("i2_1");
|
||||
auto i2_2 = imap.at("i2_2");
|
||||
|
|
Loading…
Reference in a new issue