The Gaudi Framework  v28r3 (cc1cf868)
concurrency::PrecedenceRulesGraph Class Reference

#include <src/PrecedenceRulesGraph.h>

Inheritance diagram for concurrency::PrecedenceRulesGraph:
Collaboration diagram for concurrency::PrecedenceRulesGraph:

Public Member Functions

 PrecedenceRulesGraph (const std::string &name, SmartIF< ISvcLocator > svc)
 Constructor. More...
 
 ~PrecedenceRulesGraph () override
 Destructor. More...
 
StatusCode initialize (const std::unordered_map< std::string, unsigned int > &algname_index_map)
 Initialize graph. More...
 
StatusCode initialize (const std::unordered_map< std::string, unsigned int > &algname_index_map, std::vector< EventSlot > &eventSlots)
 
void registerIODataObjects (const Algorithm *algo)
 Register algorithm in the Data Dependency index. More...
 
StatusCode buildDataDependenciesRealm ()
 Build data dependency realm WITHOUT data object nodes: just interconnect algorithm nodes directly. More...
 
StatusCode buildAugmentedDataDependenciesRealm ()
 Build data dependency realm WITH data object nodes participating. More...
 
void addHeadNode (const std::string &headName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
 Add a node, which has no parents. More...
 
StatusCode addAlgorithmNode (Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
 Add algorithm node. More...
 
template<class T >
void attachAlgorithmsToNodes (const std::string &algo_name, const T &container)
 Attach pointers to real Algorithms (and their clones) to Algorithm nodes of the graph. More...
 
AlgorithmNodegetAlgorithmNode (const std::string &algoName) const
 Get the AlgorithmNode from by algorithm name using graph index. More...
 
StatusCode addDataNode (const DataObjID &dataPath)
 Add DataNode that represents DataObject. More...
 
DataNodegetDataNode (const DataObjID &dataPath) const
 Get DataNode by DataObject path using graph index. More...
 
StatusCode addDecisionHubNode (Algorithm *daughterAlgo, const std::string &parentName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
 Add a node, which aggregates decisions of direct daughter nodes. More...
 
unsigned int getControlFlowNodeCounter () const
 Get total number of graph nodes. More...
 
void updateEventState (AlgsExecutionStates &states, std::vector< int > &node_decisions) const
 XXX CF tests. Is needed for older CF implementation. More...
 
void updateDecision (const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
 A method to update algorithm node decision, and propagate it upwards. More...
 
void rankAlgorithms (IGraphVisitor &ranker) const
 Rank Algorithm nodes by the number of data outputs. More...
 
void printState (std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const
 Print a string representing the control flow state. More...
 
const std::vector< AlgorithmNode * > getDataIndependentNodes () const
 
const std::stringname () const override
 Retrieve name of the service. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
const std::chrono::system_clock::time_point getInitTime () const
 
AlgsExecutionStatesgetAlgoStates (const int &slotNum) const
 
std::vector< int > & getNodeDecisions (const int &slotNum) const
 
std::string dumpDataFlow () const
 Print out all data origins and destinations, as reflected in the EF graph. More...
 
std::string dumpControlFlow () const
 Print out control flow of Algorithms and Sequences. More...
 
void dumpExecutionPlan ()
 dump to file encountered execution plan More...
 
void addEdgeToExecutionPlan (const AlgorithmNode *u, const AlgorithmNode *v)
 set cause-effect connection between two algorithms in the execution plan More...
 
void dumpControlFlow (std::ostringstream &, ControlFlowNode *, const int &) const
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Public Attributes

std::vector< EventSlot > * m_eventSlots
 

Private Attributes

friend ExecutionFlowManager
 
DecisionNodem_headNode
 the head node of the control flow graph; may want to have multiple ones once supporting trigger paths More...
 
AlgoNodesMap m_algoNameToAlgoNodeMap
 Index: map of algorithm's name to AlgorithmNode. More...
 
DecisionHubsMap m_decisionNameToDecisionHubMap
 Index: map of decision's name to DecisionHub. More...
 
DataNodesMap m_dataPathToDataNodeMap
 Index: map of data path to DataNode. More...
 
AlgoInputsMap m_algoNameToAlgoInputsMap
 Indexes: maps of algorithm's name to algorithm's inputs/outputs. More...
 
AlgoOutputsMap m_algoNameToAlgoOutputsMap
 
unsigned int m_nodeCounter
 Total number of nodes in the graph. More...
 
SmartIF< ISvcLocatorm_svcLocator
 Service locator (needed to access the MessageSvc) More...
 
const std::string m_name
 
const std::chrono::system_clock::time_point m_initTime
 
boost::ExecPlan m_ExecPlan
 temporary items to experiment with execution planning More...
 
std::map< std::string, boost::AlgoVertexm_exec_plan_map
 

Additional Inherited Members

- Public Types inherited from CommonMessaging< IPrecedenceRulesGraph >
using base_class = CommonMessaging
 
- Protected Member Functions inherited from CommonMessaging< IPrecedenceRulesGraph >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Detailed Description

Definition at line 293 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

concurrency::PrecedenceRulesGraph::PrecedenceRulesGraph ( const std::string name,
SmartIF< ISvcLocator svc 
)
inline

Constructor.

Definition at line 297 of file PrecedenceRulesGraph.h.

297  :
299  m_eventSlots(nullptr) {}
const std::chrono::system_clock::time_point m_initTime
std::vector< EventSlot > * m_eventSlots
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
unsigned int m_nodeCounter
Total number of nodes in the graph.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
concurrency::PrecedenceRulesGraph::~PrecedenceRulesGraph ( )
inlineoverride

Destructor.

Definition at line 301 of file PrecedenceRulesGraph.h.

301  {
302  if (m_headNode != 0) delete m_headNode;
303  }
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...

Member Function Documentation

StatusCode concurrency::PrecedenceRulesGraph::addAlgorithmNode ( Algorithm daughterAlgo,
const std::string parentName,
bool  inverted,
bool  allPass 
)

Add algorithm node.

Definition at line 588 of file PrecedenceRulesGraph.cpp.

590  {
591 
593 
594  auto& algoName = algo->name();
595 
596  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
597  concurrency::DecisionNode* parentNode;
598  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
599  parentNode = itP->second;
600  auto itA = m_algoNameToAlgoNodeMap.find( algoName );
601  concurrency::AlgorithmNode* algoNode;
602  if ( itA != m_algoNameToAlgoNodeMap.end() ) {
603  algoNode = itA->second;
604  } else {
605  algoNode = new concurrency::AlgorithmNode( *this, m_nodeCounter, algoName, inverted, allPass, algo->isIOBound() );
606  ++m_nodeCounter;
607  m_algoNameToAlgoNodeMap[algoName] = algoNode;
608  if (msgLevel(MSG::DEBUG))
609  debug() << "AlgoNode " << algoName << " added @ " << algoNode << endmsg;
610  registerIODataObjects(algo);
611  }
612 
613  parentNode->addDaughterNode( algoNode );
614  algoNode->addParentNode( parentNode );
615  } else {
616  sc = StatusCode::FAILURE;
617  error() << "Decision hub node " << parentName << ", requested to be parent, is not registered."
618  << endmsg;
619  }
620 
621  return sc;
622  }
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
void registerIODataObjects(const Algorithm *algo)
Register algorithm in the Data Dependency index.
unsigned int m_nodeCounter
Total number of nodes in the graph.
void addParentNode(DecisionNode *node)
XXX: CF tests. Method to add a parent node.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
StatusCode concurrency::PrecedenceRulesGraph::addDataNode ( const DataObjID dataPath)

Add DataNode that represents DataObject.

Definition at line 632 of file PrecedenceRulesGraph.cpp.

633  {
634 
635  StatusCode sc;
636 
637  auto itD = m_dataPathToDataNodeMap.find( dataPath );
638  concurrency::DataNode* dataNode;
639  if ( itD != m_dataPathToDataNodeMap.end() ) {
640  dataNode = itD->second;
641  sc = StatusCode::SUCCESS;
642  } else {
643  dataNode = new concurrency::DataNode( *this, dataPath );
644  m_dataPathToDataNodeMap[dataPath] = dataNode;
645  if (msgLevel(MSG::DEBUG))
646  debug() << " DataNode for " << dataPath << " added @ " << dataNode << endmsg;
647  sc = StatusCode::SUCCESS;
648  }
649 
650  return sc;
651  }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
StatusCode concurrency::PrecedenceRulesGraph::addDecisionHubNode ( Algorithm daughterAlgo,
const std::string parentName,
bool  modeConcurrent,
bool  modePromptDecision,
bool  modeOR,
bool  allPass 
)

Add a node, which aggregates decisions of direct daughter nodes.

Definition at line 661 of file PrecedenceRulesGraph.cpp.

663  {
664 
666 
667  auto& decisionHubName = decisionHubAlgo->name();
668 
669  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
670  concurrency::DecisionNode* parentNode;
671  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
672  parentNode = itP->second;
673  auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
674  concurrency::DecisionNode* decisionHubNode;
675  if ( itA != m_decisionNameToDecisionHubMap.end() ) {
676  decisionHubNode = itA->second;
677  } else {
678  decisionHubNode =
679  new concurrency::DecisionNode( *this, m_nodeCounter, decisionHubName, modeConcurrent, modePromptDecision, modeOR, allPass);
680  ++m_nodeCounter;
681  m_decisionNameToDecisionHubMap[decisionHubName] = decisionHubNode;
682  if (msgLevel(MSG::DEBUG))
683  debug() << "Decision hub node " << decisionHubName << " added @ " << decisionHubNode << endmsg;
684  }
685 
686  parentNode->addDaughterNode( decisionHubNode );
687  decisionHubNode->addParentNode( parentNode );
688  } else {
689  sc = StatusCode::FAILURE;
690  error() << "Decision hub node " << parentName << ", requested to be parent, is not registered."
691  << endmsg;
692  }
693 
694  return sc;
695  }
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
void addParentNode(DecisionNode *node)
XXX: CF tests. Method to add a parent node.
unsigned int m_nodeCounter
Total number of nodes in the graph.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
void concurrency::PrecedenceRulesGraph::addEdgeToExecutionPlan ( const AlgorithmNode u,
const AlgorithmNode v 
)

set cause-effect connection between two algorithms in the execution plan

Definition at line 841 of file PrecedenceRulesGraph.cpp.

842  {
843 
844  boost::AlgoVertex source;
845  float runtime( 0. );
846  if ( u == nullptr ) {
847  auto itT = m_exec_plan_map.find( "ENTRY" );
848  if ( itT != m_exec_plan_map.end() ) {
849  source = itT->second;
850  } else {
851  source = boost::add_vertex( boost::AlgoNodeStruct( "ENTRY", -999, -999, 0 ), m_ExecPlan );
852  m_exec_plan_map["ENTRY"] = source;
853  }
854  } else {
855  auto itS = m_exec_plan_map.find( u->getNodeName() );
856  if ( itS != m_exec_plan_map.end() ) {
857  source = itS->second;
858  } else {
859  auto alg = dynamic_cast<Algorithm*>( u->getAlgorithmRepresentatives()[0] );
860  if ( alg == 0 ) {
861  fatal() << "could not convert IAlgorithm to Algorithm!" << endmsg;
862  } else {
863  try {
864  const Gaudi::Details::PropertyBase& p = alg->getProperty( "AvgRuntime" );
865  runtime = std::stof( p.toString() );
866  } catch(...) {
867  if (msgLevel(MSG::DEBUG))
868  debug() << "no AvgRuntime for " << alg->name() << endmsg;
869  runtime = 1.;
870  }
871  }
872  source = boost::add_vertex( boost::AlgoNodeStruct( u->getNodeName(), u->getAlgoIndex(), u->getRank(), runtime ),
873  m_ExecPlan );
874  m_exec_plan_map[u->getNodeName()] = source;
875  }
876  }
877 
878  boost::AlgoVertex target;
879  auto itP = m_exec_plan_map.find( v->getNodeName() );
880  if ( itP != m_exec_plan_map.end() ) {
881  target = itP->second;
882  } else {
883  auto alg = dynamic_cast<Algorithm*>( v->getAlgorithmRepresentatives()[0] );
884  if ( alg == 0 ) {
885  fatal() << "could not convert IAlgorithm to Algorithm!" << endmsg;
886  } else {
887  try {
888  const Gaudi::Details::PropertyBase& p = alg->getProperty( "AvgRuntime" );
889  runtime = std::stof( p.toString() );
890  } catch(...) {
891  if (msgLevel(MSG::DEBUG))
892  debug() << "no AvgRuntime for " << alg->name() << endmsg;
893  runtime = 1.;
894  }
895  }
896  target = boost::add_vertex( boost::AlgoNodeStruct( v->getNodeName(), v->getAlgoIndex(), v->getRank(), runtime ),
897  m_ExecPlan );
898  m_exec_plan_map[v->getNodeName()] = target;
899  }
900 
901  if (msgLevel(MSG::DEBUG))
902  debug() << "Edge added to execution plan" << endmsg;
903  boost::add_edge(source, target, m_ExecPlan);
904  }
T stof(T...args)
T end(T...args)
virtual std::string toString() const =0
value -> string
graph_traits< ExecPlan >::vertex_descriptor AlgoVertex
std::map< std::string, boost::AlgoVertex > m_exec_plan_map
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
boost::ExecPlan m_ExecPlan
temporary items to experiment with execution planning
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void concurrency::PrecedenceRulesGraph::addHeadNode ( const std::string headName,
bool  modeConcurrent,
bool  modePromptDecision,
bool  modeOR,
bool  allPass 
)

Add a node, which has no parents.

Definition at line 698 of file PrecedenceRulesGraph.cpp.

699  {
700 
701  auto itH = m_decisionNameToDecisionHubMap.find( headName );
702  if ( itH != m_decisionNameToDecisionHubMap.end() ) {
703  m_headNode = itH->second;
704  } else {
705  m_headNode = new concurrency::DecisionNode( *this, m_nodeCounter, headName, modeConcurrent, modePromptDecision, modeOR, allPass );
706  ++m_nodeCounter;
708  }
709  }
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
T find(T...args)
unsigned int m_nodeCounter
Total number of nodes in the graph.
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
template<class T >
void concurrency::PrecedenceRulesGraph::attachAlgorithmsToNodes ( const std::string algo_name,
const T &  container 
)
inline

Attach pointers to real Algorithms (and their clones) to Algorithm nodes of the graph.

Definition at line 320 of file PrecedenceRulesGraph.h.

320  {
321  auto node = getAlgorithmNode(algo_name);
322  for (auto ialgoIt = container.unsafe_begin(); ialgoIt != container.unsafe_end(); ++ialgoIt)
323  node->attachAlgorithm(*ialgoIt);
324  }
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
StatusCode concurrency::PrecedenceRulesGraph::buildAugmentedDataDependenciesRealm ( )

Build data dependency realm WITH data object nodes participating.

Definition at line 529 of file PrecedenceRulesGraph.cpp.

530  {
531 
532  StatusCode global_sc( StatusCode::SUCCESS, true );
533 
534  // Create the DataObjects (DO) realm (represented by DataNodes in the graph),
535  // connected to DO producers (AlgorithmNodes)
536  for (auto algo : m_algoNameToAlgoNodeMap) {
537 
538  auto& outCollection = m_algoNameToAlgoOutputsMap[algo.first];
539  for (auto outputTag : outCollection) {
540  const auto sc = addDataNode(outputTag);
541  if (!sc.isSuccess()) {
542  error() << "Extra producer (" << algo.first << ") for DataObject @ "
543  << outputTag
544  << " has been detected: this is not allowed." << endmsg;
545  global_sc = sc;
546  }
547  auto dataNode = getDataNode(outputTag);
548  dataNode->addProducerNode(algo.second);
549  algo.second->addOutputDataNode(dataNode);
550  }
551  }
552 
553  // Connect previously created DO realm to DO consumers (AlgorithmNodes)
554  for ( auto algo : m_algoNameToAlgoNodeMap ) {
555  auto& inCollection = m_algoNameToAlgoInputsMap[algo.first];
556  for (auto inputTag : inCollection) {
557  DataNode* dataNode = nullptr;
558  auto primaryPath = inputTag;
559  auto itP = m_dataPathToDataNodeMap.find(primaryPath);
560  if (itP != m_dataPathToDataNodeMap.end()) {
561  dataNode = getDataNode(primaryPath);
562  //if (!inCollection[inputTag].alternativeDataProductNames().empty())
563  // warning() << "Dropping all alternative data dependencies in the graph, but '" << primaryPath
564  // << "', for algorithm " << algo.first << endmsg;
565  //} else {
566  // for (auto alterPath : inCollection[inputTag].alternativeDataProductNames()) {
567  // auto itAP = m_dataPathToDataNodeMap.find(alterPath);
568  // if (itAP != m_dataPathToDataNodeMap.end()) {
569  // dataNode = getDataNode(alterPath);
570  // warning() << "Dropping all alternative data dependencies in the graph, but '" << alterPath
571  // << "', for algorithm " << algo.first << endmsg;
572  // break;
573  // }
574  //}
575  }
576 
577  if (dataNode) {
578  dataNode->addConsumerNode(algo.second);
579  algo.second->addInputDataNode(dataNode);
580  }
581  }
582  }
583 
584  return global_sc;
585  }
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
T find(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
StatusCode concurrency::PrecedenceRulesGraph::buildDataDependenciesRealm ( )

Build data dependency realm WITHOUT data object nodes: just interconnect algorithm nodes directly.

Definition at line 476 of file PrecedenceRulesGraph.cpp.

477  {
478 
479  StatusCode global_sc( StatusCode::SUCCESS );
480 
481  for ( auto algo : m_algoNameToAlgoNodeMap ) {
482 
483  auto targetNode = m_algoNameToAlgoNodeMap[algo.first];
484 
485  // Find producers for all the inputs of the target node
486  auto& targetInCollection = m_algoNameToAlgoInputsMap[algo.first];
487  for (auto inputTag : targetInCollection) {
488  for (auto producer : m_algoNameToAlgoOutputsMap) {
489  auto& outputs = m_algoNameToAlgoOutputsMap[producer.first];
490  for (auto outputTag : outputs) {
491  if (inputTag == outputTag) {
492  auto& known_producers = targetNode->getSupplierNodes();
493  auto valid_producer = m_algoNameToAlgoNodeMap[producer.first];
494  auto& known_consumers = valid_producer->getConsumerNodes();
495  if ( std::find( known_producers.begin(), known_producers.end(), valid_producer ) ==
496  known_producers.end() )
497  targetNode->addSupplierNode( valid_producer );
498  if ( std::find( known_consumers.begin(), known_consumers.end(), targetNode ) == known_consumers.end() )
499  valid_producer->addConsumerNode( targetNode );
500  }
501  }
502  }
503  }
504 
505  // Find consumers for all the outputs of the target node
506  auto& targetOutCollection = m_algoNameToAlgoOutputsMap[algo.first];
507  for (auto outputTag : targetOutCollection) {
508  for (auto consumer : m_algoNameToAlgoInputsMap) {
509  auto& inputs = m_algoNameToAlgoInputsMap[consumer.first];
510  for (auto inputTag : inputs) {
511  if (inputTag == outputTag) {
512  auto& known_consumers = targetNode->getConsumerNodes();
513  auto valid_consumer = m_algoNameToAlgoNodeMap[consumer.first];
514  auto& known_producers = valid_consumer->getSupplierNodes();
515  if ( std::find( known_producers.begin(), known_producers.end(), targetNode ) == known_producers.end() )
516  valid_consumer->addSupplierNode( targetNode );
517  if ( std::find( known_consumers.begin(), known_consumers.end(), valid_consumer ) ==
518  known_consumers.end() )
519  targetNode->addConsumerNode( valid_consumer );
520  }
521  }
522  }
523  }
524  }
525  return global_sc;
526  }
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
std::string concurrency::PrecedenceRulesGraph::dumpControlFlow ( ) const

Print out control flow of Algorithms and Sequences.

Definition at line 758 of file PrecedenceRulesGraph.cpp.

758  {
759  std::ostringstream ost;
761  return ost.str();
762  }
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
void concurrency::PrecedenceRulesGraph::dumpControlFlow ( std::ostringstream ost,
ControlFlowNode node,
const int &  indent 
) const

Definition at line 764 of file PrecedenceRulesGraph.cpp.

766  {
767  ost << std::string(indent*2, ' ');
768  DecisionNode *dn = dynamic_cast<DecisionNode*> (node);
769  AlgorithmNode *an = dynamic_cast<AlgorithmNode*> (node);
770  if ( dn != 0 ) {
771  if (node != m_headNode) {
772  ost << node->getNodeName() << " [Seq] ";
773  ost << ( (dn->m_modeConcurrent) ? " [Concurrent] " : " [Sequential] " );
774  ost << ( (dn->m_modePromptDecision) ? " [Prompt] " : "" );
775  ost << ( (dn->m_modeOR) ? " [OR] " : "" );
776  ost << ( (dn->m_allPass) ? " [PASS] " : "" );
777  ost << "\n";
778  }
779  const std::vector<ControlFlowNode*>& dth = dn->getDaughters();
781  itr != dth.end(); ++itr) {
782  dumpControlFlow(ost,*itr,indent+1);
783  }
784  } else if (an != 0) {
785  ost << node->getNodeName() << " [Alg] ";
786  if (an != 0) {
787  auto ar = an->getAlgorithmRepresentatives();
788  ost << " [n= " << ar.at(0)->cardinality() << "]";
789  ost << ( (! ar.at(0)->isClonable()) ? " [unclonable] " : "" );
790  }
791  ost << "\n";
792  }
793 
794  }
T end(T...args)
STL class.
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
STL class.
T begin(T...args)
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
std::string concurrency::PrecedenceRulesGraph::dumpDataFlow ( ) const

Print out all data origins and destinations, as reflected in the EF graph.

Definition at line 797 of file PrecedenceRulesGraph.cpp.

798  {
799 
800  const char idt[] = " ";
801  std::ostringstream ost;
802 
803  ost << "\n" << idt << "====================================\n";
804  ost << idt << "Data origins and destinations:\n";
805  ost << idt << "====================================\n";
806 
807  for ( auto& pair : m_dataPathToDataNodeMap ) {
808 
809  for ( auto algoNode : pair.second->getProducers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
810 
811  ost << idt << " V\n";
812  ost << idt << " o " << pair.first << "\n";
813  ost << idt << " V\n";
814 
815  for ( auto algoNode : pair.second->getConsumers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
816 
817  ost << idt << "====================================\n";
818  }
819 
820  return ost.str();
821  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void concurrency::PrecedenceRulesGraph::dumpExecutionPlan ( )

dump to file encountered execution plan

Definition at line 825 of file PrecedenceRulesGraph.cpp.

826  {
827  std::ofstream myfile;
828  myfile.open( "ExecutionPlan.graphml", std::ios::app );
829 
830  boost::dynamic_properties dp;
831  dp.property( "name", boost::get( &boost::AlgoNodeStruct::m_name, m_ExecPlan ) );
832  dp.property( "index", boost::get( &boost::AlgoNodeStruct::m_index, m_ExecPlan ) );
833  dp.property( "rank", boost::get( &boost::AlgoNodeStruct::m_rank, m_ExecPlan ) );
834  dp.property( "runtime", boost::get( &boost::AlgoNodeStruct::m_runtime, m_ExecPlan ) );
835 
836  boost::write_graphml( myfile, m_ExecPlan, dp );
837 
838  myfile.close();
839  }
T open(T...args)
STL class.
T close(T...args)
boost::ExecPlan m_ExecPlan
temporary items to experiment with execution planning
AlgorithmNode * concurrency::PrecedenceRulesGraph::getAlgorithmNode ( const std::string algoName) const

Get the AlgorithmNode from by algorithm name using graph index.

Definition at line 625 of file PrecedenceRulesGraph.cpp.

626  {
627 
628  return m_algoNameToAlgoNodeMap.at( algoName );
629  }
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
AlgsExecutionStates& concurrency::PrecedenceRulesGraph::getAlgoStates ( const int &  slotNum) const
inline

Definition at line 359 of file PrecedenceRulesGraph.h.

359 {return m_eventSlots->at(slotNum).algsStates;}
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:37
T at(T...args)
std::vector< EventSlot > * m_eventSlots
unsigned int concurrency::PrecedenceRulesGraph::getControlFlowNodeCounter ( ) const
inline

Get total number of graph nodes.

Definition at line 334 of file PrecedenceRulesGraph.h.

334 {return m_nodeCounter;}
unsigned int m_nodeCounter
Total number of nodes in the graph.
const std::vector< AlgorithmNode * > concurrency::PrecedenceRulesGraph::getDataIndependentNodes ( ) const

Definition at line 744 of file PrecedenceRulesGraph.cpp.

745  {
746 
748 
749  for (auto node : m_algoNameToAlgoInputsMap) {
750  DataObjIDColl collection = (node.second);
751  if (collection.empty())
752  result.push_back(getAlgorithmNode(node.first));
753  }
754 
755  return result;
756  }
T empty(T...args)
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
T push_back(T...args)
STL class.
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
DataNode * concurrency::PrecedenceRulesGraph::getDataNode ( const DataObjID dataPath) const

Get DataNode by DataObject path using graph index.

Definition at line 654 of file PrecedenceRulesGraph.cpp.

655  {
656 
657  return m_dataPathToDataNodeMap.at( dataPath );
658  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
const std::chrono::system_clock::time_point concurrency::PrecedenceRulesGraph::getInitTime ( ) const
inline

Definition at line 357 of file PrecedenceRulesGraph.h.

357 {return m_initTime;}
const std::chrono::system_clock::time_point m_initTime
std::vector<int>& concurrency::PrecedenceRulesGraph::getNodeDecisions ( const int &  slotNum) const
inline

Definition at line 361 of file PrecedenceRulesGraph.h.

361 {return m_eventSlots->at(slotNum).controlFlowState;}
T at(T...args)
std::vector< EventSlot > * m_eventSlots
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:43
StatusCode concurrency::PrecedenceRulesGraph::initialize ( const std::unordered_map< std::string, unsigned int > &  algname_index_map)

Initialize graph.

Definition at line 423 of file PrecedenceRulesGraph.cpp.

424  {
425 
426  m_headNode->initialize( algname_index_map );
427  // StatusCode sc = buildDataDependenciesRealm();
429 
430  if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
431 
432  return sc;
433  }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode buildAugmentedDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map) override
Initialize.
StatusCode concurrency::PrecedenceRulesGraph::initialize ( const std::unordered_map< std::string, unsigned int > &  algname_index_map,
std::vector< EventSlot > &  eventSlots 
)

Definition at line 436 of file PrecedenceRulesGraph.cpp.

438  {
439 
440  m_eventSlots = &eventSlots;
441  m_headNode->initialize( algname_index_map );
442  // StatusCode sc = buildDataDependenciesRealm();
444 
445  if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
446 
447  if (msgLevel(MSG::DEBUG))
448  debug() << dumpDataFlow() << endmsg;
449 
450  return sc;
451  }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::vector< EventSlot > * m_eventSlots
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
StatusCode buildAugmentedDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map) override
Initialize.
const std::string& concurrency::PrecedenceRulesGraph::name ( ) const
inlineoverride

Retrieve name of the service.

Definition at line 353 of file PrecedenceRulesGraph.h.

353 {return m_name;}
void concurrency::PrecedenceRulesGraph::printState ( std::stringstream output,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
inline

Print a string representing the control flow state.

Definition at line 346 of file PrecedenceRulesGraph.h.

349  {m_headNode->printState(output,states,node_decisions,recursionLevel);}
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
void concurrency::PrecedenceRulesGraph::rankAlgorithms ( IGraphVisitor ranker) const

Rank Algorithm nodes by the number of data outputs.

Definition at line 730 of file PrecedenceRulesGraph.cpp.

731  {
732 
733  info() << "Starting ranking by data outputs .. " << endmsg;
734  for (auto& pair : m_algoNameToAlgoNodeMap) {
735  if (msgLevel(MSG::DEBUG))
736  debug() << " Ranking " << pair.first << "... " << endmsg;
737  pair.second->accept(ranker);
738  if (msgLevel(MSG::DEBUG))
739  debug() << " ... rank of " << pair.first << ": " << pair.second->getRank() << endmsg;
740  }
741  }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void concurrency::PrecedenceRulesGraph::registerIODataObjects ( const Algorithm algo)

Register algorithm in the Data Dependency index.

Definition at line 454 of file PrecedenceRulesGraph.cpp.

455  {
456 
457  const std::string& algoName = algo->name();
458 
459  m_algoNameToAlgoInputsMap[algoName] = algo->inputDataObjs();
460  m_algoNameToAlgoOutputsMap[algoName] = algo->outputDataObjs();
461 
462  if (msgLevel(MSG::DEBUG)) {
463  debug() << "Inputs of " << algoName << ": ";
464  for (auto tag : algo->inputDataObjs())
465  debug() << tag << " | ";
466  debug() << endmsg;
467 
468  debug() << "Outputs of " << algoName << ": ";
469  for (auto tag : algo->outputDataObjs())
470  debug() << tag << " | ";
471  debug() << endmsg;
472  }
473  }
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:750
const DataObjIDColl & outputDataObjs() const override
STL class.
const DataObjIDColl & inputDataObjs() const override
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
SmartIF<ISvcLocator>& concurrency::PrecedenceRulesGraph::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 355 of file PrecedenceRulesGraph.h.

355 {return m_svcLocator;}
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
void concurrency::PrecedenceRulesGraph::updateDecision ( const std::string algo_name,
const int &  slotNum,
AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const

A method to update algorithm node decision, and propagate it upwards.

Definition at line 718 of file PrecedenceRulesGraph.cpp.

720  {
721  //if (msgLevel(MSG::DEBUG))
722  // debug() << "(UPDATING)Setting decision of algorithm " << algo_name << " and propagating it upwards.." << endmsg;
723  //getAlgorithmNode( algo_name )->updateDecision( slotNum, algo_states, node_decisions );
724  auto& slot = (*m_eventSlots)[slotNum];
725  auto updater = DecisionUpdater(slot);
726  getAlgorithmNode( algo_name )->accept(updater);
727  }
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
bool accept(IGraphVisitor &visitor) override
void concurrency::PrecedenceRulesGraph::updateEventState ( AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const

XXX CF tests. Is needed for older CF implementation.

Definition at line 712 of file PrecedenceRulesGraph.cpp.

713  {
714  m_headNode->updateState( algo_states, node_decisions );
715  }
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
int updateState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
Method to set algos to CONTROLREADY, if possible.

Member Data Documentation

friend concurrency::PrecedenceRulesGraph::ExecutionFlowManager
private

Definition at line 294 of file PrecedenceRulesGraph.h.

AlgoInputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoInputsMap
private

Indexes: maps of algorithm's name to algorithm's inputs/outputs.

Definition at line 381 of file PrecedenceRulesGraph.h.

AlgoNodesMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoNodeMap
private

Index: map of algorithm's name to AlgorithmNode.

Definition at line 375 of file PrecedenceRulesGraph.h.

AlgoOutputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoOutputsMap
private

Definition at line 382 of file PrecedenceRulesGraph.h.

DataNodesMap concurrency::PrecedenceRulesGraph::m_dataPathToDataNodeMap
private

Index: map of data path to DataNode.

Definition at line 379 of file PrecedenceRulesGraph.h.

DecisionHubsMap concurrency::PrecedenceRulesGraph::m_decisionNameToDecisionHubMap
private

Index: map of decision's name to DecisionHub.

Definition at line 377 of file PrecedenceRulesGraph.h.

std::vector<EventSlot>* concurrency::PrecedenceRulesGraph::m_eventSlots

Definition at line 393 of file PrecedenceRulesGraph.h.

std::map<std::string,boost::AlgoVertex> concurrency::PrecedenceRulesGraph::m_exec_plan_map
private

Definition at line 391 of file PrecedenceRulesGraph.h.

boost::ExecPlan concurrency::PrecedenceRulesGraph::m_ExecPlan
private

temporary items to experiment with execution planning

Definition at line 390 of file PrecedenceRulesGraph.h.

DecisionNode* concurrency::PrecedenceRulesGraph::m_headNode
private

the head node of the control flow graph; may want to have multiple ones once supporting trigger paths

Definition at line 373 of file PrecedenceRulesGraph.h.

const std::chrono::system_clock::time_point concurrency::PrecedenceRulesGraph::m_initTime
private

Definition at line 388 of file PrecedenceRulesGraph.h.

const std::string concurrency::PrecedenceRulesGraph::m_name
private

Definition at line 387 of file PrecedenceRulesGraph.h.

unsigned int concurrency::PrecedenceRulesGraph::m_nodeCounter
private

Total number of nodes in the graph.

Definition at line 384 of file PrecedenceRulesGraph.h.

SmartIF<ISvcLocator> concurrency::PrecedenceRulesGraph::m_svcLocator
mutableprivate

Service locator (needed to access the MessageSvc)

Definition at line 386 of file PrecedenceRulesGraph.h.


The documentation for this class was generated from the following files: