]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/engine/Bloc.cxx
Salome HOME
First implementation of evalyfx.
[modules/yacs.git] / src / engine / Bloc.cxx
index efe4dba100aeb60e6d2b51603fd20f75536e6647..d4822f5b5494c05a023a091406727dc72b00a016 100644 (file)
@@ -27,6 +27,7 @@
 #include "Visitor.hxx"
 
 #include <iostream>
+#include <numeric>
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
@@ -393,6 +394,45 @@ void Bloc::accept(Visitor* visitor)
   visitor->visitBloc(this);
 }
 
+/*!
+ * Returns the max level of parallelism is this. The max of parallelism is equal to the sum of the max parallelism level
+ * for all concurrent branches in \a this.
+ */
+int Bloc::getMaxLevelOfParallelism() const
+{
+  std::set<Node *> s(_setOfNode.begin(),_setOfNode.end());
+  for(std::set<Node *>::const_iterator it=s.begin();it!=s.end();it++)
+    (*it)->_colour=White;
+  std::vector<int> levs;
+  while(!s.empty())
+    {
+      Node *seed(*(s.begin()));
+      int myCurLev(0);
+      while(seed)
+        {
+          s.erase(seed);
+          std::set<InGate *> ingates(seed->getOutGate()->edSetInGate());
+          int myCurLev2(1);
+          for(std::set<InGate *>::const_iterator it=ingates.begin();it!=ingates.end();it++)
+            {
+              Node *curNode((*it)->getNode());
+              curNode->_colour=Grey;
+              myCurLev2=std::max(curNode->getMaxLevelOfParallelism(),myCurLev2);
+            }
+          myCurLev=std::max(myCurLev,myCurLev2);
+          seed=0;
+          for(std::set<Node *>::const_iterator it=s.begin();it!=s.end();it++)
+            if((*it)->_colour==Grey)
+              {
+                seed=*it;
+                break;
+              }
+        }
+      levs.push_back(myCurLev);
+    }
+  return std::accumulate(levs.begin(),levs.end(),0);
+}
+
 /*!
  * Updates mutable structures _fwLinks and _bwLinks with the result of computation (CPU consuming method).
  * _fwLinks is a map with a Node* as key and a set<Node*> as value. The set gives