From 8b1f19a3fa45793739739403e15a9e40514a2b1d Mon Sep 17 00:00:00 2001 From: Lauffenburger Thomas Date: Tue, 1 Aug 2017 11:06:05 +0200 Subject: [PATCH] Optimized algo for PlayGround --- src/engine/AbstractPoint.hxx | 2 +- src/engine/BagPoint.cxx | 4 +- src/engine/BagPoint.hxx | 2 +- src/engine/Bloc.cxx | 4 +- src/engine/Bloc.hxx | 2 +- src/engine/Bloc_impl.cxx | 7 +- src/engine/CMakeLists.txt | 2 + src/engine/DynParaLoop.cxx | 18 +- src/engine/DynParaLoop.hxx | 9 +- src/engine/ElementaryNode.cxx | 13 +- src/engine/ElementaryNode.hxx | 5 +- src/engine/ElementaryPoint.cxx | 4 +- src/engine/ElementaryPoint.hxx | 2 +- src/engine/ForkBlocPoint.cxx | 43 ++-- src/engine/ForkBlocPoint.hxx | 2 +- src/engine/LinkedBlocPoint.cxx | 11 +- src/engine/LinkedBlocPoint.hxx | 2 +- src/engine/Loop.cxx | 7 +- src/engine/Loop.hxx | 2 +- src/engine/Node.hxx | 2 +- src/engine/PlayGround.cxx | 250 +++++++++++++------- src/engine/PlayGround.hxx | 26 +- src/engine/SetOfPoints.cxx | 4 +- src/engine/SetOfPoints.hxx | 2 +- src/engine/Switch.cxx | 11 +- src/engine/Switch.hxx | 2 +- src/engine/VisitorSaveSchema.cxx | 14 +- src/engine_swig/PlayGround.i | 22 +- src/engine_swig/pilot.i | 2 +- src/engine_swig/testPlayGround0.py | 34 +-- src/yacsloader/inlineParsers.hxx | 10 + src/yacsloader/loopParsers.hxx | 12 +- src/yacsloader/remoteParsers.hxx | 2 + src/yacsloader_swig/Test/testHPDecorator.py | 200 ++++++++++++++-- src/yacsloader_swig/Test/testSaveLoadRun.py | 4 +- 35 files changed, 520 insertions(+), 218 deletions(-) diff --git a/src/engine/AbstractPoint.hxx b/src/engine/AbstractPoint.hxx index 3b4f5dc64..2aceabfdf 100644 --- a/src/engine/AbstractPoint.hxx +++ b/src/engine/AbstractPoint.hxx @@ -67,7 +67,7 @@ namespace YACS virtual bool contains(Node *node) = 0; virtual int getNumberOfNodes() const = 0; virtual int getMaxLevelOfParallelism() const = 0; - virtual double getWeightRegardingDPL() const = 0; + virtual void getWeightRegardingDPL(ComplexWeight *weight) = 0; virtual void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const = 0; virtual std::string getRepr() const = 0; virtual ~AbstractPoint(); diff --git a/src/engine/BagPoint.cxx b/src/engine/BagPoint.cxx index d7727a16d..2492813df 100644 --- a/src/engine/BagPoint.cxx +++ b/src/engine/BagPoint.cxx @@ -79,9 +79,9 @@ int BagPoint::getMaxLevelOfParallelism() const return getUnique()->getMaxLevelOfParallelism(); } -double BagPoint::getWeightRegardingDPL() const +void BagPoint::getWeightRegardingDPL(ComplexWeight *weight) { - return getUnique()->getWeightRegardingDPL(); + getUnique()->getWeightRegardingDPL(weight); } void BagPoint::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const diff --git a/src/engine/BagPoint.hxx b/src/engine/BagPoint.hxx index 9568deb07..9e97acd25 100644 --- a/src/engine/BagPoint.hxx +++ b/src/engine/BagPoint.hxx @@ -37,7 +37,7 @@ namespace YACS Node *getFirstNode(); Node *getLastNode(); int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; AbstractPoint *getUniqueAndReleaseIt(); diff --git a/src/engine/Bloc.cxx b/src/engine/Bloc.cxx index 6fc3240ab..9a2f4ff50 100644 --- a/src/engine/Bloc.cxx +++ b/src/engine/Bloc.cxx @@ -473,11 +473,11 @@ std::list< AbstractPoint * > Bloc::analyzeParallelism() const return pts; } -double Bloc::getWeightRegardingDPL() const +void Bloc::getWeightRegardingDPL(ComplexWeight *weight) { std::list< AbstractPoint * > pts(analyzeParallelism()); ForkBlocPoint fbp(pts,NULL); - return fbp.getWeightRegardingDPL(); + fbp.getWeightRegardingDPL(weight); } void Bloc::removeRecursivelyRedundantCL() diff --git a/src/engine/Bloc.hxx b/src/engine/Bloc.hxx index 3759fc094..666cb3aba 100644 --- a/src/engine/Bloc.hxx +++ b/src/engine/Bloc.hxx @@ -66,7 +66,7 @@ namespace YACS void findAllNodesStartingFrom(Node *start, std::set& result, std::map >& accelStr, LinkInfo& info) const; virtual std::string typeName() { return "YACS__ENGINE__Bloc"; } int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void removeRecursivelyRedundantCL(); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap); void fitToPlayGround(const PlayGround *pg); diff --git a/src/engine/Bloc_impl.cxx b/src/engine/Bloc_impl.cxx index 038be80f6..1a5ed1f72 100644 --- a/src/engine/Bloc_impl.cxx +++ b/src/engine/Bloc_impl.cxx @@ -84,11 +84,14 @@ void Bloc::fitToPlayGround(const PlayGround *pg) int _lev; int _max_lev; }; - YACS::BASES::AutoRefCnt pd(new AllPartDefinition(pg,1)); + YACS::BASES::AutoRefCnt pd(new AllPartDefinition(pg)); std::map > zeMap; + MyVisitor vis(this); + this->accept(&vis); + for(std::list::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++) + (*it)->edGetNbOfBranchesPort()->edInit(1); this->removeRecursivelyRedundantCL(); this->partitionRegardingDPL(pd,zeMap); - MyVisitor vis(this); this->accept(&vis); for(std::list::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++) { diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index b1f43ff38..3e8442219 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -44,6 +44,7 @@ SET(YACSlibEngine_HEADERS AnyInputPort.hxx Bloc.hxx Catalog.hxx + ComplexWeight.hxx ComponentDefinition.hxx ComponentInstance.hxx ComposedNode.hxx @@ -181,6 +182,7 @@ SET(YACSlibEngine_SOURCES ElementaryPoint.cxx SetOfPoints.cxx PlayGround.cxx + ComplexWeight.cxx ) SET(YACSlibEngine_HEADERS ${YACSlibEngine_HEADERS} PARENT_SCOPE) # Make it visible to src/engine_swig to handle dependencies diff --git a/src/engine/DynParaLoop.cxx b/src/engine/DynParaLoop.cxx index 632f72478..5197c49e1 100644 --- a/src/engine/DynParaLoop.cxx +++ b/src/engine/DynParaLoop.cxx @@ -44,8 +44,9 @@ const char DynParaLoop::NAME_OF_NUMBER_OF_BRANCHES[]="nbBranches"; DynParaLoop::DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted) : ComposedNode(name),_node(0),_initNode(0),_finalizeNode(0),_nbOfEltConsumed(0), _nbOfBranches(NAME_OF_NUMBER_OF_BRANCHES,this,Runtime::_tc_int), - _splittedPort(NAME_OF_SPLITTED_SEQ_OUT,this,typeOfDataSplitted),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(1.) + _splittedPort(NAME_OF_SPLITTED_SEQ_OUT,this,typeOfDataSplitted),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(), _loopWeight(0) { + _weight.setDefaultLoop(); } DynParaLoop::~DynParaLoop() @@ -58,7 +59,7 @@ DynParaLoop::~DynParaLoop() DynParaLoop::DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly) : ComposedNode(other,father), _nbOfBranches(other._nbOfBranches,this), _splittedPort(other._splittedPort,this), _node(0), _initNode(0), _finalizeNode(0), - _nbOfEltConsumed(0),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(1.) + _nbOfEltConsumed(0),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(other._weight), _loopWeight(other._loopWeight) { if(other._node) _node=other._node->clone(this,editionOnly); @@ -423,11 +424,18 @@ DynParaLoop::TypeOfNode DynParaLoop::getIdentityOfNotifyerNode(const Node *node, return FINALIZE_NODE; } -void DynParaLoop::setWeight(double newVal) +void DynParaLoop::setWeight(double loopWeight) { - if(newVal<=0.) + if(loopWeight<=0.) throw Exception("DynParaLoop::setWeight : invalid input value !"); - _weight=newVal; + _loopWeight=loopWeight; +} + +ComplexWeight* DynParaLoop::getWeight() +{ + if (_loopWeight>0.) + _weight.setLoopWeight(_loopWeight, _node->getMaxLevelOfParallelism()); // not done in setWeight because _node can be null at that time + return &_weight; } bool DynParaLoop::isMultiplicitySpecified(unsigned& value) const diff --git a/src/engine/DynParaLoop.hxx b/src/engine/DynParaLoop.hxx index 723b27e2e..93bffd55d 100644 --- a/src/engine/DynParaLoop.hxx +++ b/src/engine/DynParaLoop.hxx @@ -57,7 +57,8 @@ namespace YACS int _initializingCounter; int _unfinishedCounter; int _failedCounter; - double _weight; + ComplexWeight _weight; + double _loopWeight; protected: static const char NAME_OF_SPLITTED_SEQ_OUT[]; static const char OLD_NAME_OF_SPLITTED_SEQ_OUT[]; @@ -98,9 +99,9 @@ namespace YACS Node *getChildByShortName(const std::string& name) const throw(Exception); Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception); std::vector getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes - double getWeight() const { return _weight; } - void setWeight(double newVal); - double getWeightRegardingDPL() const { return getWeight(); } + ComplexWeight * getWeight(); + void setWeight(double loopWeight); + void getWeightRegardingDPL(ComplexWeight *weight) {weight->addWeight(getWeight());} bool isMultiplicitySpecified(unsigned& value) const; void forceMultiplicity(unsigned value); virtual void checkBasicConsistency() const throw(Exception); diff --git a/src/engine/ElementaryNode.cxx b/src/engine/ElementaryNode.cxx index 129deaa1d..dff7963cc 100644 --- a/src/engine/ElementaryNode.cxx +++ b/src/engine/ElementaryNode.cxx @@ -47,11 +47,13 @@ using namespace std; ElementaryNode::ElementaryNode(const std::string& name): Node(name), _createDatastreamPorts(false), - _multi_port_node(false) + _multi_port_node(false), + _weight() { + _weight.setDefaultElementary(); } -ElementaryNode::ElementaryNode(const ElementaryNode& other, ComposedNode *father):Node(other,father) +ElementaryNode::ElementaryNode(const ElementaryNode& other, ComposedNode *father):Node(other,father), _weight(other._weight) { _createDatastreamPorts = other._createDatastreamPorts; _multi_port_node = other._multi_port_node; @@ -892,3 +894,10 @@ void ElementaryNode::getCoupledNodes(std::set& coupledSet) } } +void ElementaryNode::setWeight(double elementaryWeight) +{ + if(elementaryWeight<=0.) + throw Exception("ElementaryNode::setWeight : invalid input value !"); + _weight.setElementaryWeight(elementaryWeight); +} + diff --git a/src/engine/ElementaryNode.hxx b/src/engine/ElementaryNode.hxx index d2561e804..e0c908894 100644 --- a/src/engine/ElementaryNode.hxx +++ b/src/engine/ElementaryNode.hxx @@ -48,6 +48,7 @@ namespace YACS std::list _setOfOutputPort; std::list _setOfInputDataStreamPort; std::list _setOfOutputDataStreamPort; + ComplexWeight _weight; // Management of multi property bool _createDatastreamPorts; @@ -107,7 +108,9 @@ namespace YACS virtual void ensureLoading(); int getMaxLevelOfParallelism() const { return 1; } - double getWeightRegardingDPL() const { return 0.; } + ComplexWeight *getWeight() { return &_weight; } + void setWeight(double elementaryWeight); + void getWeightRegardingDPL(ComplexWeight *weight) { weight->addWeight(getWeight()); } void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) { } //run part diff --git a/src/engine/ElementaryPoint.cxx b/src/engine/ElementaryPoint.cxx index aeef403b4..7d161b9c2 100644 --- a/src/engine/ElementaryPoint.cxx +++ b/src/engine/ElementaryPoint.cxx @@ -59,9 +59,9 @@ int ElementaryPoint::getMaxLevelOfParallelism() const return _node->getMaxLevelOfParallelism(); } -double ElementaryPoint::getWeightRegardingDPL() const +void ElementaryPoint::getWeightRegardingDPL(ComplexWeight *weight) { - return _node->getWeightRegardingDPL(); + _node->getWeightRegardingDPL(weight); } void ElementaryPoint::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const diff --git a/src/engine/ElementaryPoint.hxx b/src/engine/ElementaryPoint.hxx index 08897e80a..f5ac56538 100644 --- a/src/engine/ElementaryPoint.hxx +++ b/src/engine/ElementaryPoint.hxx @@ -43,7 +43,7 @@ namespace YACS Node *getLastNode(); int getNumberOfNodes() const; int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; virtual ~ElementaryPoint(); diff --git a/src/engine/ForkBlocPoint.cxx b/src/engine/ForkBlocPoint.cxx index 79d30fe65..8b8768f1c 100644 --- a/src/engine/ForkBlocPoint.cxx +++ b/src/engine/ForkBlocPoint.cxx @@ -54,50 +54,41 @@ int ForkBlocPoint::getMaxLevelOfParallelism() const return ret; } -double ForkBlocPoint::getWeightRegardingDPL() const +void ForkBlocPoint::getWeightRegardingDPL(ComplexWeight *weight) { - double ret(0.); + ComplexWeight localWeight; for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) - ret+=(*it)->getWeightRegardingDPL(); - return ret; + { + (*it)->getWeightRegardingDPL(&localWeight); + weight->addWeight(&localWeight); + localWeight.setToZero(); + } } void ForkBlocPoint::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const { - std::vector< std::pair > parts,parts2; - std::vector v,v2; + std::vector< std::pair > parts; + std::vector< int> nbCoresPerShot; + std::vector v; + std::vector nodesWeight(_nodes.size()); std::size_t ii(0); for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++) { - double w((*it)->getWeightRegardingDPL()); - if(w!=0.) - { - parts.push_back(std::pair(pd,w)); - v.push_back(ii); - } - else - { - parts2.push_back(std::pair(pd,1.)); - v2.push_back(ii); - } + ComplexWeight *w=&nodesWeight[ii]; + (*it)->getWeightRegardingDPL(w); + parts.push_back(std::pair(pd,w)); + nbCoresPerShot.push_back((*it)->getMaxLevelOfParallelism()); + v.push_back(ii); } std::vector nodes2(_nodes.begin(),_nodes.end()); if(!parts.empty()) { const PlayGround *pg(pd->getPlayGround()); - std::vector< YACS::BASES::AutoRefCnt > pds(pg->partition(parts)); + std::vector< YACS::BASES::AutoRefCnt > pds(pg->partition(parts,nbCoresPerShot)); ii=0; for(std::vector::const_iterator iter=v.begin();iter!=v.end();iter++,ii++) nodes2[*iter]->partitionRegardingDPL(pds[ii],zeMap); } - if(!parts2.empty()) - { - const PlayGround *pg(pd->getPlayGround()); - std::vector< YACS::BASES::AutoRefCnt > pds(pg->partition(parts2)); - ii=0; - for(std::vector::const_iterator iter=v2.begin();iter!=v2.end();iter++,ii++) - nodes2[*iter]->partitionRegardingDPL(pds[ii],zeMap); - } } std::string ForkBlocPoint::getRepr() const diff --git a/src/engine/ForkBlocPoint.hxx b/src/engine/ForkBlocPoint.hxx index 0aa3fbf17..2c347caf2 100644 --- a/src/engine/ForkBlocPoint.hxx +++ b/src/engine/ForkBlocPoint.hxx @@ -34,7 +34,7 @@ namespace YACS Node *getFirstNode(); Node *getLastNode(); int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; virtual ~ForkBlocPoint(); diff --git a/src/engine/LinkedBlocPoint.cxx b/src/engine/LinkedBlocPoint.cxx index 666f757e5..b4d2e7f2f 100644 --- a/src/engine/LinkedBlocPoint.cxx +++ b/src/engine/LinkedBlocPoint.cxx @@ -48,12 +48,15 @@ int LinkedBlocPoint::getMaxLevelOfParallelism() const return ret; } -double LinkedBlocPoint::getWeightRegardingDPL() const +void LinkedBlocPoint::getWeightRegardingDPL(ComplexWeight *weight) { - double ret(0.); + ComplexWeight localWeight; for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) - ret=std::max(ret,(*it)->getWeightRegardingDPL()); - return ret; + { + (*it)->getWeightRegardingDPL(&localWeight); + weight->addWeight(&localWeight); + localWeight.setToZero(); + } } void LinkedBlocPoint::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const diff --git a/src/engine/LinkedBlocPoint.hxx b/src/engine/LinkedBlocPoint.hxx index 963ca24e0..3491ed407 100644 --- a/src/engine/LinkedBlocPoint.hxx +++ b/src/engine/LinkedBlocPoint.hxx @@ -36,7 +36,7 @@ namespace YACS Node *getFirstNode(); Node *getLastNode(); int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; virtual ~LinkedBlocPoint(); diff --git a/src/engine/Loop.cxx b/src/engine/Loop.cxx index cc4f089f9..66d52d28d 100644 --- a/src/engine/Loop.cxx +++ b/src/engine/Loop.cxx @@ -419,11 +419,10 @@ int Loop::getMaxLevelOfParallelism() const return _node->getMaxLevelOfParallelism(); } -double Loop::getWeightRegardingDPL() const +void Loop::getWeightRegardingDPL(ComplexWeight *weight) { - if(!_node) - return 0.; - return _node->getWeightRegardingDPL(); + if(_node) + _node->getWeightRegardingDPL(weight); } void Loop::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) diff --git a/src/engine/Loop.hxx b/src/engine/Loop.hxx index a1f533af0..cd691346a 100644 --- a/src/engine/Loop.hxx +++ b/src/engine/Loop.hxx @@ -173,7 +173,7 @@ namespace YACS std::list getSetOfInputPort() const; int getNumberOfInputPorts() const; int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap); Node *getChildByShortName(const std::string& name) const throw(Exception); static TypeCode* MappingDF2DS(TypeCode* type) throw(Exception); diff --git a/src/engine/Node.hxx b/src/engine/Node.hxx index f37920482..15c51ab1c 100644 --- a/src/engine/Node.hxx +++ b/src/engine/Node.hxx @@ -175,7 +175,7 @@ namespace YACS virtual const Proc *getProc() const; virtual void accept(Visitor *visitor) = 0; virtual int getMaxLevelOfParallelism() const = 0; - virtual double getWeightRegardingDPL() const = 0; + virtual void getWeightRegardingDPL(ComplexWeight *weight) = 0; virtual void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) = 0; std::string getQualifiedName() const; int getNumId(); diff --git a/src/engine/PlayGround.cxx b/src/engine/PlayGround.cxx index 4ed54568e..f28047937 100644 --- a/src/engine/PlayGround.cxx +++ b/src/engine/PlayGround.cxx @@ -29,6 +29,7 @@ using namespace YACS::ENGINE; + std::string PlayGround::printSelf() const { std::ostringstream oss; @@ -136,24 +137,24 @@ void PlayGround::highlightOnIds(const std::vector& coreIds, std::vector PlayGround::getFetchedCores(int nbCoresPerWorker) const -{ - int nbCores(getNumberOfCoresAvailable()); - std::vector ret(nbCores,false); - if(nbCoresPerWorker==1) - std::fill(ret.begin(),ret.end(),true); - else - { - std::size_t posBg(0); - for(std::vector< std::pair >::const_iterator it=_data.begin();it!=_data.end();it++) - { - int nbElemsToPutOn(((*it).second/nbCoresPerWorker)*nbCoresPerWorker); - std::fill(ret.begin()+posBg,ret.begin()+posBg+nbElemsToPutOn,true); - posBg+=(*it).second; - } - } - return ret; -} +// std::vector PlayGround::getFetchedCores(int nbCoresPerWorker) const +// { +// int nbCores(getNumberOfCoresAvailable()); +// std::vector ret(nbCores,false); +// if(nbCoresPerWorker==1) +// std::fill(ret.begin(),ret.end(),true); +// else +// { +// std::size_t posBg(0); +// for(std::vector< std::pair >::const_iterator it=_data.begin();it!=_data.end();it++) +// { +// int nbElemsToPutOn(((*it).second/nbCoresPerWorker)*nbCoresPerWorker); +// std::fill(ret.begin()+posBg,ret.begin()+posBg+nbElemsToPutOn,true); +// posBg+=(*it).second; +// } +// } +// return ret; +//} /*! * follow getMaxNumberOfContainersCanBeHostedWithoutOverlap method */ @@ -175,9 +176,11 @@ std::vector PlayGround::getWorkerIdsFullyFetchedBy(int nbCoresPerCo return ret; } -std::vector< YACS::BASES::AutoRefCnt > PlayGround::partition(const std::vector< std::pair >& parts) const +std::vector< YACS::BASES::AutoRefCnt > PlayGround::partition(const std::vector< std::pair >& parts, const std::vector< int>& nbCoresPerShot) const { std::size_t sz(parts.size()),szs(getNumberOfCoresAvailable()); + if (sz!=nbCoresPerShot.size()) + throw Exception("PlayGround::partition : incoherent vector size !"); if(sz==0) return std::vector< YACS::BASES::AutoRefCnt >(); if(sz==1) @@ -193,35 +196,31 @@ std::vector< YACS::BASES::AutoRefCnt > PlayGround::partition(con throw Exception("PlayGround::partition : not implemented yet for more than 31 ! You need to pay for it :)"); std::vector zeArr(szs*sz,false); std::size_t i(0); - for(std::vector< std::pair >::const_iterator it=parts.begin();it!=parts.end();it++,i++) + for(std::vector< std::pair >::const_iterator it=parts.begin();it!=parts.end();it++,i++) { const PartDefinition *pd((*it).first); if(!pd) throw Exception("Presence of null pointer as part def !"); if(pd->getPlayGround()!=this) throw Exception("Presence of non homogeneous playground !"); - if((*it).second<=0.) - throw Exception("Invalid weight !"); - std::vector bs(pd->getCoresOn()); + std::vector bs(pd->getCoresOn()); // tab of length nbCores, with True or False for each Core for(std::size_t j=0;j > retIds(sz); for(std::size_t i=0;i code(zeArr.begin()+i*sz,zeArr.begin()+(i+1)*sz); - std::vector locIds(GetIdsMatching(zeArr,code)); - std::vector partsIds(BuildVectOfIdsFromVecBool(code)); + std::vector code(zeArr.begin()+i*sz,zeArr.begin()+(i+1)*sz);// vecteur contenant le true/false d'un coeur pour ttes les partitions + std::vector locIds(GetIdsMatching(zeArr,code)); // liste des coeurs qui peuvent correspondre au pattern code + std::vector partsIds(BuildVectOfIdsFromVecBool(code));// pour chaque partition retourne l'id de la premiere partition à true if(partsIds.empty()) continue; - std::vector wg; - std::vector nbCores2; + std::vector > wg; for(std::vector::const_iterator it=partsIds.begin();it!=partsIds.end();it++) { - wg.push_back(parts[*it].second); - nbCores2.push_back(parts[*it].first->getNbCoresPerCompo()); + wg.push_back(std::pair (parts[*it].second, nbCoresPerShot[*it])); } - std::vector< std::vector > ress(splitIntoParts(locIds,nbCores2,wg)); + std::vector< std::vector > ress(splitIntoParts(locIds,wg)); std::size_t k(0); for(std::vector::const_iterator it=partsIds.begin();it!=partsIds.end();it++,k++) { @@ -234,47 +233,138 @@ std::vector< YACS::BASES::AutoRefCnt > PlayGround::partition(con { std::set s(retIds[i].begin(),retIds[i].end()); std::vector v(s.begin(),s.end()); - ret[i]=PartDefinition::BuildFrom(this,(parts[i].first)->getNbCoresPerCompo(),v); + ret[i]=PartDefinition::BuildFrom(this,v); } return ret; } -std::vector sortArr(const std::vector& v) +std::vector< std::vector > PlayGround::splitIntoParts(const std::vector& coreIds, const std::vector< std::pair >& weights) const { - std::multimap m; - int i(v.size()-1); - for(std::vector::const_reverse_iterator it=v.rbegin();it!=v.rend();it++) - m.insert(std::pair(*it,i--)); - std::vector ret(m.size()); - i=0; - for(std::multimap::const_reverse_iterator it=m.rbegin();it!=m.rend();it++)// reverse -> sort from biggest to the finest - ret[i++]=(*it).second; - return ret; -} - -std::vector< std::vector > PlayGround::splitIntoParts(const std::vector& coreIds, const std::vector& nbCoresConso, const std::vector& weights) const -{ - double wgs(std::accumulate(weights.begin(),weights.end(),0.)); - std::size_t sz(nbCoresConso.size()); - if(sz!=weights.size()) - throw Exception("PlayGround::splitIntoParts : internal error !"); + std::size_t sz(weights.size()); if(sz==0) return std::vector< std::vector >(); - int totalSpace(coreIds.size()); - std::vector< std::vector > ret(sz); - std::vector fromBigToTiny(sortArr(nbCoresConso));// start to treat the coarse grain to finish with fine grain + std::vector< std::vector > ret; + std::vector< std::vector > disorderRet(sz); std::vector zeArr(getNumberOfCoresAvailable(),false); highlightOnIds(coreIds,zeArr); int nbOfCoresToSplit(coreIds.size()); - std::size_t ii(fromBigToTiny.size()); - for(std::vector::const_iterator it=fromBigToTiny.begin();it!=fromBigToTiny.end();it++,ii--) + int totalSpace(coreIds.size()); + int remainingSpace(totalSpace); + std::vector nbOfCoresAllocated(sz); + std::vector nbCoresPerShot(sz,-1); + // first every other branchs take its minimal part of the cake + // and remove branch without valid weight + int i(0); + std::map saveOrder; + const std::vector< std::pair > sortedWeights(bigToTiny(weights, saveOrder)); + for(std::vector >::const_iterator it=sortedWeights.begin();it!=sortedWeights.end();it++,i++) + { + nbCoresPerShot[i]=(*it).second; + if ((*it).first->isUnsetLoopWeight()) + { + nbOfCoresAllocated[i]=nbCoresPerShot[i]; // branch with only elementary nodes + } + else if (!(*it).first->hasValidLoopWeight()) + { + nbOfCoresAllocated[i]=(int)((double)totalSpace/(double)(sz)); // branch with undefined weight + } + else + { + nbOfCoresAllocated[i]=nbCoresPerShot[i]; + } + } + remainingSpace-=std::accumulate(nbOfCoresAllocated.begin(), nbOfCoresAllocated.end(), 0); + //get critical path (between path with loopWeight) + int criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated); + if (criticalPathRank!=-1) { - int maxNbOfCores((int)(totalSpace*weights[*it]/wgs));// now try to find in zeArr at most maxNbOfCores cores - ret[*it]=takePlace(maxNbOfCores,nbCoresConso[*it],zeArr,ii==1); + // add cores to critical path while enough cores are availables + while (remainingSpace >= nbCoresPerShot[criticalPathRank]) + { + nbOfCoresAllocated[criticalPathRank]+=nbCoresPerShot[criticalPathRank]; + remainingSpace-=nbCoresPerShot[criticalPathRank]; + criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated); + } + //fill other paths with remaining cores (if possible) (reuse fromBigToTiny here?) + // and takePlace + int coresToAdd; + int j(0); + for(std::vector::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,j++) + { + coresToAdd=((int)(remainingSpace/nbCoresPerShot[j]))*nbCoresPerShot[j]; + *it+=coresToAdd; + remainingSpace-=coresToAdd; + } } + int k(0); + for(std::vector::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,k++) + { + disorderRet[k]=takePlace(*it,nbCoresPerShot[k],zeArr,k==(sz-1)); + } + ret=backToOriginalOrder(disorderRet, saveOrder); return ret; } +std::vector< std::pair > PlayGround::bigToTiny(const std::vector< std::pair > &weights, std::map &saveOrder) const +{ + int maxCoresPerShot(0), rankMax(0); + int i(0); + std::vector< std::pair > ret; + std::size_t sz(weights.size()); + while (ret.size() >::const_iterator it=weights.begin();it!=weights.end();it++,i++) + { + if ((maxCoresPerShot<(*it).second) && (saveOrder.find(i)==saveOrder.end())) + { + maxCoresPerShot=(*it).second; + rankMax=i; + } + } + ret.push_back(std::pair (weights[rankMax].first,weights[rankMax].second)); + saveOrder[rankMax]=ret.size()-1; + maxCoresPerShot=0; + i=0; + } + return ret; +} + +std::vector< std::vector > PlayGround::backToOriginalOrder(const std::vector< std::vector > &disorderVec, const std::map &saveOrder) const +{ + std::vector< std::vector > ret; + std::size_t sz(disorderVec.size()); + if (disorderVec.size()!=saveOrder.size()) + throw Exception("PlayGround::backToOriginalOrder : incoherent vector size !"); + for (int i=0; i >& weights, const std::vector& nbOfCoresAllocated) const +{ + double maxWeight(0.); + double pathWeight(0.); + int rankMaxPath(-1); + if ((weights.size()!=nbOfCoresAllocated.size()) || (weights.size()==0)) + throw Exception("PlayGround::getCriticalPath : internal error !"); + int i=0; + for(std::vector >::const_iterator it=weights.begin();it!=weights.end();it++,i++) + { + if (nbOfCoresAllocated[i]==0) + throw Exception("PlayGround::getCriticalPath : nbOfCoresAllocated is null! error !"); + if (!(*it).first->isDefaultValue()) + { + pathWeight=(*it).first->calculateTotalLength(nbOfCoresAllocated[i]); + if (pathWeight > maxWeight) + { + maxWeight=pathWeight; + rankMaxPath=i; + } + } + } + return rankMaxPath; +} + std::vector PlayGround::takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector& distributionOfCores, bool lastOne) const { if(maxNbOfCoresToAlloc<1) @@ -378,12 +468,12 @@ PlayGround::~PlayGround() ////////////////////// -PartDefinition::PartDefinition(const PlayGround *pg, int nbOfCoresPerComp):_nbOfCoresPerComp(nbOfCoresPerComp) +PartDefinition::PartDefinition(const PlayGround *pg) { _pg.takeRef(pg); } -PartDefinition::PartDefinition(const PartDefinition& other):_pg(other._pg),_nbOfCoresPerComp(other._nbOfCoresPerComp) +PartDefinition::PartDefinition(const PartDefinition& other):_pg(other._pg) { } @@ -391,16 +481,16 @@ PartDefinition::~PartDefinition() { } -std::vector< YACS::BASES::AutoRefCnt > PartDefinition::partition(const std::vector< double >& wgs) const -{ - std::size_t sz(wgs.size()); - std::vector< std::pair > elts(sz); - for(std::size_t i=0;i(this,wgs[i]); - return getPlayGround()->partition(elts); -} +// std::vector< YACS::BASES::AutoRefCnt > PartDefinition::partition(const std::vector< const ComplexWeight *>& wgs) const +// { +// std::size_t sz(wgs.size()); +// std::vector< std::pair > elts(sz); +// for(std::size_t i=0;i(this,wgs[i]); +// return getPlayGround()->partition(elts); +// } -YACS::BASES::AutoRefCnt PartDefinition::BuildFrom(const PlayGround *pg, int nbOfCoresPerComp, const std::vector& coreIds) +YACS::BASES::AutoRefCnt PartDefinition::BuildFrom(const PlayGround *pg, const std::vector& coreIds) { int spaceSz(pg->getNumberOfCoresAvailable()),sz(coreIds.size()); if(sz>spaceSz) @@ -415,15 +505,15 @@ YACS::BASES::AutoRefCnt PartDefinition::BuildFrom(const PlayGrou throw Exception("PartDefinition::BuildFrom : error ! The content of core Ids is not OK 2 !"); if(zeEnd-zeStart+1!=sz) { - YACS::BASES::AutoRefCnt pd(new NonContigPartDefinition(pg,nbOfCoresPerComp,coreIds)); + YACS::BASES::AutoRefCnt pd(new NonContigPartDefinition(pg,coreIds)); return pd; } if(sz==spaceSz) { - YACS::BASES::AutoRefCnt pd(new AllPartDefinition(pg,nbOfCoresPerComp)); + YACS::BASES::AutoRefCnt pd(new AllPartDefinition(pg)); return pd; } - YACS::BASES::AutoRefCnt pd(new ContigPartDefinition(pg,nbOfCoresPerComp,zeStart,zeEnd+1)); + YACS::BASES::AutoRefCnt pd(new ContigPartDefinition(pg,zeStart,zeEnd+1)); return pd; } @@ -444,21 +534,21 @@ void PartDefinition::stashPart(int nbCoresStashed, double weightOfRemain, YACS:: int n1(nbCoresAvailable-n0); if(n1<=0) { - pdStashed=PartDefinition::BuildFrom(getPlayGround(),1,ids); - pdRemain=PartDefinition::BuildFrom(getPlayGround(),1,ids); + pdStashed=PartDefinition::BuildFrom(getPlayGround(),ids); + pdRemain=PartDefinition::BuildFrom(getPlayGround(),ids); } else { std::vector ids0(ids.begin(),ids.begin()+n0),ids1(ids.begin()+n0,ids.end()); - pdStashed=PartDefinition::BuildFrom(getPlayGround(),1,ids0); - pdRemain=PartDefinition::BuildFrom(getPlayGround(),1,ids1); + pdStashed=PartDefinition::BuildFrom(getPlayGround(),ids0); + pdRemain=PartDefinition::BuildFrom(getPlayGround(),ids1); } } else { std::vector ids0(ids.begin(),ids.begin()+nbCoresStashed),ids1(ids.begin()+nbCoresStashed,ids.end()); - pdStashed=PartDefinition::BuildFrom(getPlayGround(),1,ids0); - pdRemain=PartDefinition::BuildFrom(getPlayGround(),1,ids1); + pdStashed=PartDefinition::BuildFrom(getPlayGround(),ids0); + pdRemain=PartDefinition::BuildFrom(getPlayGround(),ids1); } } @@ -473,7 +563,7 @@ std::vector PartDefinition::computeWorkerIdsCovered(int nbCoresPerC ////////////////////// -ContigPartDefinition::ContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, int zeStart, int zeStop):PartDefinition(pg,nbOfCoresPerComp),_start(zeStart),_stop(zeStop) +ContigPartDefinition::ContigPartDefinition(const PlayGround *pg, int zeStart, int zeStop):PartDefinition(pg),_start(zeStart),_stop(zeStop) { if(_start<0 || _stop<_start || _stop>getSpaceSize()) throw Exception("ContigPartDefinition constructor : Invalid input values"); @@ -510,7 +600,7 @@ int ContigPartDefinition::getNumberOfCoresConsumed() const ////////////////////// -NonContigPartDefinition::NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector& ids):PartDefinition(pg,nbOfCoresPerComp),_ids(ids) +NonContigPartDefinition::NonContigPartDefinition(const PlayGround *pg, const std::vector& ids):PartDefinition(pg),_ids(ids) { checkOKIds(); } diff --git a/src/engine/PlayGround.hxx b/src/engine/PlayGround.hxx index 63236663a..cd688aff8 100644 --- a/src/engine/PlayGround.hxx +++ b/src/engine/PlayGround.hxx @@ -23,15 +23,17 @@ #include "YACSlibEngineExport.hxx" #include "RefCounter.hxx" #include "AutoRefCnt.hxx" +#include "ComplexWeight.hxx" #include #include +#include namespace YACS { namespace ENGINE { - class PartDefinition; + class PartDefinition; class YACSLIBENGINE_EXPORT PlayGround : public RefCounter { @@ -45,7 +47,7 @@ namespace YACS int getNumberOfCoresAvailable() const; int getMaxNumberOfContainersCanBeHostedWithoutOverlap(int nbCoresPerCont) const; std::vector computeOffsets() const; - std::vector< YACS::BASES::AutoRefCnt > partition(const std::vector< std::pair >& parts) const; + std::vector< YACS::BASES::AutoRefCnt > partition(const std::vector< std::pair >& parts, const std::vector &nbCoresPerShot) const; int fromWorkerIdToResId(int workerId, int nbProcPerNode) const; std::string deduceMachineFrom(int workerId, int nbProcPerNode) const; int getNumberOfWorkers(int nbCoresPerWorker) const; @@ -55,7 +57,10 @@ namespace YACS static std::vector BuildVectOfIdsFromVecBool(const std::vector& v); static std::vector GetIdsMatching(const std::vector& bigArr, const std::vector& pat); private: - std::vector< std::vector > splitIntoParts(const std::vector& coreIds, const std::vector& nbCoresConso, const std::vector& weights) const; + std::vector< std::pair > bigToTiny(const std::vector< std::pair > &weights, std::map &saveOrder) const; + std::vector< std::vector > backToOriginalOrder(const std::vector< std::vector > &disorderVec, const std::map &saveOrder) const; + int getCriticalPath(const std::vector >& weights, const std::vector& maxNbOfCores) const; + std::vector< std::vector > splitIntoParts(const std::vector& coreIds, const std::vector >& weights) const; std::vector takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector& distributionOfCores, bool lastOne=false) const; private: void checkCoherentInfo() const; @@ -68,15 +73,13 @@ namespace YACS class YACSLIBENGINE_EXPORT PartDefinition : public RefCounter { protected: - PartDefinition(const PlayGround *pg, int nbOfCoresPerComp); + PartDefinition(const PlayGround *pg); PartDefinition(const PartDefinition& other); virtual ~PartDefinition(); public: - std::vector< YACS::BASES::AutoRefCnt > partition(const std::vector< double >& wgs) const; - static YACS::BASES::AutoRefCnt BuildFrom(const PlayGround *pg, int nbOfCoresPerComp, const std::vector& coreIds); + //std::vector< YACS::BASES::AutoRefCnt > partition(const std::vector< const ComplexWeight *>& wgs) const; + static YACS::BASES::AutoRefCnt BuildFrom(const PlayGround *pg, const std::vector& coreIds); const PlayGround *getPlayGround() const { return _pg; } - int getNbCoresPerCompo() const { return _nbOfCoresPerComp; } - void setNbCoresPerCompo(int newNbCores) { _nbOfCoresPerComp=newNbCores; } int getSpaceSize() const { return _pg->getNumberOfCoresAvailable(); } void stashPart(int nbCoresStashed, double weightOfRemain, YACS::BASES::AutoRefCnt& pdStashed, YACS::BASES::AutoRefCnt& pdRemain) const; std::vector computeWorkerIdsCovered(int nbCoresPerComp) const; @@ -86,13 +89,12 @@ namespace YACS virtual int getNumberOfCoresConsumed() const = 0; private: YACS::BASES::AutoConstRefCnt _pg; - int _nbOfCoresPerComp; }; class YACSLIBENGINE_EXPORT ContigPartDefinition : public PartDefinition { public: - ContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, int zeStart, int zeStop); + ContigPartDefinition(const PlayGround *pg, int zeStart, int zeStop); ContigPartDefinition(const ContigPartDefinition& other); std::string printSelf() const; std::vector getCoresOn() const; @@ -110,7 +112,7 @@ namespace YACS class YACSLIBENGINE_EXPORT NonContigPartDefinition : public PartDefinition { public: - NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector& ids); + NonContigPartDefinition(const PlayGround *pg, const std::vector& ids); NonContigPartDefinition(const ContigPartDefinition& other); std::string printSelf() const; std::vector getCoresOn() const; @@ -127,7 +129,7 @@ namespace YACS class AllPartDefinition : public PartDefinition { public: - AllPartDefinition(const PlayGround *pg, int nbOfCoresPerComp):PartDefinition(pg,nbOfCoresPerComp) { } + AllPartDefinition(const PlayGround *pg):PartDefinition(pg) { } AllPartDefinition(const AllPartDefinition& other); std::string printSelf() const; std::vector getCoresOn() const; diff --git a/src/engine/SetOfPoints.cxx b/src/engine/SetOfPoints.cxx index 39d787168..76f892577 100644 --- a/src/engine/SetOfPoints.cxx +++ b/src/engine/SetOfPoints.cxx @@ -87,9 +87,9 @@ int SetOfPoints::getMaxLevelOfParallelism() const return _bp->getMaxLevelOfParallelism(); } -double SetOfPoints::getWeightRegardingDPL() const +void SetOfPoints::getWeightRegardingDPL(ComplexWeight *weight) { - return _bp->getWeightRegardingDPL(); + _bp->getWeightRegardingDPL(weight); } void SetOfPoints::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const diff --git a/src/engine/SetOfPoints.hxx b/src/engine/SetOfPoints.hxx index d670ff692..bc29934b0 100644 --- a/src/engine/SetOfPoints.hxx +++ b/src/engine/SetOfPoints.hxx @@ -47,7 +47,7 @@ namespace YACS AbstractPoint *findPointWithNode(Node *node); const std::list& getListOfPoints() const; int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; AbstractPoint *getUniqueAndReleaseIt() const; private: diff --git a/src/engine/Switch.cxx b/src/engine/Switch.cxx index 5c0b7a2d8..99e6ba45a 100644 --- a/src/engine/Switch.cxx +++ b/src/engine/Switch.cxx @@ -408,12 +408,15 @@ int Switch::getMaxLevelOfParallelism() const return ret; } -double Switch::getWeightRegardingDPL() const +void Switch::getWeightRegardingDPL(ComplexWeight *weight) { - double ret(0); + ComplexWeight localWeight; for(std::map< int , Node * >::const_iterator it=_mapOfNode.begin();it!=_mapOfNode.end();it++) - ret=std::max(ret,((*it).second)->getWeightRegardingDPL()); - return ret; + { + ((*it).second)->getWeightRegardingDPL(&localWeight); + weight->max(localWeight); + localWeight.setToZero(); + } } void Switch::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) diff --git a/src/engine/Switch.hxx b/src/engine/Switch.hxx index be5b1c16f..a635bdb41 100644 --- a/src/engine/Switch.hxx +++ b/src/engine/Switch.hxx @@ -116,7 +116,7 @@ namespace YACS void writeDot(std::ostream &os) const; int getNumberOfInputPorts() const; int getMaxLevelOfParallelism() const; - double getWeightRegardingDPL() const; + void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap); void edRemoveChild(Node *node) throw(Exception); std::list getSetOfInputPort() const; diff --git a/src/engine/VisitorSaveSchema.cxx b/src/engine/VisitorSaveSchema.cxx index 4e33796b9..cf7abb9a1 100644 --- a/src/engine/VisitorSaveSchema.cxx +++ b/src/engine/VisitorSaveSchema.cxx @@ -134,7 +134,7 @@ void VisitorSaveSchema::visitForEachLoop(ForEachLoop *node) _out << " state=\"disabled\""; if (!nbranch->isEmpty()) _out << " nbranch=\"" << nbranch->getIntValue() << "\""; - _out << " weight=\"" << node->getWeight() << "\""; + _out << " loopWeight=\"" << node->getWeight()->getSimpleLoopWeight() << "\""; if (node->edGetSamplePort()) _out << " type=\"" << node->edGetSamplePort()->edGetType()->name() << "\""; _out << ">" << endl; @@ -160,7 +160,7 @@ void VisitorSaveSchema::visitOptimizerLoop(OptimizerLoop *node) _out << " state=\"disabled\""; if (!nbranch->isEmpty()) _out << " nbranch=\"" << nbranch->getIntValue() << "\""; - _out << " weight=\"" << node->getWeight() << "\""; + _out << " loopWeight=\"" << node->getWeight()->getSimpleLoopWeight() << "\""; _out << " lib=\"" << node->getAlgLib() << "\""; _out << " entry=\"" << node->getSymbol() << "\""; _out << ">" << endl; @@ -227,7 +227,10 @@ void VisitorSaveSchema::visitInlineNode(InlineNode *node) if(node->getExecutionMode()==InlineNode::LOCAL_STR) _out << indent(depth) << "getName() << "\""; else - _out << indent(depth) << "getName() << "\""; + { + _out << indent(depth) << "getName() << "\""; + _out << " elementaryWeight=\"" << node->getWeight()->getElementaryWeight() << "\""; + } if (node->getState() == YACS::DISABLED) _out << " state=\"disabled\">" << endl; else @@ -264,7 +267,10 @@ void VisitorSaveSchema::visitInlineFuncNode(InlineFuncNode *node) if(node->getExecutionMode()==InlineNode::LOCAL_STR) _out << indent(depth) << "getName() << "\""; else - _out << indent(depth) << "getName() << "\""; + { + _out << indent(depth) << "getName() << "\""; + _out << " elementaryWeight=\"" << node->getWeight()->getElementaryWeight() << "\""; + } if (node->getState() == YACS::DISABLED) _out << " state=\"disabled\">" << endl; else diff --git a/src/engine_swig/PlayGround.i b/src/engine_swig/PlayGround.i index 859ed1fcb..e0b34f254 100644 --- a/src/engine_swig/PlayGround.i +++ b/src/engine_swig/PlayGround.i @@ -16,9 +16,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - -%template() std::pair< YACS::ENGINE::PartDefinition *, double>; -%template(vecppdd) std::vector< std::pair< YACS::ENGINE::PartDefinition *, double> >; +%include +%template() std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *>; +%template(vecppdd) std::vector< std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *> >; %newobject YACS::ENGINE::PlayGround::copy; @@ -55,7 +55,7 @@ namespace YACS namespace ENGINE { class PartDefinition; - + class PlayGround : public RefCounter { public: @@ -75,13 +75,13 @@ namespace YACS return self->printSelf(); } - std::vector< YACS::BASES::AutoRefCnt > partition(const std::vector< std::pair< YACS::ENGINE::PartDefinition *,double> >& parts) const + std::vector< YACS::BASES::AutoRefCnt > partition(const std::vector< std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *> >& parts, const std::vector &nbCoresPerShot) const { std::size_t sz(parts.size()); - std::vector< std::pair< const YACS::ENGINE::PartDefinition *,double> > partsCpp(sz); + std::vector< std::pair< const YACS::ENGINE::PartDefinition *, const YACS::ENGINE::ComplexWeight *> > partsCpp(sz); for(std::size_t i=0;i(parts[i].first,parts[i].second); - return self->partition(partsCpp); + partsCpp[i]=std::pair(parts[i].first, parts[i].second); + return self->partition(partsCpp, nbCoresPerShot); } } private: @@ -102,7 +102,7 @@ namespace YACS class ContigPartDefinition : public PartDefinition { public: - ContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, int zeStart, int zeStop); + ContigPartDefinition(const PlayGround *pg, int zeStart, int zeStop); int getStart() const; int getStop() const; %extend @@ -119,7 +119,7 @@ namespace YACS class NonContigPartDefinition : public PartDefinition { public: - NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector& ids); + NonContigPartDefinition(const PlayGround *pg, const std::vector& ids); std::vector getIDs() const; %extend { @@ -135,7 +135,7 @@ namespace YACS class AllPartDefinition : public PartDefinition { public: - AllPartDefinition(const PlayGround *pg, int nbOfCoresPerComp); + AllPartDefinition(const PlayGround *pg); %extend { std::string __str__() const diff --git a/src/engine_swig/pilot.i b/src/engine_swig/pilot.i index 98a7296db..f0316e5f4 100644 --- a/src/engine_swig/pilot.i +++ b/src/engine_swig/pilot.i @@ -320,7 +320,7 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause) return (long)self; } } - +%include %include %include %include diff --git a/src/engine_swig/testPlayGround0.py b/src/engine_swig/testPlayGround0.py index 3128e2126..df0509c59 100644 --- a/src/engine_swig/testPlayGround0.py +++ b/src/engine_swig/testPlayGround0.py @@ -23,17 +23,18 @@ import unittest class TestPlayGround0(unittest.TestCase): def test0(self): pg=pilot.PlayGround([("a0",28),("a1",28),("a2",28)]) - pd=pilot.ContigPartDefinition(pg,4,0,3*28) - res=pg.partition([(pd,1.),(pd,1.)]) + pd=pilot.ContigPartDefinition(pg,0,3*28) + cw=pilot.ComplexWeight(0.,1.,4) + res=pg.partition([(pd,cw),(pd,cw)],[4,4]) assert(len(res)==2) assert(isinstance(res[0],pilot.ContigPartDefinition)) assert(isinstance(res[1],pilot.ContigPartDefinition)) - assert(res[0].getStart()==0 and res[0].getStop()==40) - assert(res[1].getStart()==40 and res[1].getStop()==84) + assert(res[0].getStart()==0 and res[0].getStop()==44) + assert(res[1].getStart()==44 and res[1].getStop()==84) assert(sum([elt.getNumberOfCoresConsumed() for elt in res])==pg.getNumberOfCoresAvailable()) - pd2=pilot.AllPartDefinition(pg,4) + pd2=pilot.AllPartDefinition(pg) assert(pd2.getNumberOfCoresConsumed()==84) - res=pg.partition([(pd2,1.),(pd2,1.),(pd2,1.)]) + res=pg.partition([(pd2,cw),(pd2,cw),(pd2,cw)],[4,4,4]) assert(len(res)==3) assert(isinstance(res[0],pilot.ContigPartDefinition)) assert(isinstance(res[1],pilot.ContigPartDefinition)) @@ -43,7 +44,8 @@ class TestPlayGround0(unittest.TestCase): assert(res[2].getStart()==56 and res[2].getStop()==84) # pg.setData([("a0",2),("a1",8),("a2",8)]) - res=pg.partition([(pilot.AllPartDefinition(pg,4),1.),(pilot.AllPartDefinition(pg,1),1.)]) + cw2=pilot.ComplexWeight(0.,4.,1) + res=pg.partition([(pilot.AllPartDefinition(pg),cw),(pilot.AllPartDefinition(pg),cw)],[4,1]) assert(len(res)==2) assert(isinstance(res[0],pilot.ContigPartDefinition)) assert(isinstance(res[1],pilot.NonContigPartDefinition)) @@ -54,20 +56,24 @@ class TestPlayGround0(unittest.TestCase): def test1(self): """ test focused on complicated cut due to lack of cores""" pg=pilot.PlayGround([("a0",13)]) - pd=pilot.ContigPartDefinition(pg,4,0,13) - res=pg.partition([(pd,1.),(pd,1.)]) + pd=pilot.ContigPartDefinition(pg,0,13) + cw=pilot.ComplexWeight(0.,1.,4) + cw2=pilot.ComplexWeight(0.,2.,4) + res=pg.partition([(pd,cw),(pd,cw2)],[4,4]) assert(len(res)==2) assert(isinstance(res[0],pilot.ContigPartDefinition) and isinstance(res[1],pilot.ContigPartDefinition)) assert(res[0].getStart()==0 and res[0].getStop()==4) assert(res[1].getStart()==4 and res[1].getStop()==12)# 1 core lost # - pg=pilot.PlayGround([("a0",2),("a1",11)]) - pd=pilot.ContigPartDefinition(pg,4,0,13) - res=pg.partition([(pd,1.),(pd,1.)]) + pg=pilot.PlayGround([("a0",2),("a1",27)]) + cw3=pilot.ComplexWeight(0.,20,1) + cw4=pilot.ComplexWeight(0.,1.,8) + pd=pilot.ContigPartDefinition(pg,0,29) + res=pg.partition([(pd,cw3),(pd,cw4)],[4,8]) assert(len(res)==2) assert(isinstance(res[0],pilot.ContigPartDefinition) and isinstance(res[1],pilot.ContigPartDefinition)) - assert(res[0].getStart()==2 and res[0].getStop()==6) - assert(res[1].getStart()==6 and res[1].getStop()==10)# 5 cores lost + assert(res[0].getStart()==10 and res[0].getStop()==26) + assert(res[1].getStart()==2 and res[1].getStop()==10)# 5 cores lost pass pass diff --git a/src/yacsloader/inlineParsers.hxx b/src/yacsloader/inlineParsers.hxx index 0a6cedb5a..9fd2d7393 100644 --- a/src/yacsloader/inlineParsers.hxx +++ b/src/yacsloader/inlineParsers.hxx @@ -72,6 +72,7 @@ struct inlinetypeParser:public nodetypeParser for (int i = 0; attr[i]; i += 2) { if(std::string(attr[i]) == "name")this->name(attr[i+1]); + if(std::string(attr[i]) == "elementaryWeight")this->weight(atof(attr[i+1])); if(std::string(attr[i]) == "state")this->state(attr[i+1]); } } @@ -81,6 +82,12 @@ struct inlinetypeParser:public nodetypeParser _kind=""; this->_state=""; this->_container=""; + this->_weight=-1.; + } + virtual void weight (const double& x) + { + DEBTRACE("elementary_weight: " << x ) + _weight=x; } virtual void kind (const std::string& name) { @@ -154,6 +161,7 @@ struct inlinetypeParser:public nodetypeParser return this->_node; } std::string _kind; + double _weight; }; template inlinetypeParser inlinetypeParser::inlineParser; @@ -164,6 +172,7 @@ void inlinetypeParser::script (const myfunc& f) DEBTRACE( "inline_script: " << f._code ) _node=theRuntime->createScriptNode(_kind,_name); _node->setScript(f._code); + if(_weight>0)_node->setWeight(_weight); } template <> @@ -174,6 +183,7 @@ void inlinetypeParser::function (const myfunc& f) fnode=theRuntime->createFuncNode(_kind,_name); fnode->setScript(f._code); fnode->setFname(f._name); + if(_weight>0)fnode->setWeight(_weight); _node=fnode; } diff --git a/src/yacsloader/loopParsers.hxx b/src/yacsloader/loopParsers.hxx index db84e6ff1..83abbc33d 100644 --- a/src/yacsloader/loopParsers.hxx +++ b/src/yacsloader/loopParsers.hxx @@ -506,7 +506,7 @@ struct foreachlooptypeParser:dynparalooptypeParser if(std::string(attr[i]) == "name")name(attr[i+1]); if(std::string(attr[i]) == "state")this->state(attr[i+1]); if(std::string(attr[i]) == "nbranch")nbranch(atoi(attr[i+1])); - if(std::string(attr[i]) == "weight")weight(atof(attr[i+1])); + if(std::string(attr[i]) == "loopWeight")weight(atof(attr[i+1])); if(std::string(attr[i]) == "type")datatype(attr[i+1]); } postAttr(); @@ -514,7 +514,7 @@ struct foreachlooptypeParser:dynparalooptypeParser virtual void pre () { _nbranch=0; - _weight=1; + _weight=-1.; this->looptypeParser::pre(); } virtual void name (const std::string& name) @@ -559,7 +559,7 @@ struct foreachlooptypeParser:dynparalooptypeParser this->_cnode=theRuntime->createForEachLoop(_name,currentProc->typeMap[_datatype]); //set number of branches if(_nbranch > 0)this->_cnode->edGetNbOfBranchesPort()->edInit(_nbranch); - this->_cnode->setWeight(_weight); + if(_weight > 0)this->_cnode->setWeight(_weight); this->_cnodes.push_back(this->_cnode); currentProc->names.push_back(_fullname + '.'); } @@ -604,7 +604,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser if(std::string(attr[i]) == "name")name(attr[i+1]); if(std::string(attr[i]) == "state")this->state(attr[i+1]); if(std::string(attr[i]) == "nbranch")nbranch(atoi(attr[i+1])); - if(std::string(attr[i]) == "weight")weight(atof(attr[i+1])); + if(std::string(attr[i]) == "loopWeight")weight(atof(attr[i+1])); if(std::string(attr[i]) == "lib")lib(attr[i+1]); if(std::string(attr[i]) == "entry")entry(attr[i+1]); if(std::string(attr[i]) == "kind")kind(attr[i+1]); @@ -614,7 +614,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser virtual void pre () { _nbranch=0; - _weight=1; + _weight=-1.; this->looptypeParser::pre(); } virtual void name (const std::string& name) @@ -650,7 +650,7 @@ struct optimizerlooptypeParser:dynparalooptypeParser this->_cnode=theRuntime->createOptimizerLoop(_name,_lib,_entry,true,_kind, currentProc); //set number of branches if(_nbranch > 0)this->_cnode->edGetNbOfBranchesPort()->edInit(_nbranch); - this->_cnode->setWeight(_weight); + if(_weight > 0)this->_cnode->setWeight(_weight); this->_cnodes.push_back(this->_cnode); currentProc->names.push_back(_fullname + '.'); } diff --git a/src/yacsloader/remoteParsers.hxx b/src/yacsloader/remoteParsers.hxx index 6db9b3586..47ea6897a 100644 --- a/src/yacsloader/remoteParsers.hxx +++ b/src/yacsloader/remoteParsers.hxx @@ -61,6 +61,7 @@ struct remotetypeParser:public inlinetypeParser fnode->setScript(f._code); fnode->setFname(f._name); fnode->setExecutionMode("remote"); + if (this->_weight>0)fnode->setWeight(this->_weight); this->_node=fnode; } @@ -71,6 +72,7 @@ struct remotetypeParser:public inlinetypeParser node=theRuntime->createScriptNode(this->_kind,this->_name); node->setScript(f._code); node->setExecutionMode("remote"); + if (this->_weight>0)node->setWeight(this->_weight); this->_node=node; } diff --git a/src/yacsloader_swig/Test/testHPDecorator.py b/src/yacsloader_swig/Test/testHPDecorator.py index aa15b60df..717654e44 100644 --- a/src/yacsloader_swig/Test/testHPDecorator.py +++ b/src/yacsloader_swig/Test/testHPDecorator.py @@ -65,6 +65,7 @@ class TestHPDecortator(unittest.TestCase): n1_1.edAddChild(n1_1_sc) n1_1_sc.setExecutionMode("remote") n1_1_sc.setScript("""3*i1""") + n1_1.setWeight(4.) i1_1_sc=n1_1_sc.edAddInputPort("i1",td) p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc) n1_1_sc.setContainer(hp1) @@ -72,8 +73,8 @@ class TestHPDecortator(unittest.TestCase): hp1.setProperty("nb_proc_per_node","1") hp4.setProperty("nb_proc_per_node","4") pg.setData([("m0",8),("m1",8),("m2",8),("m3",8)]) # virtual machine with 32 cores spread over 4 nodes - assert(n1_0.getWeight()==1.) - assert(n1_1.getWeight()==1.) + assert(n1_0.getWeight().getSimpleLoopWeight()==-1.) + assert(n1_1.getWeight().getSimpleLoopWeight()==4.) p.fitToPlayGround(pg)########### ZE CALL fyto=pilot.ForTestOmlyHPContCls() assert(hp4.getSizeOfPool()==8)# 32/4 @@ -104,25 +105,25 @@ class TestHPDecortator(unittest.TestCase): ############################# # Change weight of ForEach # ############################# - n1_0.setWeight(2) + n1_0.setWeight(1) p.fitToPlayGround(pg)########### ZE CALL assert(hp4.getSizeOfPool()==8)# 32/4 n1_0_sc.getContainer().forYourTestsOnly(fyto) assert(fyto.getContainerType()=="HPContainerShared") pd=fyto.getPD() assert(isinstance(pd,pilot.ContigPartDefinition)) - assert(pd.getStart()==0 and pd.getStop()==21) - assert(fyto.getIDS()==(0,1,2,3,4)) + assert(pd.getStart()==0 and pd.getStop()==16) + assert(fyto.getIDS()==(0,1,2,3)) assert(hp1.getSizeOfPool()==32)# 32/1 fyto=pilot.ForTestOmlyHPContCls() n1_1_sc.getContainer().forYourTestsOnly(fyto) assert(fyto.getContainerType()=="HPContainerShared") pd=fyto.getPD() assert(isinstance(pd,pilot.ContigPartDefinition)) - assert(pd.getStart()==21 and pd.getStop()==32) - assert(fyto.getIDS()==(21,22,23,24,25,26,27,28,29,30,31)) - assert(n1_0.edGetNbOfBranchesPort().getPyObj()==6) - assert(n1_1.edGetNbOfBranchesPort().getPyObj()==11) + assert(pd.getStart()==16 and pd.getStop()==32) + assert(fyto.getIDS()==(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)) + assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4) + assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16) # fyto=pilot.ForTestOmlyHPContCls() n0.getContainer().forYourTestsOnly(fyto) @@ -156,6 +157,7 @@ class TestHPDecortator(unittest.TestCase): p.edAddChild(n1_0) p.edAddCFLink(n0,n1_0) p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort()) + n1_0.setWeight(1.) ## n1_0_sc=r.createScriptNode("Salome","n1_0_sc") n1_0.edAddChild(n1_0_sc) @@ -170,6 +172,7 @@ class TestHPDecortator(unittest.TestCase): p.edAddChild(n1_1) p.edAddCFLink(n0,n1_1) p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort()) + n1_1.setWeight(4.) ## n1_1_sc=r.createScriptNode("Salome","n1_1_sc") n1_1.edAddChild(n1_1_sc) @@ -188,11 +191,11 @@ class TestHPDecortator(unittest.TestCase): ## hp1.setProperty("nb_proc_per_node","1") hp4.setProperty("nb_proc_per_node","4") - pg.setData([("m0",8),("m1",8),("m2",8),("m3",8)]) # virtual machine with 32 cores spread over 4 nodes - assert(n1_0.getWeight()==1.) - assert(n1_1.getWeight()==1.) + pg.setData([("m0",8),("m1",8),("m2",8),("m3",8),("m4",4)]) # virtual machine with 32 cores spread over 4 nodes + assert(n1_0.getWeight().getSimpleLoopWeight()==1.) + assert(n1_1.getWeight().getSimpleLoopWeight()==4.) p.fitToPlayGround(pg)########### ZE CALL - assert(hp4.getSizeOfPool()==8)# 32/4 + assert(hp4.getSizeOfPool()==9)# 36/4 fyto=pilot.ForTestOmlyHPContCls() n1_0_sc.getContainer().forYourTestsOnly(fyto) assert(fyto.getContainerType()=="HPContainerShared") @@ -201,14 +204,14 @@ class TestHPDecortator(unittest.TestCase): assert(pd.getStart()==0 and pd.getStop()==16) assert(fyto.getIDS()==(0,1,2,3)) # - assert(hp1.getSizeOfPool()==32)# 32/1 + assert(hp1.getSizeOfPool()==36)# 36/1 fyto=pilot.ForTestOmlyHPContCls() n1_1_sc.getContainer().forYourTestsOnly(fyto) assert(fyto.getContainerType()=="HPContainerShared") pd=fyto.getPD() assert(isinstance(pd,pilot.ContigPartDefinition)) - assert(pd.getStart()==16 and pd.getStop()==32) - assert(fyto.getIDS()==(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)) + assert(pd.getStart()==20 and pd.getStop()==36) + assert(fyto.getIDS()==(20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35)) assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4) assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16) # @@ -217,13 +220,13 @@ class TestHPDecortator(unittest.TestCase): assert(fyto.getContainerType()=="HPContainerShared") pd=fyto.getPD() assert(isinstance(pd,pilot.AllPartDefinition)) - assert(list(fyto.getIDS())==range(8)) + assert(list(fyto.getIDS())==range(9)) fyto=pilot.ForTestOmlyHPContCls() n1_2.getContainer().forYourTestsOnly(fyto) assert(fyto.getContainerType()=="HPContainerShared") pd=fyto.getPD() - assert(isinstance(pd,pilot.AllPartDefinition)) - assert(list(fyto.getIDS())==range(8)) + assert(isinstance(pd,pilot.ContigPartDefinition)) + assert(list(fyto.getIDS())==[4]) pass @unittest.skip("requires 2 machines in catalog") @@ -357,6 +360,165 @@ class TestHPDecortator(unittest.TestCase): assert(len(set(hp1.getKernelContainerNames()))==3) pass + def test4(self): + """ two branch whose on with one elementary node and on foreach""" + SALOMERuntime.RuntimeSALOME.setRuntime() + r=SALOMERuntime.getSALOMERuntime() + pg=pilot.PlayGround() + pg.loadFromKernelCatalog() + assert(len(pg.getData())!=0) + p=r.createProc("p0") + td=p.createType("double","double") + tdd=p.createSequenceTc("seqdouble","seqdouble",td) + hp1=p.createContainer("HP1","HPSalome") + # + ## + n0=r.createScriptNode("Salome","n0") + n0.setExecutionMode("remote") + out0_0=n0.edAddOutputPort("o1",tdd) + n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""") + n0.setContainer(hp1) + p.edAddChild(n0) + # + b0 = r.createBloc("Bloc0") + p.edAddChild(b0) + p.edAddCFLink(n0,b0) + ## + n1_0=r.createForEachLoop("n1_0",td) + b0.edAddChild(n1_0) + p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort()) + n1_0.setWeight(10.) + ## + n1_0_sc=r.createScriptNode("Salome","n1_0_sc") + n1_0.edAddChild(n1_0_sc) + n1_0_sc.setExecutionMode("remote") + n1_0_sc.setScript("""2*i1""") + i1_0_sc=n1_0_sc.edAddInputPort("i1",td) + p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc) + n1_0_sc.setContainer(hp1) + ## + n1_0_1=r.createScriptNode("Salome","n1_0_1") + n1_0_1.setExecutionMode("remote") + n1_0_1.setScript("""a=2""") + b0.edAddChild(n1_0_1) + p.edAddCFLink(n1_0,n1_0_1) + n1_0_1.setContainer(hp1) + n1_0_1.setWeight(20.) + ## + # + n1_1=r.createForEachLoop("n1_1",td) + p.edAddChild(n1_1) + p.edAddCFLink(n0,n1_1) + p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort()) + n1_1.setWeight(100.) + ## + n1_1_sc=r.createScriptNode("Salome","n1_1_sc") + n1_1.edAddChild(n1_1_sc) + n1_1_sc.setExecutionMode("remote") + n1_1_sc.setScript("""3*i1""") + i1_1_sc=n1_1_sc.edAddInputPort("i1",td) + p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc) + n1_1_sc.setContainer(hp1) + + hp1.setProperty("nb_proc_per_node","1") + pg.setData([("m0",12)]) + w=pilot.ComplexWeight() + b0.getWeightRegardingDPL(w) + assert(w.getElementaryWeight()==20.) + assert(w.calculateTotalLength(1)==30.) + assert(w.calculateTotalLength(2)==25.) + p.fitToPlayGround(pg)########### ZE CALL + assert(n1_0.edGetNbOfBranchesPort().getPyObj()==7) + assert(n1_1.edGetNbOfBranchesPort().getPyObj()==5) + # + fyto=pilot.ForTestOmlyHPContCls() + n1_0_sc.getContainer().forYourTestsOnly(fyto) + assert(fyto.getContainerType()=="HPContainerShared") + pd=fyto.getPD() + assert(isinstance(pd,pilot.ContigPartDefinition)) + print (pd.getStart(),pd.getStop()) + assert(pd.getStart()==0 and pd.getStop()==7) + + ######################### + ## change HPcontainer + ## very important: if you change HPcontainer you have to reload the graph + ######################### + p=r.createProc("p0") + n0=r.createScriptNode("Salome","n0") + n0.setExecutionMode("remote") + out0_0=n0.edAddOutputPort("o1",tdd) + n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""") + n0.setContainer(hp1) + p.edAddChild(n0) + # + b0 = r.createBloc("Bloc0") + p.edAddChild(b0) + p.edAddCFLink(n0,b0) + ## + n1_0=r.createForEachLoop("n1_0",td) + b0.edAddChild(n1_0) + p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort()) + ## + n1_0_sc=r.createScriptNode("Salome","n1_0_sc") + n1_0.edAddChild(n1_0_sc) + n1_0_sc.setExecutionMode("remote") + n1_0_sc.setScript("""2*i1""") + i1_0_sc=n1_0_sc.edAddInputPort("i1",td) + p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc) + n1_0_sc.setContainer(hp1) + ## + n1_0_1=r.createForEachLoop("n1_0_1",td) + b0.edAddChild(n1_0_1) + p.edAddLink(out0_0,n1_0_1.edGetSeqOfSamplesPort()) + p.edAddCFLink(n1_0,n1_0_1) + ## + n1_0_1sc=r.createScriptNode("Salome","n1_0_1sc") + n1_0_1.edAddChild(n1_0_1sc) + n1_0_1sc.setExecutionMode("remote") + n1_0_1sc.setScript("""a=2""") + i1_0_1sc=n1_0_1sc.edAddInputPort("i1",td) + p.edAddLink(n1_0_1.edGetSamplePort(),i1_0_1sc) + ## + # + n1_1=r.createForEachLoop("n1_1",td) + p.edAddChild(n1_1) + p.edAddCFLink(n0,n1_1) + p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort()) + ## + n1_1_sc=r.createScriptNode("Salome","n1_1_sc") + n1_1.edAddChild(n1_1_sc) + n1_1_sc.setExecutionMode("remote") + n1_1_sc.setScript("""3*i1""") + i1_1_sc=n1_1_sc.edAddInputPort("i1",td) + p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc) + n1_1_sc.setContainer(hp1) + ## + ## + hp4=p.createContainer("HP4","HPSalome") + hp4.setProperty("nb_proc_per_node","4") + n1_0.setWeight(40.) + n1_0_1.setWeight(20) + n1_1.setWeight(100.) + n1_0_1sc.setContainer(hp4) + w=pilot.ComplexWeight() + b0.getWeightRegardingDPL(w) + assert(w.getElementaryWeight()==0.) + assert(w.calculateTotalLength(4)==30.) + assert(w.calculateTotalLength(8)==15.) + pg.setData([("m0",120)]) + p.fitToPlayGround(pg)########### ZE CALL + assert(n1_0.edGetNbOfBranchesPort().getPyObj()==64) + assert(n1_0_1.edGetNbOfBranchesPort().getPyObj()==16) + assert(n1_1.edGetNbOfBranchesPort().getPyObj()==56) + # + fyto=pilot.ForTestOmlyHPContCls() + n1_0_sc.getContainer().forYourTestsOnly(fyto) + assert(fyto.getContainerType()=="HPContainerShared") + pd=fyto.getPD() + assert(isinstance(pd,pilot.ContigPartDefinition)) + assert(pd.getStart()==0 and pd.getStop()==64) + pass + pass if __name__ == '__main__': diff --git a/src/yacsloader_swig/Test/testSaveLoadRun.py b/src/yacsloader_swig/Test/testSaveLoadRun.py index 6a35686d2..caf0271db 100755 --- a/src/yacsloader_swig/Test/testSaveLoadRun.py +++ b/src/yacsloader_swig/Test/testSaveLoadRun.py @@ -1609,6 +1609,7 @@ import time time.sleep(2) o2=2*i1 """) + n10.setWeight(4.) i1=n10.edAddInputPort("i1",ti) o2=n10.edAddOutputPort("o2",ti) p.edAddChild(n1) @@ -1628,7 +1629,8 @@ o2=2*i1 # l=loader.YACSLoader() p=l.load(fname) - self.assertEqual(p.getChildByName("n1").getWeight(),3.0) + self.assertEqual(p.getChildByName("n1").getWeight().getSimpleLoopWeight(),3.0) + self.assertEqual(p.getChildByName("n1").getChildByName("n10").getWeight().getElementaryWeight(),4.0) pass pass -- 2.30.2