X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fengine%2FBloc.cxx;h=6fc3240abfa88716d1fb14d9d23e3654f04aaa64;hb=53629c53c7f47f2d86aa47e31206e836290f055a;hp=422e3947099d20254774fec16953c5ee051f032c;hpb=88c5f67088445931a1598331e1faae6df0145c0b;p=modules%2Fyacs.git diff --git a/src/engine/Bloc.cxx b/src/engine/Bloc.cxx index 422e39470..6fc3240ab 100644 --- a/src/engine/Bloc.cxx +++ b/src/engine/Bloc.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2006-2014 CEA/DEN, EDF R&D +// Copyright (C) 2006-2016 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 @@ -25,8 +25,13 @@ #include "OutputDataStreamPort.hxx" #include "ElementaryNode.hxx" #include "Visitor.hxx" +#include "ForkBlocPoint.hxx" +#include "SetOfPoints.hxx" +#include "PlayGround.hxx" +#include #include +#include //#define _DEVDEBUG_ #include "YacsTrace.hxx" @@ -58,7 +63,10 @@ Bloc::Bloc(const Bloc& other, ComposedNode *father, bool editionOnly):StaticDefi { OutPort* pout = iter2->first; InPort* pin = iter2->second; - edAddLink(getOutPort(other.getPortName(pout)),getInPort(other.getPortName(pin))); + if(&other == getLowestCommonAncestor(pout->getNode(), pin->getNode())) + { + edAddLink(getOutPort(other.getPortName(pout)),getInPort(other.getPortName(pin))); + } } } @@ -220,6 +228,54 @@ void Bloc::edRemoveChild(Node *node) throw(YACS::Exception) } } +std::vector< std::list > Bloc::splitIntoIndependantGraph() const +{ + std::size_t sz(_setOfNode.size()); + list::const_iterator it=_setOfNode.begin(); + for(;it!=_setOfNode.end();it++) + (*it)->_colour=White; + it=_setOfNode.begin(); + std::vector< list > ret; + while(it!=_setOfNode.end()) + { + Node *start(*it); start->_colour=Grey; + ret.push_back(list()); + list& ll(ret.back()); + std::queue fifo; fifo.push(start); + while(!fifo.empty()) + { + Node *cur(fifo.front()); fifo.pop(); + ll.push_back(cur); + // + OutGate *og(cur->getOutGate()); + list og2(og->edSetInGate()); + for(list::const_iterator it2=og2.begin();it2!=og2.end();it2++) + { + Node *cur2((*it2)->getNode()); + if(cur2->_colour==White) + { + cur2->_colour=Grey; + fifo.push(cur2); + } + } + // + InGate *ig(cur->getInGate()); + list bl(ig->getBackLinks()); + for(list::const_iterator it3=bl.begin();it3!=bl.end();it3++) + { + Node *cur3((*it3)->getNode()); + if(cur3->_colour==White) + { + cur3->_colour=Grey; + fifo.push(cur3); + } + } + } + for(it=_setOfNode.begin();it!=_setOfNode.end() && (*it)->_colour!=White;it++); + } + return ret; +} + Node *Bloc::getChildByShortName(const std::string& name) const throw(YACS::Exception) { for (list::const_iterator iter = _setOfNode.begin(); iter != _setOfNode.end(); iter++) @@ -229,10 +285,6 @@ Node *Bloc::getChildByShortName(const std::string& name) const throw(YACS::Excep throw Exception(what); } -void Bloc::selectRunnableTasks(std::vector& tasks) -{ -} - bool Bloc::areAllSubNodesDone() const { for(list::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++) @@ -269,8 +321,8 @@ bool Bloc::isNameAlreadyUsed(const std::string& name) const bool insertNodeChildrenInSet(Node *node, std::set& nodeSet) { bool verdict=true; - set outNodes=node->getOutNodes(); - for (set::iterator iter=outNodes.begin();iter!=outNodes.end(); iter++) + list outNodes=node->getOutNodes(); + for (list::iterator iter=outNodes.begin();iter!=outNodes.end(); iter++) { verdict=(nodeSet.insert(*iter)).second; if (verdict) verdict = insertNodeChildrenInSet((*iter),nodeSet); @@ -300,8 +352,8 @@ std::vector< std::pair > Bloc::getSetOfInternalCFLinks() co vector< pair > ret; for(list::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++) { - set outCFLinksOfCurNode=(*iter)->_outGate.edSetInGate(); - for(set::iterator iter2=outCFLinksOfCurNode.begin();iter2!=outCFLinksOfCurNode.end();iter2++) + list outCFLinksOfCurNode=(*iter)->_outGate.edSetInGate(); + for(list::iterator iter2=outCFLinksOfCurNode.begin();iter2!=outCFLinksOfCurNode.end();iter2++) ret.push_back(pair(&(*iter)->_outGate,*iter2)); } return ret; @@ -353,7 +405,7 @@ YACS::Event Bloc::updateStateOnFinishedEventFrom(Node *node) * \param node : node that has emitted the event * \return the event to notify to bloc's father */ -YACS::Event Bloc::updateStateOnFailedEventFrom(Node *node) +YACS::Event Bloc::updateStateOnFailedEventFrom(Node *node, const Executor *execInst) { node->exForwardFailed(); if(areAllSubNodesFinished()) @@ -370,26 +422,26 @@ YACS::Event Bloc::updateStateOnFailedEventFrom(Node *node) void Bloc::writeDot(std::ostream &os) const { - os << " subgraph cluster_" << getId() << " {\n" ; - listnodes=getChildren(); - for(list::const_iterator iter=nodes.begin();iter!=nodes.end();iter++) + os << " subgraph cluster_" << getId() << " {\n" ; + listnodes=getChildren(); + for(list::const_iterator iter=nodes.begin();iter!=nodes.end();iter++) { - (*iter)->writeDot(os); - string p=(*iter)->getId(); - //not connected node - if((*iter)->_inGate._backLinks.size() == 0) os << getId() << " -> " << p << ";\n"; - setoutnodes = (*iter)->getOutNodes(); - for(set::const_iterator itout=outnodes.begin();itout!=outnodes.end();itout++) + (*iter)->writeDot(os); + string p=(*iter)->getId(); + //not connected node + if((*iter)->_inGate._backLinks.size() == 0) os << getId() << " -> " << p << ";\n"; + listoutnodes = (*iter)->getOutNodes(); + for(list::const_iterator itout=outnodes.begin();itout!=outnodes.end();itout++) { - os << p << " -> " << (*itout)->getId() << ";\n"; + os << p << " -> " << (*itout)->getId() << ";\n"; } } - os << "}\n" ; - os << getId() << "[fillcolor=\"" ; - YACS::StatesForNode state=getEffectiveState(); - os << getColorState(state); - os << "\" label=\"" << "Bloc:" ; - os << getQualifiedName() <<"\"];\n"; + os << "}\n" ; + os << getId() << "[fillcolor=\"" ; + YACS::StatesForNode state=getEffectiveState(); + os << getColorState(state); + os << "\" label=\"" << "Bloc:" ; + os << getQualifiedName() <<"\"];\n"; } void Bloc::accept(Visitor* visitor) @@ -398,20 +450,59 @@ void Bloc::accept(Visitor* visitor) } /*! - * 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 as value. The set gives - * all nodes that are forwardly connected to the key node - * _bwLinks is a map for backward dependencies - * The method is : for all CF link (n1->n2) - * add n2 and _fwLinks[n2] in forward dependencies of n1 and _bwLinks[n1] - * add n1 and _bwLinks[n1] in backward dependencies of n2 and _fwLinks[n2] - * For useless links - * If a node is already in a forward dependency when adding and the direct link - * already exists so it's a useless link (see the code !) + * 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. */ -void Bloc::performCFComputations(LinkInfo& info) const +int Bloc::getMaxLevelOfParallelism() const +{ + std::list< AbstractPoint * > pts(analyzeParallelism()); + ForkBlocPoint fbp(pts,NULL); + return fbp.getMaxLevelOfParallelism(); +} + +std::list< AbstractPoint * > Bloc::analyzeParallelism() const +{ + std::vector< std::list > r(splitIntoIndependantGraph()); + std::list< AbstractPoint * > pts; + for(std::vector< std::list >::const_iterator it=r.begin();it!=r.end();it++) + { + SetOfPoints sop(*it); + sop.simplify(); + pts.push_back(sop.getUniqueAndReleaseIt()); + } + return pts; +} + +double Bloc::getWeightRegardingDPL() const +{ + std::list< AbstractPoint * > pts(analyzeParallelism()); + ForkBlocPoint fbp(pts,NULL); + return fbp.getWeightRegardingDPL(); +} + +void Bloc::removeRecursivelyRedundantCL() +{ + StaticDefinedComposedNode::removeRecursivelyRedundantCL(); + LinkInfo info(I_CF_USELESS); + initComputation(); + performCFComputationsOnlyOneLevel(info); + std::set< std::pair > linksToKill(info.getInfoUselessLinks()); + for(std::set< std::pair >::const_iterator it=linksToKill.begin();it!=linksToKill.end();it++) + edRemoveCFLink((*it).first,(*it).second); + destructCFComputations(info); +} + +void Bloc::partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) +{ + if(!pd) + throw Exception("Bloc::partitionRegardingDPL : NULL pointer !"); + std::list< AbstractPoint * > pts(analyzeParallelism()); + ForkBlocPoint fbp(pts,NULL); + fbp.partitionRegardingDPL(pd,zeMap); +} + +void Bloc::performCFComputationsOnlyOneLevel(LinkInfo& info) const { - StaticDefinedComposedNode::performCFComputations(info); delete _fwLinks;//Normally useless delete _bwLinks;//Normally useless _fwLinks=new map >; @@ -423,8 +514,8 @@ void Bloc::performCFComputations(LinkInfo& info) const for(list::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++) { Node* n1=*iter; - std::set ingates=n1->getOutGate()->edSetInGate(); - for(std::set::const_iterator it2=ingates.begin();it2!=ingates.end();it2++) + std::list ingates=n1->getOutGate()->edSetInGate(); + for(std::list::const_iterator it2=ingates.begin();it2!=ingates.end();it2++) { //CF link : n1 -> (*it2)->getNode() Node* n2=(*it2)->getNode(); @@ -482,6 +573,24 @@ void Bloc::performCFComputations(LinkInfo& info) const } } +/*! + * 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 as value. The set gives + * all nodes that are forwardly connected to the key node + * _bwLinks is a map for backward dependencies + * The method is : for all CF link (n1->n2) + * add n2 and _fwLinks[n2] in forward dependencies of n1 and _bwLinks[n1] + * add n1 and _bwLinks[n1] in backward dependencies of n2 and _fwLinks[n2] + * For useless links + * If a node is already in a forward dependency when adding and the direct link + * already exists so it's a useless link (see the code !) + */ +void Bloc::performCFComputations(LinkInfo& info) const +{ + StaticDefinedComposedNode::performCFComputations(info); + performCFComputationsOnlyOneLevel(info); +} + void Bloc::destructCFComputations(LinkInfo& info) const { StaticDefinedComposedNode::destructCFComputations(info); @@ -789,9 +898,8 @@ void Bloc::findUselessLinksIn(const std::list< std::vector >& res , Link set searcher(iter2+1,(*whereToPeerAt).end());//to boost research for(;iter2!=((*whereToPeerAt).end()-2);iter2++) { - map::iterator iter4; - map& nexts=(*iter2)->getOutGate()->edMapInGate(); - for(iter4=nexts.begin();iter4!=nexts.end();iter4++) + list< pair >& nexts=(*iter2)->getOutGate()->edMapInGate(); + for(list< pair >::iterator iter4=nexts.begin();iter4!=nexts.end();iter4++) if((*iter4).first->getNode()!=*(iter2+1)) if(searcher.find((*iter4).first->getNode())!=searcher.end()) info.pushUselessCFLink(*iter2,(*iter4).first->getNode());