This commit is contained in:
Christian Zimmermann 2020-08-28 13:46:12 +02:00
parent 7afd193d09
commit cb6a6ccdb3
4 changed files with 59 additions and 24 deletions

View file

@ -46,20 +46,21 @@ namespace MultiArrayTools
const std::shared_ptr<typename Ranges::IndexType>&... inds)
: mOp(op),
mMa(std::make_shared<MultiArray<T,Ranges...>>(mkArray<T>(inds->range()...))),
mProto((*mMa)(inds...))
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
mL(std::make_tuple(mProto.mOp,mOp), std::make_tuple(inds...),
std::make_tuple(mMa), std::make_tuple(mProto.mOp.assign( mOp )),
std::array<size_t,1>({0}), std::array<size_t,1>({0}))
{
/*
auto ll = mkILoop(std::make_tuple(mProto.mOp,mOp), std::make_tuple(inds...),
std::make_tuple(mMa), std::make_tuple(mProto.mOp.assign( mOp )),
std::array<size_t,1>({0}), std::array<size_t,1>({0}));
*/
VCHECK(reinterpret_cast<std::intptr_t>(mProto.mOp.data()));
VCHECK(reinterpret_cast<std::intptr_t>(mMa->data()));
}
template <typename T, class Operation, class... Ranges>
OpH<OperationRoot<T,Ranges...>> DynamicOuterOp<T,Operation,Ranges...>::get(const DExtT& pos) const
{
mOp.get(pos.expl<ET>());
//mL();
CHECK;
//mOp.get(pos.expl<ET>());
//mL(0,pos.expl<ET>());
// execute assignment... care about threads!!!
return mProto.mOp; // empty
}
@ -68,6 +69,7 @@ namespace MultiArrayTools
DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>&
DynamicOuterOp<T,Operation,Ranges...>::set(const DExtT& pos)
{
CHECK;
mOp.set(pos.expl<ET>());
return *this;
}
@ -75,18 +77,21 @@ namespace MultiArrayTools
template <typename T, class Operation, class... Ranges>
DExtT DynamicOuterOp<T,Operation,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{
return DExtT(mkDExt(mkExtT(mOp.rootSteps(iPtrNum))),None(0));
CHECK;
return DExtT(mkDExt(mkExtT(mL.rootSteps(iPtrNum))),None(0));
}
template <typename T, class Operation, class... Ranges>
DynamicExpression DynamicOuterOp<T,Operation,Ranges...>::loop(const DynamicExpression& exp) const
{
return mOp.loop(exp);
CHECK;
return mOp.loop(exp); // ???!!
}
template <typename T, class Operation, class... Ranges>
const OpH<OperationRoot<T,Ranges...>>* DynamicOuterOp<T,Operation,Ranges...>::data() const
{
CHECK;
return &mProto;
}
@ -94,6 +99,7 @@ namespace MultiArrayTools
std::shared_ptr<DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>>
DynamicOuterOp<T,Operation,Ranges...>::deepCopy() const
{
CHECK;
return std::make_shared<DynamicOuterOp<T,Operation,Ranges...>>(*this);
}

View file

@ -73,16 +73,16 @@ namespace MultiArrayTools
//OperationRoot<T,Ranges...> mProto;
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 ))>> LoopT;
LoopT mL;
*/
mutable LoopT mL;
public:
typedef decltype(mOp.rootSteps()) ET;
typedef decltype(mL.rootSteps()) ET;
//typedef decltype(std::declval<Operation>().rootSteps()) ET;
DynamicOuterOp() = default;

View file

@ -7,6 +7,7 @@
#include <tuple>
#include <array>
#include <omp.h>
#include "xfor.h"
namespace MultiArrayHelper
{
@ -98,7 +99,7 @@ namespace MultiArrayHelper
};
template <class OpTp, class IndTp, class VarTp, class LTp>
class ILoop
class ILoop : public ExpressionBase
{
private:
static constexpr size_t LTpSize = std::tuple_size<LTp>::value;
@ -121,7 +122,7 @@ namespace MultiArrayHelper
ILoop() { assert(omp_get_thread_num() == 0); }
ILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp,
ILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp,
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) {}
@ -143,6 +144,28 @@ namespace MultiArrayHelper
{
return mVarTp;
}
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; //!!
}
};
template <size_t N>

View file

@ -125,24 +125,30 @@ namespace
auto resx2 = res1;
auto resx3 = res1;
auto resx4 = res1;
//auto xx = std::make_shared<decltype(resx4)>(resx4);
auto xx = std::make_shared<decltype(resx4)>(resx4);
res1(i1,di4) = ma1(i1,di1) * ma2(i1,di2);
resx1(i1,di4) = mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2));
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);
/**auto opr = resx4(i1,di4);
auto loop = mkILoop(std::make_tuple(opr,op1), std::make_tuple(ci4),
std::make_tuple(xx), std::make_tuple(opr.assign( op1.data()->mOp )),
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),
std::make_tuple(xx), std::make_tuple(opr.assign( op1.data()->mOp, ci4 )),
//std::make_tuple(), std::make_tuple(),
std::array<size_t,1>({1}), std::array<size_t,1>({0}));
*/
//std::array<size_t,0>(), std::array<size_t,0>());
//!!!!
/*
auto loop = mkILoop(std::make_tuple(opr,op1x), std::make_tuple(ci4),
std::make_tuple(xx), std::make_tuple(opr.assign( op1x, ci4 )),
//std::make_tuple(), std::make_tuple(),
std::array<size_t,1>({1}), std::array<size_t,1>({0}));
*/
//mi->ifor(1, loop)();
mi->ifor(1, loop)();
//mi->ifor(1, opr.assign( op1.data()->mOp ))();
auto i2_1 = imap.at("i2_1");
auto i2_2 = imap.at("i2_2");
auto i3_1 = imap.at("i3_1");