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...
 
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...
 
- 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...
 

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
 
std::vector< EventSlot > * m_eventSlots
 
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 280 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 284 of file PrecedenceRulesGraph.h.

284  :
286  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 288 of file PrecedenceRulesGraph.h.

288  {
289  if (m_headNode != 0) delete m_headNode;
290  }
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 608 of file PrecedenceRulesGraph.cpp.

610  {
611 
613 
614  auto& algoName = algo->name();
615 
616  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
617  concurrency::DecisionNode* parentNode;
618  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
619  parentNode = itP->second;
620  auto itA = m_algoNameToAlgoNodeMap.find( algoName );
621  concurrency::AlgorithmNode* algoNode;
622  if ( itA != m_algoNameToAlgoNodeMap.end() ) {
623  algoNode = itA->second;
624  } else {
625  algoNode = new concurrency::AlgorithmNode( *this, m_nodeCounter, algoName, inverted, allPass, algo->isIOBound() );
626  ++m_nodeCounter;
627  m_algoNameToAlgoNodeMap[algoName] = algoNode;
628  if (msgLevel(MSG::DEBUG))
629  debug() << "AlgoNode " << algoName << " added @ " << algoNode << endmsg;
630  registerIODataObjects(algo);
631  }
632 
633  parentNode->addDaughterNode( algoNode );
634  algoNode->addParentNode( parentNode );
635  } else {
636  sc = StatusCode::FAILURE;
637  error() << "Decision hub node " << parentName << ", requested to be parent, is not registered."
638  << endmsg;
639  }
640 
641  return sc;
642  }
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 652 of file PrecedenceRulesGraph.cpp.

653  {
654 
655  StatusCode sc;
656 
657  auto itD = m_dataPathToDataNodeMap.find( dataPath );
658  concurrency::DataNode* dataNode;
659  if ( itD != m_dataPathToDataNodeMap.end() ) {
660  dataNode = itD->second;
661  sc = StatusCode::SUCCESS;
662  } else {
663  dataNode = new concurrency::DataNode( *this, dataPath );
664  m_dataPathToDataNodeMap[dataPath] = dataNode;
665  if (msgLevel(MSG::DEBUG))
666  debug() << " DataNode for " << dataPath << " added @ " << dataNode << endmsg;
667  sc = StatusCode::SUCCESS;
668  }
669 
670  return sc;
671  }
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 681 of file PrecedenceRulesGraph.cpp.

683  {
684 
686 
687  auto& decisionHubName = decisionHubAlgo->name();
688 
689  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
690  concurrency::DecisionNode* parentNode;
691  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
692  parentNode = itP->second;
693  auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
694  concurrency::DecisionNode* decisionHubNode;
695  if ( itA != m_decisionNameToDecisionHubMap.end() ) {
696  decisionHubNode = itA->second;
697  } else {
698  decisionHubNode =
699  new concurrency::DecisionNode( *this, m_nodeCounter, decisionHubName, modeConcurrent, modePromptDecision, modeOR, allPass);
700  ++m_nodeCounter;
701  m_decisionNameToDecisionHubMap[decisionHubName] = decisionHubNode;
702  if (msgLevel(MSG::DEBUG))
703  debug() << "Decision hub node " << decisionHubName << " added @ " << decisionHubNode << endmsg;
704  }
705 
706  parentNode->addDaughterNode( decisionHubNode );
707  decisionHubNode->addParentNode( parentNode );
708  } else {
709  sc = StatusCode::FAILURE;
710  error() << "Decision hub node " << parentName << ", requested to be parent, is not registered."
711  << endmsg;
712  }
713 
714  return sc;
715  }
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 820 of file PrecedenceRulesGraph.cpp.

