const char DynParaLoop::NAME_OF_SPLITTED_SEQ_OUT[] = "evalSamples";
const char DynParaLoop::OLD_NAME_OF_SPLITTED_SEQ_OUT[] = "SmplPrt"; // For backward compatibility with 5.1.4
-DynParaLoop::DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted)
+DynParaLoop::DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted, std::unique_ptr<NbBranchesAbstract>&& branchManager)
: ComposedNode(name),_node(0),_initNode(0),_finalizeNode(0),_nbOfEltConsumed(0),
- _nbOfBranches(this),
+ _nbOfBranches(std::move(branchManager)),
_splittedPort(NAME_OF_SPLITTED_SEQ_OUT,this,typeOfDataSplitted),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(), _loopWeight(0)
{
_weight.setDefaultLoop();
}
DynParaLoop::DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly)
- : ComposedNode(other,father), _nbOfBranches(other._nbOfBranches,this),
+ : ComposedNode(other,father),_nbOfBranches(other._nbOfBranches->copy(this)),
_splittedPort(other._splittedPort,this), _node(0), _initNode(0), _finalizeNode(0),
_nbOfEltConsumed(0),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(other._weight), _loopWeight(other._loopWeight)
{
_node->init(start);
if (_initNode) _initNode->init(start);
if (_finalizeNode) _finalizeNode->init(start);
- _nbOfBranches.exInit(start);
+ _nbOfBranches->exInit(start);
_splittedPort.exInit();
_nbOfEltConsumed=0;
_failedCounter=0;
std::list<InputPort *> DynParaLoop::getSetOfInputPort() const
{
list<InputPort *> ret=ComposedNode::getSetOfInputPort();
- ret.push_back(_nbOfBranches.getPort());
+ InputPort *port(_nbOfBranches->getPort());
+ if(port)
+ ret.push_back(port);
return ret;
}
InputPort *DynParaLoop::getInputPort(const std::string& name) const throw(YACS::Exception)
{
- if(NbBranches::IsBranchPortName(name))
- return _nbOfBranches.getPort();
+ if(_nbOfBranches->isMyName(name))
+ return _nbOfBranches->getPort();
return ComposedNode::getInputPort(name);
}
std::list<InputPort *> DynParaLoop::getLocalInputPorts() const
{
list<InputPort *> ret=ComposedNode::getLocalInputPorts();
- ret.push_back(_nbOfBranches.getPort());
+ InputPort *port(_nbOfBranches->getPort());
+ if(port)
+ ret.push_back(port);
return ret;
}
bool DynParaLoop::isMultiplicitySpecified(unsigned& value) const
{
- return _nbOfBranches.isMultiplicitySpecified(value);
+ return _nbOfBranches->isMultiplicitySpecified(value);
}
void DynParaLoop::forceMultiplicity(unsigned value)
{
- _nbOfBranches.forceMultiplicity(value);
+ _nbOfBranches->forceMultiplicity(value);
}
void DynParaLoop::buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView)
int DynParaLoop::getMaxLevelOfParallelism() const
{
- return _nbOfBranches.getIntValue() * _node->getMaxLevelOfParallelism();
+ return _nbOfBranches->getIntValue() * _node->getMaxLevelOfParallelism();
}
void DynParaLoop::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap)
#include "OutputPort.hxx"
#include "NbBranches.hxx"
+#include <memory>
+
namespace YACS
{
namespace ENGINE
Node *_finalizeNode;
unsigned _nbOfEltConsumed;
std::vector<int> _execIds;
- NbBranches _nbOfBranches;
+ //NbBranches _nbOfBranches2;
+ std::unique_ptr<NbBranchesAbstract> _nbOfBranches;
AnyOutputPort _splittedPort;
std::vector<Node *> _execNodes;
std::vector<Node *> _execInitNodes;
static const char NAME_OF_SPLITTED_SEQ_OUT[];
static const char OLD_NAME_OF_SPLITTED_SEQ_OUT[];
protected:
- DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted);
+ DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted, std::unique_ptr<NbBranchesAbstract>&& branchManager);
virtual ~DynParaLoop();
DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
public:
Node *edSetFinalizeNode(Node *DISOWNnode);
virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
void init(bool start=true);
- InputPort *edGetNbOfBranchesPort() { return _nbOfBranches.getPort(); }
+ InputPort *edGetNbOfBranchesPort() { return _nbOfBranches->getPort(); }
int getNumberOfInputPorts() const;
int getNumberOfOutputPorts() const;
unsigned getNumberOfEltsConsumed() const { return _nbOfEltConsumed; }
}
}
-ForEachLoop::ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted):DynParaLoop(name,typeOfDataSplitted),
+ForEachLoop::ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted):DynParaLoop(name,typeOfDataSplitted,std::unique_ptr<NbBranchesAbstract>(new NbBranches(this))),
_splitterNode(NAME_OF_SPLITTERNODE,typeOfDataSplitted,this),
_execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
{
{
//internal graph update
int i;
- int nbOfBr(_nbOfBranches.getIntValue()),nbOfElts(_splitterNode.getNumberOfElements()),nbOfEltsDone(0);
+ int nbOfBr(_nbOfBranches->getIntValue()),nbOfElts(_splitterNode.getNumberOfElements()),nbOfEltsDone(0);
if(_passedData)
{
_passedData->checkCompatibilyWithNb(nbOfElts);
if(end->getNode() == &_splitterNode)
throw Exception("Illegal link within a foreach loop: \
the 'SmplsCollection' port cannot be linked within the scope of the loop.");
- if(end == _nbOfBranches.getPort())
+ if(end == _nbOfBranches->getPort())
throw Exception("Illegal link within a foreach loop: \
the 'nbBranches' port cannot be linked within the scope of the loop.");
}
int ForEachLoop::getNbOfElementsToBeProcessed() const
{
- int nbBranches = _nbOfBranches.getIntValue();
+ int nbBranches = _nbOfBranches->getIntValue();
return _splitterNode.getNumberOfElements()
+ (_initNode ? nbBranches:0)
+ (_finalizeNode ? nbBranches:0) ;
using namespace YACS::ENGINE;
-const char NbBranches::NAME_OF_NUMBER_OF_BRANCHES[]="nbBranches";
+const char NbBranchesAbstract::NAME_OF_NUMBER_OF_BRANCHES[]="nbBranches";
+
+bool NbBranchesAbstract::IsBranchPortName(const std::string& name)
+{
+ return name == NAME_OF_NUMBER_OF_BRANCHES;
+}
+
+std::unique_ptr<NbBranchesAbstract> NbBranches::copy(Node *node) const
+{
+ return std::unique_ptr<NbBranchesAbstract>(new NbBranches(*this,node));
+}
+
+bool NbBranches::isMyName(const std::string& name) const
+{
+ return NbBranchesAbstract::IsBranchPortName(name);
+}
void NbBranches::exInit(bool start)
{
_nbOfBranches.edInit((int)value);
}
-bool NbBranches::IsBranchPortName(const std::string& name)
+std::unique_ptr<NbBranchesAbstract> NoNbBranches::copy(Node *) const
{
- return name == NAME_OF_NUMBER_OF_BRANCHES;
-}
\ No newline at end of file
+ return std::unique_ptr<NbBranchesAbstract>(new NoNbBranches);
+}
+
+void NoNbBranches::exInit(bool start)
+{
+}
+
+InputPort *NoNbBranches::getPort() const
+{
+ return nullptr;
+}
+
+bool NoNbBranches::isMultiplicitySpecified(unsigned& value) const
+{
+ return false;
+}
+
+void NoNbBranches::forceMultiplicity(unsigned value)
+{
+ throw Exception("NoNbBranches::forceMultiplicity : impossible to be forced !");
+}
+
+int NoNbBranches::getIntValue() const
+{
+ throw Exception("NoNbBranches::getIntValue : no value stored !");
+}
#include "YACSlibEngineExport.hxx"
#include "AnyInputPort.hxx"
+#include <memory>
+
namespace YACS
{
namespace ENGINE
{
class Node;
- class YACSLIBENGINE_EXPORT NbBranches
+ class YACSLIBENGINE_EXPORT NbBranchesAbstract
+ {
+ public:
+ virtual std::unique_ptr<NbBranchesAbstract> copy(Node *node) const = 0;
+ virtual bool isMyName(const std::string& name) const = 0;
+ virtual void exInit(bool start) = 0;
+ virtual InputPort *getPort() const = 0;
+ virtual bool isMultiplicitySpecified(unsigned& value) const = 0;
+ virtual void forceMultiplicity(unsigned value) = 0;
+ virtual int getIntValue() const = 0;
+ static bool IsBranchPortName(const std::string& name);
+ protected:
+ static const char NAME_OF_NUMBER_OF_BRANCHES[];
+ };
+
+ class YACSLIBENGINE_EXPORT NbBranches : public NbBranchesAbstract
{
public:
NbBranches(Node *node):_nbOfBranches(NAME_OF_NUMBER_OF_BRANCHES,node,Runtime::_tc_int) { }
NbBranches(const NbBranches& other, Node *node):_nbOfBranches(other._nbOfBranches,node) { }
- void exInit(bool start);
- InputPort *getPort() const;
- bool isMultiplicitySpecified(unsigned& value) const;
- void forceMultiplicity(unsigned value);
- int getIntValue() const { return _nbOfBranches.getIntValue(); }
- static bool IsBranchPortName(const std::string& name);
+ bool isMyName(const std::string& name) const override;
+ std::unique_ptr<NbBranchesAbstract> copy(Node *node) const override;
+ void exInit(bool start) override;
+ InputPort *getPort() const override;
+ bool isMultiplicitySpecified(unsigned& value) const override;
+ void forceMultiplicity(unsigned value) override;
+ int getIntValue() const override { return _nbOfBranches.getIntValue(); }
private:
AnyInputPort _nbOfBranches;
- static const char NAME_OF_NUMBER_OF_BRANCHES[];
+ };
+
+ class YACSLIBENGINE_EXPORT NoNbBranches : public NbBranchesAbstract
+ {
+ public:
+ NoNbBranches() = default;
+ std::unique_ptr<NbBranchesAbstract> copy(Node *node) const override;
+ bool isMyName(const std::string& name) const override { return false; }
+ void exInit(bool start) override;
+ InputPort *getPort() const override;
+ bool isMultiplicitySpecified(unsigned& value) const override;
+ void forceMultiplicity(unsigned value) override;
+ int getIntValue() const override;
};
}
}
OptimizerLoop::OptimizerLoop(const std::string& name, const std::string& algLibWthOutExt,
const std::string& symbolNameToOptimizerAlgBaseInstanceFactory,
bool algInitOnFile,bool initAlgo, Proc * procForTypes):
- DynParaLoop(name,Runtime::_tc_string),_algInitOnFile(algInitOnFile),_alglib(algLibWthOutExt),
+ DynParaLoop(name,Runtime::_tc_string,std::unique_ptr<NbBranchesAbstract>(new NbBranches(this))),_algInitOnFile(algInitOnFile),_alglib(algLibWthOutExt),
_algoInitPort(NAME_OF_ALGO_INIT_PORT, this, Runtime::_tc_string, true),
_loader(NULL),_alg(0),_convergenceReachedWithOtherCalc(false),
_retPortForOutPool(NAME_OF_OUT_POOL_INPUT,this,Runtime::_tc_string),
//internal graph update
int i;
- int nbOfBr=_nbOfBranches.getIntValue();
+ int nbOfBr=_nbOfBranches->getIntValue();
_alg->setNbOfBranches(nbOfBr);
_alg->startProxy();
{
// Run the finalize nodes, the OptimizerLoop will be done only when they all finish
_unfinishedCounter = 0; // This counter indicates how many branches are not finished
- for (int i=0 ; i<_nbOfBranches.getIntValue() ; i++)
+ for (int i=0 ; i<_nbOfBranches->getIntValue() ; i++)
if (_execIds[i] == NOT_RUNNING_BRANCH_ID)
{
DEBTRACE("Launching finalize node for branch " << i)
linkName += start->getName()+" to "+end->getName()+")";
// Yes, it should be possible to link back the result port to any input port of the loop.
- if(end == _nbOfBranches.getPort() || end == &_algoInitPort)
+ if(end == _nbOfBranches->getPort() || end == &_algoInitPort)
if(start != &_algoResultPort)
throw Exception(std::string("Illegal OptimizerLoop link.") + linkName);
else