]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/engine/DynParaLoop.cxx
Salome HOME
Ready to unplug nbOfBranches from foreach
[modules/yacs.git] / src / engine / DynParaLoop.cxx
index db101aebadadf8de673135da8abc0b6eee390f4a..fd1b2b420b84d6586b7dafe9148dc7e427c15238 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2019  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
@@ -39,13 +39,12 @@ using namespace YACS::ENGINE;
 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
 
-const char DynParaLoop::NAME_OF_NUMBER_OF_BRANCHES[]="nbBranches";
-
-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(NAME_OF_NUMBER_OF_BRANCHES,this,Runtime::_tc_int),
-    _splittedPort(NAME_OF_SPLITTED_SEQ_OUT,this,typeOfDataSplitted),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0)
+    _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()
@@ -56,9 +55,9 @@ DynParaLoop::~DynParaLoop()
 }
 
 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)
+    _nbOfEltConsumed(0),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0),_weight(other._weight), _loopWeight(other._loopWeight)
 {
   if(other._node)
     _node=other._node->clone(this,editionOnly);
@@ -114,7 +113,7 @@ void DynParaLoop::init(bool start)
   _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;
@@ -275,21 +274,25 @@ std::list<Node *> DynParaLoop::edGetDirectDescendants() const
 std::list<InputPort *> DynParaLoop::getSetOfInputPort() const
 {
   list<InputPort *> ret=ComposedNode::getSetOfInputPort();
-  ret.push_back((InputPort *)&_nbOfBranches);
+  InputPort *port(_nbOfBranches->getPort());
+  if(port)
+    ret.push_back(port);
   return ret;
 }
 
 InputPort *DynParaLoop::getInputPort(const std::string& name) const throw(YACS::Exception)
 {
-  if(name==NAME_OF_NUMBER_OF_BRANCHES)
-    return (InputPort *)&_nbOfBranches;
+  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((InputPort *)&_nbOfBranches);
+  InputPort *port(_nbOfBranches->getPort());
+  if(port)
+    ret.push_back(port);
   return ret;
 }
 
@@ -371,8 +374,9 @@ void DynParaLoop::prepareInputsFromOutOfScope(int branchNb)
       if(portToSet)//portToSet==0 in case of portToSet==_splitterNode._dataPortToDispatch of ForEach
         {
           portToSet->put((const void *)val);
-          portToSet->edNotifyReferencedBy(0);//This is to indicate that somewhere somebody deals with this inputport
+          portToSet->edNotifyReferencedBy(nullptr,false);//This is to indicate that somewhere somebody deals with this inputport
           //even if no direct physical link exists. This exclusively for _execNodes[branchNb]::init on the next turn of loop.
+          //false is put as 2nd parameter to tell to portToSet, do not touch to the data in case of squeezeMemory.
         }
     }
 }
@@ -423,21 +427,28 @@ DynParaLoop::TypeOfNode DynParaLoop::getIdentityOfNotifyerNode(const Node *node,
       return FINALIZE_NODE;
 }
 
+void DynParaLoop::setWeight(double loopWeight)
+{
+  if(loopWeight<=0.)
+    throw Exception("DynParaLoop::setWeight : invalid input value !");
+  _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
 {
-  if(_nbOfBranches.edIsManuallyInitialized())
-    if(_nbOfBranches.edGetNumberOfLinks()==0)
-      {
-        value=_nbOfBranches.getIntValue();
-        return true;
-      }
-  return false;
+  return _nbOfBranches->isMultiplicitySpecified(value);
 }
 
 void DynParaLoop::forceMultiplicity(unsigned value)
 {
-  _nbOfBranches.edRemoveAllLinksLinkedWithMe();
-  _nbOfBranches.edInit((int)value);
+  _nbOfBranches->forceMultiplicity(value);
 }
 
 void DynParaLoop::buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView)
@@ -625,10 +636,13 @@ std::string DynParaLoop::getErrorReport()
         }
       for(vector<Node *>::iterator iter=_execNodes.begin();iter!=_execNodes.end();iter++)
         {
-          std::string rep=(*iter)->getErrorReport();
-          if(rep != "")
+          if(*iter)
             {
-              report=report+rep+"\n";
+              std::string rep=(*iter)->getErrorReport();
+              if(rep != "")
+                {
+                  report=report+rep+"\n";
+                }
             }
         }
       for(vector<Node *>::iterator iter=_execFinalizeNodes.begin();iter!=_execFinalizeNodes.end();iter++)
@@ -893,7 +907,15 @@ Node * DynParaLoop::getFinalizeNode()
 
 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)
+{
+  YACS::BASES::AutoRefCnt<PartDefinition> pd2(pd->copy());
+  zeMap[this]=pd2;
+  if(_node)
+    _node->partitionRegardingDPL(pd,zeMap);
 }
 
 void DynParaLoop::shutdown(int level)