821  {
822 
823  boost::AlgoVertex source;
824  float runtime( 0. );
825  if ( u == nullptr ) {
826  auto itT = m_exec_plan_map.find( "ENTRY" );
827  if ( itT != m_exec_plan_map.end() ) {
828  source = itT->second;
829  } else {
830  source = boost::add_vertex( boost::AlgoNodeStruct( "ENTRY", -999, -999, 0 ), m_ExecPlan );
831  m_exec_plan_map["ENTRY"] = source;
832  }
833  } else {
834  auto itS = m_exec_plan_map.find( u->getNodeName() );
835  if ( itS != m_exec_plan_map.end() ) {
836  source = itS->second;
837  } else {
838  auto alg = dynamic_cast<Algorithm*>( u->getAlgorithmRepresentatives()[0] );
839  if ( alg == 0 ) {
840  fatal() << "could not convert IAlgorithm to Algorithm!" << endmsg;
841  } else {
842  try {
843  const Gaudi::Details::PropertyBase& p = alg->getProperty( "AvgRuntime" );
844  runtime = std::stof( p.toString() );
845  } catch(...) {
846  if (msgLevel(MSG::DEBUG))
847  debug() << "no AvgRuntime for " << alg->name() << endmsg;
848  runtime = 1.;
849  }
850  }
851  source = boost::add_vertex( boost::AlgoNodeStruct( u->getNodeName(), u->getAlgoIndex(), u->getRank(), runtime ),
852  m_ExecPlan );
853  m_exec_plan_map[u->getNodeName()] = source;
854  }
855  }
856 
857  boost::AlgoVertex target;
858  auto itP = m_exec_plan_map.find( v->getNodeName() );
859  if ( itP != m_exec_plan_map.end() ) {
860  target = itP->second;
861  } else {
862  auto alg = dynamic_cast<Algorithm*>( v->getAlgorithmRepresentatives()[0] );
863  if ( alg == 0 ) {
864  fatal() << "could not convert IAlgorithm to Algorithm!" << endmsg;
865  } else {
866  try {
867  const Gaudi::Details::PropertyBase& p = alg->getProperty( "AvgRuntime" );
868  runtime = std::stof( p.toString() );
869  } catch(...) {
870  if (msgLevel(MSG::DEBUG))
871  debug() << "no AvgRuntime for " << alg->name() << endmsg;
872  runtime = 1.;
873  }
874  }
875  target = boost::add_vertex( boost::AlgoNodeStruct( v->getNodeName(), v->getAlgoIndex(), v->getRank(), runtime ),
876  m_ExecPlan );
877  m_exec_plan_map[v->getNodeName()] = target;
878  }
879 
880  if (msgLevel(MSG::DEBUG))
881  debug() << "Edge added to execution plan" << endmsg;
882  boost::add_edge(source, target, m_ExecPlan);
883  }
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 718 of file PrecedenceRulesGraph.cpp.

719  {
720 
721  auto itH = m_decisionNameToDecisionHubMap.find( headName );
722  if ( itH != m_decisionNameToDecisionHubMap.end() ) {
723  m_headNode = itH->second;
724  } else {
725  m_headNode = new concurrency::DecisionNode( *this, m_nodeCounter, headName, modeConcurrent, modePromptDecision, modeOR, allPass );
726  ++m_nodeCounter;
728  }
729  }
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 307 of file PrecedenceRulesGraph.h.

307  {
308  auto node = getAlgorithmNode(algo_name);
309  for (auto ialgoIt = container.unsafe_begin(); ialgoIt != container.unsafe_end(); ++ialgoIt)
310  node->attachAlgorithm(*ialgoIt);
311  }
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 549 of file PrecedenceRulesGraph.cpp.

