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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const = 0;
virtual std::string getRepr() const = 0;
virtual ~AbstractPoint();
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
Node *getFirstNode();
Node *getLastNode();
int getMaxLevelOfParallelism() const;
- double getWeightRegardingDPL() const;
+ void getWeightRegardingDPL(ComplexWeight *weight);
void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
std::string getRepr() const;
AbstractPoint *getUniqueAndReleaseIt();
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()
void findAllNodesStartingFrom(Node *start, std::set<Node *>& result, std::map<Node *, std::set<Node *> >& 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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
void fitToPlayGround(const PlayGround *pg);
int _lev;
int _max_lev;
};
- YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg,1));
+ YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg));
std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> > zeMap;
+ MyVisitor vis(this);
+ this->accept(&vis);
+ for(std::list<ForEachLoop *>::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<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
{
int maxLev((*it)->getExecNode()->getMaxLevelOfParallelism());
int a((*it2).second->getNumberOfCoresConsumed());
int res(a/maxLev);
- if(a%maxLev!=0)
- res++;
(*it)->edGetNbOfBranchesPort()->edInit(res);
}
for(std::set< HomogeneousPoolContainer * >::const_iterator it=vis._cont2.begin();it!=vis._cont2.end();it++)
AnyInputPort.hxx
Bloc.hxx
Catalog.hxx
+ ComplexWeight.hxx
ComponentDefinition.hxx
ComponentInstance.hxx
ComposedNode.hxx
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
--- /dev/null
+// Copyright (C) 2006-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "ComplexWeight.hxx"
+
+#include "Exception.hxx"
+
+using namespace YACS::ENGINE;
+
+ComplexWeight::ComplexWeight()
+{
+ setToZero();
+}
+
+ComplexWeight::ComplexWeight(double elementaryWeight, double loopWeight, int nbCoresByIteration): _elementaryWeight(elementaryWeight), _bootWeight(false)
+{
+ _loopWeight.push_back(std::pair<double,int>(loopWeight,nbCoresByIteration));
+}
+
+double ComplexWeight::getSimpleLoopWeight() const
+{
+ if(_loopWeight.size()!=1)
+ throw Exception("ComplexWeight::getSimpleLoopWeight : can not get loop weight. Node contain multiple loop weights!");
+ return (*(_loopWeight.begin())).first;
+}
+
+double ComplexWeight::calculateTotalLength(int nbOfCoresAllocated) const
+{
+ if (isDefaultValue())
+ throw Exception("ComplexWeight::calculateTotalLength : can not calculate total weight with default value!");
+ double totalWeight(0);
+ if (hasValidElementaryWeight())
+ totalWeight+=_elementaryWeight;
+ for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
+ {
+ if ((*it).second>0)
+ totalWeight+=(*it).first*((double)(*it).second)/((double)nbOfCoresAllocated);
+ }
+ return totalWeight;
+}
+
+void ComplexWeight::setLoopWeight(double loopWeight, int nbCoresByIteration)
+{
+ bool found(false);
+ int i(0), rankFound(0);
+ _bootWeight=false;
+ for(std::vector<std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++,i++)
+ {
+ if ((*it).second==nbCoresByIteration)
+ {
+ found=true;
+ rankFound=i;
+ }
+
+ }
+ if (found)
+ _loopWeight.erase(_loopWeight.begin()+rankFound);
+ _loopWeight.push_back(std::pair<double,int>(loopWeight,nbCoresByIteration));
+ if ((_loopWeight.size()>1) && ((*(_loopWeight.begin())).second==-1))
+ _loopWeight.erase(_loopWeight.begin());
+}
+
+int ComplexWeight::getNbCoresConsoLoopMax() const
+{
+ int nbCoresPerShotLoopMax(0);
+ for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
+ if ((*it).second>nbCoresPerShotLoopMax)nbCoresPerShotLoopMax=(*it).second;
+ return nbCoresPerShotLoopMax;
+}
+
+void ComplexWeight::max(ComplexWeight &other)
+{
+ _elementaryWeight=std::max(_elementaryWeight,other._elementaryWeight);
+
+ double allLoopWeight1(0);
+ double allLoopWeight2(0);
+ for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
+ {
+ if (((*it).first>0) && ((*it).second>0))
+ allLoopWeight1+=(*it).first * (*it).second;
+ }
+ for(std::vector< std::pair<double,int> >::const_iterator it=other._loopWeight.begin();it!=other._loopWeight.end();it++)
+ {
+ if (((*it).first>0) && ((*it).second>0))
+ allLoopWeight2+=(*it).first * (*it).second;
+ }
+ if (allLoopWeight2>allLoopWeight1)
+ _loopWeight=other._loopWeight;
+}
+
+ComplexWeight& ComplexWeight::addWeight(const ComplexWeight *other)
+{
+ bool found;
+ if ((!_bootWeight) && ((other->isUnsetLoopWeight() && this->isDefaultValueLoop()) || (this->isUnsetLoopWeight() && other->isDefaultValueLoop())))
+ this->unsetLoop();
+ else
+ {
+ for(std::vector< std::pair<double,int> >::const_iterator it=other->_loopWeight.begin();it!=other->_loopWeight.end();it++)
+ {
+ found=false;
+ for(std::vector< std::pair<double,int> >::iterator it2=_loopWeight.begin();it2!=_loopWeight.end();it2++)
+ {
+ if ((*it).second == (*it2).second)
+ {
+ if (((*it2).first>=0) && ((*it).first>=0))
+ this->setLoopWeight((*it2).first+(*it).first, (*it2).second);
+ else if ((*it).first>=0)
+ this->setLoopWeight((*it).first, (*it2).second);
+ found=true;
+ continue;
+ }
+ }
+ if ((!found) && ((*it).second!=-1))
+ this->setLoopWeight((*it).first, (*it).second);
+ }
+ if ((_loopWeight.size()>1) && ((*(_loopWeight.begin())).second==-1))
+ _loopWeight.erase(_loopWeight.begin());
+ }
+
+ if ((!_bootWeight) && ((other->isUnsetElementaryWeight() && this->isDefaultValueElementary()) || (this->isUnsetElementaryWeight() && other->isDefaultValueElementary())))
+ this->unsetElementary();
+ else
+ {
+ if (other->hasValidElementaryWeight())
+ {
+ if (hasValidElementaryWeight())
+ _elementaryWeight+=other->_elementaryWeight;
+ else
+ _elementaryWeight=other->_elementaryWeight;
+ }
+ }
+ if (!other->_bootWeight)
+ _bootWeight=false;
+}
+
+
+
+
--- /dev/null
+// Copyright (C) 2006-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef __COMPLEXWEIGHT_HXX__
+#define __COMPLEXWEIGHT_HXX__
+
+#include <vector>
+
+namespace YACS
+{
+ namespace ENGINE
+ {
+ class ComplexWeight
+ {
+ public:
+ ComplexWeight();
+ ComplexWeight(double elementaryWeight, double loopWeight, int nbCoresByIteration);
+ ComplexWeight(const ComplexWeight& other) {_bootWeight=other._bootWeight; _loopWeight=other._loopWeight; _elementaryWeight=other._elementaryWeight;}
+ ~ComplexWeight() {};
+ std::vector<std::pair<double,int> > getLoopWeight() const {return _loopWeight;}
+ double getSimpleLoopWeight() const;
+ double getElementaryWeight() const {return _elementaryWeight;}
+ double calculateTotalLength(int nbOfCoresAllocated) const;
+ void setDefaultElementary() {setToZero(); setLoopWeight(0.,0);}
+ void setDefaultLoop() {setToZero(); setElementaryWeight(0.);}
+ bool isDefaultValue() const { return ((isDefaultValueElementary()) && (isDefaultValueLoop()));}
+ bool isUnsetLoopWeight() const {return ((*(_loopWeight.begin())).second==0);}
+ bool isUnsetElementaryWeight() const {return (_elementaryWeight==0);}
+ bool hasValidLoopWeight() const { return (((*(_loopWeight.begin())).first>0) && ((*(_loopWeight.begin())).second!=-1));}
+ bool hasValidElementaryWeight() const { return (_elementaryWeight>=0);}
+ void setLoopWeight(double loopWeight, int nbCoresByIteration);
+ void setElementaryWeight(double elementaryWeight) {_bootWeight=false; _elementaryWeight=elementaryWeight;}
+ void setToZero() {_bootWeight=true; unsetElementary(); unsetLoop(); }
+ int getNbCoresConsoLoopMax() const;
+ void max(ComplexWeight &other);
+ ComplexWeight& addWeight(const ComplexWeight *other);
+ protected:
+ bool _bootWeight;
+ // _loopWeight: vect<pair(weight,nbcorePerIteration)>, for first element of vector: nbcorePerIteration<0 -> unset, nbcorePerIteration==0 -> no loopweight
+ std::vector<std::pair<double,int> > _loopWeight;
+ double _elementaryWeight;
+ private:
+ void unsetLoop() {_loopWeight.clear(); _loopWeight.push_back(std::pair<double,int>(-1.,-1));}
+ void unsetElementary(){_elementaryWeight=-1.;}
+ bool isDefaultValueLoop() const {return ((*(_loopWeight.begin())).second==-1);}
+ bool isDefaultValueElementary() const {return (_elementaryWeight<0);}
+ };
+ }
+}
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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()
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);
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
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[];
Node *getChildByShortName(const std::string& name) const throw(Exception);
Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
std::vector<Node *> 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);
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;
}
}
+void ElementaryNode::setWeight(double elementaryWeight)
+{
+ if(elementaryWeight<=0.)
+ throw Exception("ElementaryNode::setWeight : invalid input value !");
+ _weight.setElementaryWeight(elementaryWeight);
+}
+
std::list<OutputPort *> _setOfOutputPort;
std::list<InputDataStreamPort *> _setOfInputDataStreamPort;
std::list<OutputDataStreamPort *> _setOfOutputDataStreamPort;
+ ComplexWeight _weight;
// Management of multi property
bool _createDatastreamPorts;
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) { }
//run part
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
Node *getLastNode();
int getNumberOfNodes() const;
int getMaxLevelOfParallelism() const;
- double getWeightRegardingDPL() const;
+ void getWeightRegardingDPL(ComplexWeight *weight);
void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
std::string getRepr() const;
virtual ~ElementaryPoint();
return ret;
}
-double ForkBlocPoint::getWeightRegardingDPL() const
+void ForkBlocPoint::getWeightRegardingDPL(ComplexWeight *weight)
{
- double ret(0.);
+ ComplexWeight localWeight;
for(std::list<AbstractPoint *>::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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
{
- std::vector< std::pair<const PartDefinition *,double> > parts,parts2;
- std::vector<std::size_t> v,v2;
+ std::vector< std::pair<const PartDefinition *, const ComplexWeight *> > parts;
+ std::vector< int> nbCoresPerShot;
+ std::vector<std::size_t> v;
+ std::vector<ComplexWeight> nodesWeight(_nodes.size());
std::size_t ii(0);
for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
{
- double w((*it)->getWeightRegardingDPL());
- if(w!=0.)
- {
- parts.push_back(std::pair<const PartDefinition *,double >(pd,w));
- v.push_back(ii);
- }
- else
- {
- parts2.push_back(std::pair<const PartDefinition *,double >(pd,1.));
- v2.push_back(ii);
- }
+ ComplexWeight *w=&nodesWeight[ii];
+ (*it)->getWeightRegardingDPL(w);
+ parts.push_back(std::pair<const PartDefinition *, const ComplexWeight *>(pd,w));
+ nbCoresPerShot.push_back((*it)->getMaxLevelOfParallelism());
+ v.push_back(ii);
}
std::vector<AbstractPoint *> nodes2(_nodes.begin(),_nodes.end());
if(!parts.empty())
{
const PlayGround *pg(pd->getPlayGround());
- std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > pds(pg->partition(parts));
+ std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > pds(pg->partition(parts,nbCoresPerShot));
ii=0;
for(std::vector<std::size_t>::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<PartDefinition> > pds(pg->partition(parts2));
- ii=0;
- for(std::vector<std::size_t>::const_iterator iter=v2.begin();iter!=v2.end();iter++,ii++)
- nodes2[*iter]->partitionRegardingDPL(pds[ii],zeMap);
- }
}
std::string ForkBlocPoint::getRepr() const
Node *getFirstNode();
Node *getLastNode();
int getMaxLevelOfParallelism() const;
- double getWeightRegardingDPL() const;
+ void getWeightRegardingDPL(ComplexWeight *weight);
void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
std::string getRepr() const;
virtual ~ForkBlocPoint();
return ret;
}
-double LinkedBlocPoint::getWeightRegardingDPL() const
+void LinkedBlocPoint::getWeightRegardingDPL(ComplexWeight *weight)
{
- double ret(0.);
+ ComplexWeight localWeight;
for(std::list<AbstractPoint *>::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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
Node *getFirstNode();
Node *getLastNode();
int getMaxLevelOfParallelism() const;
- double getWeightRegardingDPL() const;
+ void getWeightRegardingDPL(ComplexWeight *weight);
void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
std::string getRepr() const;
virtual ~LinkedBlocPoint();
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap)
std::list<InputPort *> getSetOfInputPort() const;
int getNumberOfInputPorts() const;
int getMaxLevelOfParallelism() const;
- double getWeightRegardingDPL() const;
+ void getWeightRegardingDPL(ComplexWeight *weight);
void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
Node *getChildByShortName(const std::string& name) const throw(Exception);
static TypeCode* MappingDF2DS(TypeCode* type) throw(Exception);
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) = 0;
std::string getQualifiedName() const;
int getNumId();
using namespace YACS::ENGINE;
+
std::string PlayGround::printSelf() const
{
std::ostringstream oss;
throw Exception("host names entries must be different each other !");
}
-std::vector<bool> PlayGround::FromUItoVB(unsigned int sz, unsigned int v)
-{
- std::vector<bool> ret(sz);
- unsigned int p(1);
- for(std::size_t i=0;i<sz;i++)
- {
- ret[i]=p&v;
- p<<=1;
- }
- return ret;
-}
-
-unsigned int PlayGround::FromVBtoUI(const std::vector<bool>& v)
-{
- std::size_t sz(v.size());
- unsigned int ret(0);
- for(std::size_t i=0;i<sz;i++)
- {
- if(v[i])
- ret+=1u<<i;
- }
- return ret;
-}
-
std::vector<int> PlayGround::GetIdsMatching(const std::vector<bool>& bigArr, const std::vector<bool>& pat)
{
std::vector<int> ret;
/*!
* you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, and PartDefinition::computeWorkerIdsCovered
*/
-std::vector<bool> PlayGround::getFetchedCores(int nbCoresPerWorker) const
-{
- int nbCores(getNumberOfCoresAvailable());
- std::vector<bool> ret(nbCores,false);
- if(nbCoresPerWorker==1)
- std::fill(ret.begin(),ret.end(),true);
- else
- {
- std::size_t posBg(0);
- for(std::vector< std::pair<std::string,int> >::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<bool> PlayGround::getFetchedCores(int nbCoresPerWorker) const
+// {
+// int nbCores(getNumberOfCoresAvailable());
+// std::vector<bool> ret(nbCores,false);
+// if(nbCoresPerWorker==1)
+// std::fill(ret.begin(),ret.end(),true);
+// else
+// {
+// std::size_t posBg(0);
+// for(std::vector< std::pair<std::string,int> >::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
*/
return ret;
}
-std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > PlayGround::partition(const std::vector< std::pair<const PartDefinition *,double> >& parts) const
+std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > PlayGround::partition(const std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >& 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<PartDefinition> >();
if(sz==1)
throw Exception("PlayGround::partition : not implemented yet for more than 31 ! You need to pay for it :)");
std::vector<bool> zeArr(szs*sz,false);
std::size_t i(0);
- for(std::vector< std::pair<const PartDefinition *,double> >::const_iterator it=parts.begin();it!=parts.end();it++,i++)
+ for(std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >::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<bool> bs(pd->getCoresOn());
+ std::vector<bool> bs(pd->getCoresOn()); // tab of length nbCores, with True or False for each Core
for(std::size_t j=0;j<szs;j++)
- zeArr[j*sz+i]=bs[j];
- }
- std::set<unsigned int> ss;
- for(std::size_t i=0;i<szs;i++)
- {
- std::vector<bool> vb(zeArr.begin()+i*sz,zeArr.begin()+(i+1)*sz);
- ss.insert(FromVBtoUI(vb));
+ zeArr[j*sz+i]=bs[j]; // remplis une table avec les valeurs de bs. La table est [nb part] * [nb cores]
}
std::vector< std::vector<int> > retIds(sz);
- for(std::set<unsigned int>::const_iterator i=ss.begin();i!=ss.end();i++)
+ for(std::size_t i=0;i<szs;i++)
{
- std::vector<bool> code(FromUItoVB(sz,*i));// for this configuration which parts are considered
- std::vector<int> locIds(GetIdsMatching(zeArr,code));
- std::vector<int> partsIds(BuildVectOfIdsFromVecBool(code));
+ std::vector<bool> code(zeArr.begin()+i*sz,zeArr.begin()+(i+1)*sz);// vecteur contenant le true/false d'un coeur pour ttes les partitions
+ std::vector<int> locIds(GetIdsMatching(zeArr,code)); // liste des coeurs qui peuvent correspondre au pattern code
+ std::vector<int> partsIds(BuildVectOfIdsFromVecBool(code));// pour chaque partition retourne l'id de la premiere partition à true
if(partsIds.empty())
continue;
- std::vector<double> wg;
- std::vector<int> nbCores2;
+ std::vector<std::pair <const ComplexWeight *, int> > wg;
for(std::vector<int>::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 <const ComplexWeight *, int> (parts[*it].second, nbCoresPerShot[*it]));
}
- std::vector< std::vector<int> > ress(splitIntoParts(locIds,nbCores2,wg));
+ std::vector< std::vector<int> > ress(splitIntoParts(locIds,wg));
std::size_t k(0);
for(std::vector<int>::const_iterator it=partsIds.begin();it!=partsIds.end();it++,k++)
{
{
std::set<int> s(retIds[i].begin(),retIds[i].end());
std::vector<int> 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<int> sortArr(const std::vector<int>& v)
-{
- std::multimap<int,int> m;
- int i(v.size()-1);
- for(std::vector<int>::const_reverse_iterator it=v.rbegin();it!=v.rend();it++)
- m.insert(std::pair<int,int>(*it,i--));
- std::vector<int> ret(m.size());
- i=0;
- for(std::multimap<int,int>::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<int> > PlayGround::splitIntoParts(const std::vector<int>& coreIds, const std::vector<int>& nbCoresConso, const std::vector<double>& weights) const
+std::vector< std::vector<int> > PlayGround::splitIntoParts(const std::vector<int>& coreIds, const std::vector< std::pair <const ComplexWeight *, int> >& 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> >();
- int totalSpace(coreIds.size());
- std::vector< std::vector<int> > ret(sz);
- std::vector<int> fromBigToTiny(sortArr(nbCoresConso));// start to treat the coarse grain to finish with fine grain
+ std::vector< std::vector<int> > ret;
+ std::vector< std::vector<int> > disorderRet(sz);
std::vector<bool> zeArr(getNumberOfCoresAvailable(),false);
highlightOnIds(coreIds,zeArr);
int nbOfCoresToSplit(coreIds.size());
- std::size_t ii(fromBigToTiny.size());
- for(std::vector<int>::const_iterator it=fromBigToTiny.begin();it!=fromBigToTiny.end();it++,ii--)
+ int totalSpace(coreIds.size());
+ int remainingSpace(totalSpace);
+ std::vector<int> nbOfCoresAllocated(sz);
+ std::vector<int> 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<int,int> saveOrder;
+ const std::vector< std::pair <const ComplexWeight *, int> > sortedWeights(bigToTiny(weights, saveOrder));
+ for(std::vector<std::pair <const ComplexWeight *, int> >::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)
+ {
+ // 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<int>::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<int>::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 <const ComplexWeight *, int> > PlayGround::bigToTiny(const std::vector< std::pair <const ComplexWeight *, int> > &weights, std::map<int,int> &saveOrder) const
+{
+ int maxCoresPerShot(0), rankMax(0);
+ int i(0);
+ std::vector< std::pair <const ComplexWeight *, int> > ret;
+ std::size_t sz(weights.size());
+ while (ret.size()<sz)
{
- 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);
+ for(std::vector<std::pair <const ComplexWeight *, int> >::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 <const ComplexWeight *, int>(weights[rankMax].first,weights[rankMax].second));
+ saveOrder[rankMax]=ret.size()-1;
+ maxCoresPerShot=0;
+ i=0;
}
+ return ret;
+}
+
+std::vector< std::vector<int> > PlayGround::backToOriginalOrder(const std::vector< std::vector<int> > &disorderVec, const std::map<int,int> &saveOrder) const
+{
+ std::vector< std::vector<int> > ret;
+ std::size_t sz(disorderVec.size());
+ if (disorderVec.size()!=saveOrder.size())
+ throw Exception("PlayGround::backToOriginalOrder : incoherent vector size !");
+ for (int i=0; i<sz; i++)
+ ret.push_back(disorderVec[saveOrder.at(i)]);
return ret;
}
+int PlayGround::getCriticalPath(const std::vector<std::pair <const ComplexWeight *, int > >& weights, const std::vector<int>& 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<std::pair <const ComplexWeight *, int> >::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<int> PlayGround::takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector<bool>& distributionOfCores, bool lastOne) const
{
if(maxNbOfCoresToAlloc<1)
//////////////////////
-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)
{
}
{
}
-std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > PartDefinition::partition(const std::vector< double >& wgs) const
-{
- std::size_t sz(wgs.size());
- std::vector< std::pair<const PartDefinition *,double> > elts(sz);
- for(std::size_t i=0;i<sz;i++)
- elts[i]=std::pair<const PartDefinition *,double>(this,wgs[i]);
- return getPlayGround()->partition(elts);
-}
+// std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > PartDefinition::partition(const std::vector< const ComplexWeight *>& wgs) const
+// {
+// std::size_t sz(wgs.size());
+// std::vector< std::pair<const PartDefinition *, const ComplexWeight *> > elts(sz);
+// for(std::size_t i=0;i<sz;i++)
+// elts[i]=std::pair<const PartDefinition *, const ComplexWeight *>(this,wgs[i]);
+// return getPlayGround()->partition(elts);
+// }
-YACS::BASES::AutoRefCnt<PartDefinition> PartDefinition::BuildFrom(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& coreIds)
+YACS::BASES::AutoRefCnt<PartDefinition> PartDefinition::BuildFrom(const PlayGround *pg, const std::vector<int>& coreIds)
{
int spaceSz(pg->getNumberOfCoresAvailable()),sz(coreIds.size());
if(sz>spaceSz)
throw Exception("PartDefinition::BuildFrom : error ! The content of core Ids is not OK 2 !");
if(zeEnd-zeStart+1!=sz)
{
- YACS::BASES::AutoRefCnt<PartDefinition> pd(new NonContigPartDefinition(pg,nbOfCoresPerComp,coreIds));
+ YACS::BASES::AutoRefCnt<PartDefinition> pd(new NonContigPartDefinition(pg,coreIds));
return pd;
}
if(sz==spaceSz)
{
- YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg,nbOfCoresPerComp));
+ YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg));
return pd;
}
- YACS::BASES::AutoRefCnt<PartDefinition> pd(new ContigPartDefinition(pg,nbOfCoresPerComp,zeStart,zeEnd+1));
+ YACS::BASES::AutoRefCnt<PartDefinition> pd(new ContigPartDefinition(pg,zeStart,zeEnd+1));
return pd;
}
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<int> 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<int> 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);
}
}
//////////////////////
-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");
//////////////////////
-NonContigPartDefinition::NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& ids):PartDefinition(pg,nbOfCoresPerComp),_ids(ids)
+NonContigPartDefinition::NonContigPartDefinition(const PlayGround *pg, const std::vector<int>& ids):PartDefinition(pg),_ids(ids)
{
checkOKIds();
}
#include "YACSlibEngineExport.hxx"
#include "RefCounter.hxx"
#include "AutoRefCnt.hxx"
+#include "ComplexWeight.hxx"
#include <vector>
#include <string>
+#include <map>
namespace YACS
{
namespace ENGINE
{
- class PartDefinition;
+ class PartDefinition;
class YACSLIBENGINE_EXPORT PlayGround : public RefCounter
{
int getNumberOfCoresAvailable() const;
int getMaxNumberOfContainersCanBeHostedWithoutOverlap(int nbCoresPerCont) const;
std::vector<int> computeOffsets() const;
- std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< std::pair<const PartDefinition *,double> >& parts) const;
+ std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >& parts, const std::vector<int> &nbCoresPerShot) const;
int fromWorkerIdToResId(int workerId, int nbProcPerNode) const;
std::string deduceMachineFrom(int workerId, int nbProcPerNode) const;
int getNumberOfWorkers(int nbCoresPerWorker) const;
std::vector<std::size_t> getWorkerIdsFullyFetchedBy(int nbCoresPerComp, const std::vector<bool>& coreFlags) const;
static std::vector<int> BuildVectOfIdsFromVecBool(const std::vector<bool>& v);
static std::vector<int> GetIdsMatching(const std::vector<bool>& bigArr, const std::vector<bool>& pat);
- static std::vector<bool> FromUItoVB(unsigned int sz, unsigned int v);
- static unsigned int FromVBtoUI(const std::vector<bool>& v);
private:
- std::vector< std::vector<int> > splitIntoParts(const std::vector<int>& coreIds, const std::vector<int>& nbCoresConso, const std::vector<double>& weights) const;
+ std::vector< std::pair <const ComplexWeight *, int> > bigToTiny(const std::vector< std::pair <const ComplexWeight *, int> > &weights, std::map<int,int> &saveOrder) const;
+ std::vector< std::vector<int> > backToOriginalOrder(const std::vector< std::vector<int> > &disorderVec, const std::map<int,int> &saveOrder) const;
+ int getCriticalPath(const std::vector<std::pair <const ComplexWeight *, int > >& weights, const std::vector<int>& maxNbOfCores) const;
+ std::vector< std::vector<int> > splitIntoParts(const std::vector<int>& coreIds, const std::vector<std::pair <const ComplexWeight *, int> >& weights) const;
std::vector<int> takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector<bool>& distributionOfCores, bool lastOne=false) const;
private:
void checkCoherentInfo() const;
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<PartDefinition> > partition(const std::vector< double >& wgs) const;
- static YACS::BASES::AutoRefCnt<PartDefinition> BuildFrom(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& coreIds);
+ //std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< const ComplexWeight *>& wgs) const;
+ static YACS::BASES::AutoRefCnt<PartDefinition> BuildFrom(const PlayGround *pg, const std::vector<int>& 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<PartDefinition>& pdStashed, YACS::BASES::AutoRefCnt<PartDefinition>& pdRemain) const;
std::vector<std::size_t> computeWorkerIdsCovered(int nbCoresPerComp) const;
virtual int getNumberOfCoresConsumed() const = 0;
private:
YACS::BASES::AutoConstRefCnt<PlayGround> _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<bool> getCoresOn() const;
class YACSLIBENGINE_EXPORT NonContigPartDefinition : public PartDefinition
{
public:
- NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& ids);
+ NonContigPartDefinition(const PlayGround *pg, const std::vector<int>& ids);
NonContigPartDefinition(const ContigPartDefinition& other);
std::string printSelf() const;
std::vector<bool> getCoresOn() const;
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<bool> getCoresOn() 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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
AbstractPoint *findPointWithNode(Node *node);
const std::list<AbstractPoint *>& getListOfPoints() const;
int getMaxLevelOfParallelism() const;
- double getWeightRegardingDPL() const;
+ void getWeightRegardingDPL(ComplexWeight *weight);
void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const;
AbstractPoint *getUniqueAndReleaseIt() const;
private:
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap)
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<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
void edRemoveChild(Node *node) throw(Exception);
std::list<InputPort *> getSetOfInputPort() const;
_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;
_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;
if(node->getExecutionMode()==InlineNode::LOCAL_STR)
_out << indent(depth) << "<inline name=\"" << node->getName() << "\"";
else
- _out << indent(depth) << "<remote name=\"" << node->getName() << "\"";
+ {
+ _out << indent(depth) << "<remote name=\"" << node->getName() << "\"";
+ _out << " elementaryWeight=\"" << node->getWeight()->getElementaryWeight() << "\"";
+ }
if (node->getState() == YACS::DISABLED)
_out << " state=\"disabled\">" << endl;
else
if(node->getExecutionMode()==InlineNode::LOCAL_STR)
_out << indent(depth) << "<inline name=\"" << node->getName() << "\"";
else
- _out << indent(depth) << "<remote name=\"" << node->getName() << "\"";
+ {
+ _out << indent(depth) << "<remote name=\"" << node->getName() << "\"";
+ _out << " elementaryWeight=\"" << node->getWeight()->getElementaryWeight() << "\"";
+ }
if (node->getState() == YACS::DISABLED)
_out << " state=\"disabled\">" << endl;
else
//
// 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 <std_vector.i>
+%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;
namespace ENGINE
{
class PartDefinition;
-
+
class PlayGround : public RefCounter
{
public:
return self->printSelf();
}
- std::vector< YACS::BASES::AutoRefCnt<YACS::ENGINE::PartDefinition> > partition(const std::vector< std::pair< YACS::ENGINE::PartDefinition *,double> >& parts) const
+ std::vector< YACS::BASES::AutoRefCnt<YACS::ENGINE::PartDefinition> > partition(const std::vector< std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *> >& parts, const std::vector<int> &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<sz;i++)
- partsCpp[i]=std::pair<const YACS::ENGINE::PartDefinition *,double >(parts[i].first,parts[i].second);
- return self->partition(partsCpp);
+ partsCpp[i]=std::pair<const YACS::ENGINE::PartDefinition *, const YACS::ENGINE::ComplexWeight *>(parts[i].first, parts[i].second);
+ return self->partition(partsCpp, nbCoresPerShot);
}
}
private:
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
class NonContigPartDefinition : public PartDefinition
{
public:
- NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& ids);
+ NonContigPartDefinition(const PlayGround *pg, const std::vector<int>& ids);
std::vector<int> getIDs() const;
%extend
{
class AllPartDefinition : public PartDefinition
{
public:
- AllPartDefinition(const PlayGround *pg, int nbOfCoresPerComp);
+ AllPartDefinition(const PlayGround *pg);
%extend
{
std::string __str__() const
return (long)self;
}
}
-
+%include <ComplexWeight.hxx>
%include <ElementaryNode.hxx>
%include <InlineNode.hxx>
%include <ServiceNode.hxx>
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))
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))
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
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]);
}
}
_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)
{
return this->_node;
}
std::string _kind;
+ double _weight;
};
template <class T> inlinetypeParser<T> inlinetypeParser<T>::inlineParser;
DEBTRACE( "inline_script: " << f._code )
_node=theRuntime->createScriptNode(_kind,_name);
_node->setScript(f._code);
+ if(_weight>0)_node->setWeight(_weight);
}
template <>
fnode=theRuntime->createFuncNode(_kind,_name);
fnode->setScript(f._code);
fnode->setFname(f._name);
+ if(_weight>0)fnode->setWeight(_weight);
_node=fnode;
}
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();
virtual void pre ()
{
_nbranch=0;
- _weight=1;
+ _weight=-1.;
this->looptypeParser<T>::pre();
}
virtual void name (const std::string& name)
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 + '.');
}
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]);
virtual void pre ()
{
_nbranch=0;
- _weight=1;
+ _weight=-1.;
this->looptypeParser<T>::pre();
}
virtual void name (const std::string& name)
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 + '.');
}
fnode->setScript(f._code);
fnode->setFname(f._name);
fnode->setExecutionMode("remote");
+ if (this->_weight>0)fnode->setWeight(this->_weight);
this->_node=fnode;
}
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;
}
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)
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
#############################
# 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)
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)
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)
##
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")
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)
#
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")
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()==-1.)
+ 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__':
time.sleep(2)
o2=2*i1
""")
+ n10.setWeight(4.)
i1=n10.edAddInputPort("i1",ti)
o2=n10.edAddOutputPort("o2",ti)
p.edAddChild(n1)
#
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