550  {
551 
552  StatusCode global_sc( StatusCode::SUCCESS, true );
553 
554  // Create the DataObjects (DO) realm (represented by DataNodes in the graph),
555  // connected to DO producers (AlgorithmNodes)
556  for (auto algo : m_algoNameToAlgoNodeMap) {
557 
558  auto& outCollection = m_algoNameToAlgoOutputsMap[algo.first];
559  for (auto outputTag : outCollection) {
560  const auto sc = addDataNode(outputTag);
561  if (!sc.isSuccess()) {
562  error() << "Extra producer (" << algo.first << ") for DataObject @ "
563  << outputTag
564  << " has been detected: this is not allowed." << endmsg;
565  global_sc = sc;
566  }
567  auto dataNode = getDataNode(outputTag);
568  dataNode->addProducerNode(algo.second);
569  algo.second->addOutputDataNode(dataNode);
570  }
571  }
572 
573  // Connect previously created DO realm to DO consumers (AlgorithmNodes)
574  for ( auto algo : m_algoNameToAlgoNodeMap ) {
575  auto& inCollection = m_algoNameToAlgoInputsMap[algo.first];
576  for (auto inputTag : inCollection) {
577  DataNode* dataNode = nullptr;
578  auto primaryPath = inputTag;
579  auto itP = m_dataPathToDataNodeMap.find(primaryPath);
580  if (itP != m_dataPathToDataNodeMap.end()) {
581  dataNode = getDataNode(primaryPath);
582  //if (!inCollection[inputTag].alternativeDataProductNames().empty())
583  // warning() << "Dropping all alternative data dependencies in the graph, but '" << primaryPath
584  // << "', for algorithm " << algo.first << endmsg;
585  //} else {
586  // for (auto alterPath : inCollection[inputTag].alternativeDataProductNames()) {
587  // auto itAP = m_dataPathToDataNodeMap.find(alterPath);
588  // if (itAP != m_dataPathToDataNodeMap.end()) {
589  // dataNode = getDataNode(alterPath);
590  // warning() << "Dropping all alternative data dependencies in the graph, but '" << alterPath
591  // << "', for algorithm " << algo.first << endmsg;
592  // break;
593  // }
594  //}
595  }
596 
597  if (dataNode) {
598  dataNode->addConsumerNode(algo.second);
599  algo.second->addInputDataNode(dataNode);
600  }
601  }
602  }
603 
604  return global_sc;
605  }
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 496 of file PrecedenceRulesGraph.cpp.

497  {
498 
499  StatusCode global_sc( StatusCode::SUCCESS );
500 
501  for ( auto algo : m_algoNameToAlgoNodeMap ) {
502 
503  auto targetNode = m_algoNameToAlgoNodeMap[algo.first];
504 
505  // Find producers for all the inputs of the target node
506  auto& targetInCollection = m_algoNameToAlgoInputsMap[algo.first];
507  for (auto inputTag : targetInCollection) {
508  for (auto producer : m_algoNameToAlgoOutputsMap) {
509  auto& outputs = m_algoNameToAlgoOutputsMap[producer.first];
510  for (auto outputTag : outputs) {
511  if (inputTag == outputTag) {
512  auto& known_producers = targetNode->getSupplierNodes();
513  auto valid_producer = m_algoNameToAlgoNodeMap[producer.first];
514  auto& known_consumers = valid_producer->getConsumerNodes();
515  if ( std::find( known_producers.begin(), known_producers.end(), valid_producer ) ==
516  known_producers.end() )
517  targetNode->addSupplierNode( valid_producer );
518  if ( std::find( known_consumers.begin(), known_consumers.end(), targetNode ) == known_consumers.end() )
519  valid_producer->addConsumerNode( targetNode );
520  }
521  }
522  }
523  }
524 
525  // Find consumers for all the outputs of the target node
526  auto& targetOutCollection = m_algoNameToAlgoOutputsMap[algo.first];
527  for (auto outputTag : targetOutCollection) {
528  for (auto consumer : m_algoNameToAlgoInputsMap) {
529  auto& inputs = m_algoNameToAlgoInputsMap[consumer.first];
530  for (auto inputTag : inputs) {
531  if (inputTag == outputTag) {
532  auto& known_consumers = targetNode->getConsumerNodes();
533  auto valid_consumer = m_algoNameToAlgoNodeMap[consumer.first];
534  auto& known_producers = valid_consumer->getSupplierNodes();
535  if ( std::find( known_producers.begin(), known_producers.end(), targetNode ) == known_producers.end() )
536  valid_consumer->addSupplierNode( targetNode );
537  if ( std::find( known_consumers.begin(), known_consumers.end(), valid_consumer ) ==
538  known_consumers.end() )
539  targetNode->addConsumerNode( valid_consumer );
540  }
541  }
542  }
543  }
544  }
545  return global_sc;
546  }
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::dumpDataFlow ( ) const

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

Definition at line 776 of file PrecedenceRulesGraph.cpp.

777  {
778 
779  const char idt[] = " ";
780  std::ostringstream ost;
781 
782  ost << "\n" << idt << "====================================\n";
783  ost << idt << "Data origins and destinations:\n";
784  ost << idt << "====================================\n";
785 
786  for ( auto& pair : m_dataPathToDataNodeMap ) {
787 
788  for ( auto algoNode : pair.second->getProducers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
789 
790  ost << idt << " V\n";
791  ost << idt << " o " << pair.first << "\n";
792  ost << idt << " V\n";
793 
794  for ( auto algoNode : pair.second->getConsumers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
795 
796  ost << idt << "====================================\n";
797  }
798 
799  return ost.str();
800  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void concurrency::PrecedenceRulesGraph::dumpExecutionPlan ( )

dump to file encountered execution plan

Definition at line 804 of file PrecedenceRulesGraph.cpp.

805  {
806  std::ofstream myfile;
807  myfile.open( "ExecutionPlan.graphml", std::ios::app );
808 
809  boost::dynamic_properties dp;
810  dp.property( "name", boost::get( &boost::AlgoNodeStruct::m_name, m_ExecPlan ) );
811  dp.property( "index", boost::get( &boost::AlgoNodeStruct::m_index, m_ExecPlan ) );
812  dp.property( "rank", boost::get( &boost::AlgoNodeStruct::m_rank, m_ExecPlan ) );
813  dp.property( "runtime", boost::get( &boost::AlgoNodeStruct::m_runtime, m_ExecPlan ) );
814 
815  boost::write_graphml( myfile, m_ExecPlan, dp );
816 
817  myfile.close();
818  }
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 645 of file PrecedenceRulesGraph.cpp.

646  {
647 
648  return m_algoNameToAlgoNodeMap.at( algoName );
649  }
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
AlgsExecutionStates& concurrency::PrecedenceRulesGraph::getAlgoStates ( const int &  slotNum) const
inline

Definition at line 346 of file PrecedenceRulesGraph.h.

346 {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 321 of file PrecedenceRulesGraph.h.

321 {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 761 of file PrecedenceRulesGraph.cpp.

762  {
763 
765 
766  for (auto node : m_algoNameToAlgoInputsMap) {
767  DataObjIDColl collection = (node.second);
768  if (collection.empty())
769  result.push_back(getAlgorithmNode(node.first));
770  }
771 
772  return result;
773  }
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 674 of file PrecedenceRulesGraph.cpp.

675  {
676 
677  return m_dataPathToDataNodeMap.at( dataPath );
678  }
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 344 of file PrecedenceRulesGraph.h.

344 {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 348 of file PrecedenceRulesGraph.h.

348 {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 439 of file PrecedenceRulesGraph.cpp.

440  {
441 
442  m_headNode->initialize( algname_index_map );
443  // StatusCode sc = buildDataDependenciesRealm();
445 
446  if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
447 
448  return sc;
449  }
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 452 of file PrecedenceRulesGraph.cpp.

454  {
455 
456  m_eventSlots = &eventSlots;
457  m_headNode->initialize( algname_index_map );
458  // StatusCode sc = buildDataDependenciesRealm();
460 
461  if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
462 
463  if (msgLevel(MSG::DEBUG))
464  debug() << dumpDataFlow() << endmsg;
465 
466  return sc;
467  }
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 340 of file PrecedenceRulesGraph.h.

340 {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 333 of file PrecedenceRulesGraph.h.

336  {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 747 of file PrecedenceRulesGraph.cpp.

748  {
749 
750  info() << "Starting ranking by data outputs .. " << endmsg;
751  for (auto& pair : m_algoNameToAlgoNodeMap) {
752  if (msgLevel(MSG::DEBUG))
753  debug() << " Ranking " << pair.first << "... " << endmsg;
754  pair.second->accept(ranker);
755  if (msgLevel(MSG::DEBUG))
756  debug() << " ... rank of " << pair.first << ": " << pair.second->getRank() << endmsg;
757  }
758  }
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 470 of file PrecedenceRulesGraph.cpp.

471  {
472 
473  const std::string& algoName = algo->name();
474 
475  DataObjIDColl inputObjs, outputObjs;
476  DHHVisitor avis( inputObjs, outputObjs );
477  algo->acceptDHVisitor( &avis );
478 
479  m_algoNameToAlgoInputsMap[algoName] = inputObjs;
480  m_algoNameToAlgoOutputsMap[algoName] = outputObjs;
481 
482  if (msgLevel(MSG::DEBUG)) {
483  debug() << "Inputs of " << algoName << ": ";
484  for (auto tag : inputObjs)
485  debug() << tag << " | ";
486  debug() << endmsg;
487 
488  debug() << "Outputs of " << algoName << ": ";
489  for (auto tag : outputObjs)
490  debug() << tag << " | ";
491  debug() << endmsg;
492  }
493  }
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:715
virtual void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Algorithm.cpp:205
STL class.
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 342 of file PrecedenceRulesGraph.h.

342 {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 738 of file PrecedenceRulesGraph.cpp.

740  {
741  //if (msgLevel(MSG::DEBUG))
742  // debug() << "(UPDATING)Setting decision of algorithm " << algo_name << " and propagating it upwards.." << endmsg;
743  getAlgorithmNode( algo_name )->updateDecision( slotNum, algo_states, node_decisions );
744  }
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
void updateDecision(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const override
XXX: CF tests.
void concurrency::PrecedenceRulesGraph::updateEventState ( AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const

XXX CF tests. Is needed for older CF implementation.

Definition at line 732 of file PrecedenceRulesGraph.cpp.

733  {
734  m_headNode->updateState( algo_states, node_decisions );
735  }
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 281 of file PrecedenceRulesGraph.h.

AlgoInputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoInputsMap
private

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

Definition at line 366 of file PrecedenceRulesGraph.h.

AlgoNodesMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoNodeMap
private

Index: map of algorithm's name to AlgorithmNode.

Definition at line 360 of file PrecedenceRulesGraph.h.

AlgoOutputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoOutputsMap
private

Definition at line 367 of file PrecedenceRulesGraph.h.

DataNodesMap concurrency::PrecedenceRulesGraph::m_dataPathToDataNodeMap
private

Index: map of data path to DataNode.

Definition at line 364 of file PrecedenceRulesGraph.h.

DecisionHubsMap concurrency::PrecedenceRulesGraph::m_decisionNameToDecisionHubMap
private

Index: map of decision's name to DecisionHub.

Definition at line 362 of file PrecedenceRulesGraph.h.

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

Definition at line 375 of file PrecedenceRulesGraph.h.

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

Definition at line 378 of file PrecedenceRulesGraph.h.

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

temporary items to experiment with execution planning

Definition at line 377 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 358 of file PrecedenceRulesGraph.h.

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

Definition at line 373 of file PrecedenceRulesGraph.h.

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

Definition at line 372 of file PrecedenceRulesGraph.h.

unsigned int concurrency::PrecedenceRulesGraph::m_nodeCounter
private

Total number of nodes in the graph.

Definition at line 369 of file PrecedenceRulesGraph.h.

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

Service locator (needed to access the MessageSvc)

Definition at line 371 of file PrecedenceRulesGraph.h.


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