Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
concurrency::ExecutionFlowManager Class Reference

Manage the execution flow using a graph of task precedence rules Once initialized, the graph is const and can be shared across events. More...

#include <GaudiHive/src/ExecutionFlowManager.h>

Inheritance diagram for concurrency::ExecutionFlowManager:
Collaboration diagram for concurrency::ExecutionFlowManager:

Public Member Functions

 ExecutionFlowManager ()
 Constructor. More...
 
 ~ExecutionFlowManager () override=default
 Destructor. More...
 
StatusCode initialize (PrecedenceRulesGraph *graph, const std::unordered_map< std::string, unsigned int > &algname_index_map)
 Initialize the control flow manager It greps the topalg list and the index map for the algo names. More...
 
StatusCode initialize (PrecedenceRulesGraph *graph, const std::unordered_map< std::string, unsigned int > &algname_index_map, std::vector< EventSlot > &eventSlots, const std::string &mode)
 
void simulateExecutionFlow (IGraphVisitor &visitor) const
 
PrecedenceRulesGraphgetPrecedenceRulesGraph () const
 Get the flow graph instance. More...
 
bool needsAlgorithmToRun (const unsigned int iAlgo) const
 A little bit silly, but who cares. ;-) More...
 
void updateEventState (AlgsExecutionStates &algo_states, std::vector< int > &node_decisions) const
 Update the state of algorithms to controlready, where possible. More...
 
void updateDecision (const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
 
void updateEventState (AlgsExecutionStates &algo_states) const
 XXX: CF tests. More...
 
void promoteToControlReadyState (AlgsExecutionStates &algo_states, std::vector< int > &node_decisions, const int &slotNum=-1) const
 XXX: CF tests. More...
 
bool algoDataDependenciesSatisfied (const std::string &algo_name, const int &slotNum) const
 Check all data dependencies of an algorithm are satisfied. More...
 
bool rootDecisionResolved (const std::vector< int > &node_decisions) const
 Check whether root decision was resolved. More...
 
void printEventState (std::stringstream &ss, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const
 Print the state of the control flow for a given event. More...
 
void touchReadyAlgorithms (IGraphVisitor &visitor) const
 Promote all algorithms, ready to be executed, to DataReady state. More...
 
const std::stringname () const override
 Retrieve name of the service. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. 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

std::string m_name
 
PrecedenceRulesGraphm_PRGraph
 the graph of precedence rules More...
 

Additional Inherited Members

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

Detailed Description

Manage the execution flow using a graph of task precedence rules Once initialized, the graph is const and can be shared across events.

Author
Benedikt Hegner
Illya Shapoval

Definition at line 21 of file ExecutionFlowManager.h.

Constructor & Destructor Documentation

concurrency::ExecutionFlowManager::ExecutionFlowManager ( )
inline

Constructor.

Definition at line 24 of file ExecutionFlowManager.h.

24 : m_name("ExecutionFlowManager"), m_PRGraph(0) {};
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
concurrency::ExecutionFlowManager::~ExecutionFlowManager ( )
overridedefault

Destructor.

Member Function Documentation

bool concurrency::ExecutionFlowManager::algoDataDependenciesSatisfied ( const std::string algo_name,
const int &  slotNum 
) const

Check all data dependencies of an algorithm are satisfied.

Definition at line 116 of file ExecutionFlowManager.cpp.

116  {
117  return m_PRGraph->getAlgorithmNode(algo_name)->dataDependenciesSatisfied(slotNum);
118  }
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
PrecedenceRulesGraph* concurrency::ExecutionFlowManager::getPrecedenceRulesGraph ( ) const
inline

Get the flow graph instance.

Definition at line 38 of file ExecutionFlowManager.h.

38 {return m_PRGraph;}
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
StatusCode concurrency::ExecutionFlowManager::initialize ( PrecedenceRulesGraph graph,
const std::unordered_map< std::string, unsigned int > &  algname_index_map 
)

Initialize the control flow manager It greps the topalg list and the index map for the algo names.

Definition at line 6 of file ExecutionFlowManager.cpp.

7  {
9  StatusCode sc = graph->initialize(algname_index_map);
10  if (!sc.isSuccess())
11  error() << "Could not initialize the flow graph." << endmsg;
12 
13  return sc;
14  }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
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
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode concurrency::ExecutionFlowManager::initialize ( PrecedenceRulesGraph graph,
const std::unordered_map< std::string, unsigned int > &  algname_index_map,
std::vector< EventSlot > &  eventSlots,
const std::string mode 
)

Definition at line 17 of file ExecutionFlowManager.cpp.

20  {
21  m_PRGraph = graph;
22  StatusCode sc = graph->initialize(algname_index_map, eventSlots);
23  if (!sc.isSuccess()) {
24  error() << "Could not initialize the execution flow graph." << endmsg;
25  return sc;
26  }
27 
28  // Rank algorithms if any known optimization mode is supplied
29  if (mode == "PCE") {
31  m_PRGraph->rankAlgorithms(ranker);
32  } else if (mode == "COD") {
34  m_PRGraph->rankAlgorithms(ranker);
35  } else if (mode == "E") {
36  auto ranker = concurrency::RankerByEccentricity();
37  m_PRGraph->rankAlgorithms(ranker);
38  } else if (mode == "T") {
39  auto ranker = concurrency::RankerByTiming();
40  m_PRGraph->rankAlgorithms(ranker);
41  } else if (mode == "DRE") {
43  m_PRGraph->rankAlgorithms(ranker);
44  } else if (!mode.empty()){
45  error() << "Requested optimization mode '" << mode << "' is not known." << endmsg;
47  }
48 
49  return sc;
50  }
T empty(T...args)
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
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
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const std::string& concurrency::ExecutionFlowManager::name ( ) const
inlineoverride

Retrieve name of the service.

Definition at line 67 of file ExecutionFlowManager.h.

bool concurrency::ExecutionFlowManager::needsAlgorithmToRun ( const unsigned int  iAlgo) const

A little bit silly, but who cares. ;-)

void concurrency::ExecutionFlowManager::printEventState ( std::stringstream ss,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
inline

Print the state of the control flow for a given event.

Definition at line 60 of file ExecutionFlowManager.h.

63  {m_PRGraph->printState(ss,states,node_decisions,recursionLevel);}
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.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
void concurrency::ExecutionFlowManager::promoteToControlReadyState ( AlgsExecutionStates algo_states,
std::vector< int > &  node_decisions,
const int &  slotNum = -1 
) const

XXX: CF tests.

Definition at line 109 of file ExecutionFlowManager.cpp.

111  {
112  m_PRGraph->m_headNode->promoteToControlReadyState(slotNum, algo_states, node_decisions);
113  }
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
bool concurrency::ExecutionFlowManager::rootDecisionResolved ( const std::vector< int > &  node_decisions) const

Check whether root decision was resolved.

Definition at line 121 of file ExecutionFlowManager.cpp.

121  {
122 
123  return (-1 != node_decisions[m_PRGraph->m_headNode->getNodeIndex()]) ? true : false;
124  }
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
const unsigned int & getNodeIndex() const
XXX: CF tests.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
SmartIF<ISvcLocator>& concurrency::ExecutionFlowManager::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 69 of file ExecutionFlowManager.h.

69 {return m_PRGraph->serviceLocator();}
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
void concurrency::ExecutionFlowManager::simulateExecutionFlow ( IGraphVisitor visitor) const

Definition at line 53 of file ExecutionFlowManager.cpp.

53  {
54 
55  std::vector<int>& nodeDecisions = m_PRGraph->getNodeDecisions(0);
56 
57  std::vector<int> fixedNodeDecisions;
58  int cntr = 0;
59  std::vector<int> counters;
60  while (!rootDecisionResolved(nodeDecisions)) {
61  cntr += 1;
62  int prevAlgosNum = visitor.m_nodesSucceeded;
63  debug() << " Proceeding with iteration #" << cntr << endmsg;
64  fixedNodeDecisions = m_PRGraph->getNodeDecisions(0);
65  m_PRGraph->m_headNode->accept(visitor);
66  if ( fixedNodeDecisions == nodeDecisions) {
67  error() << " No progress on iteration " << cntr << " detected" << endmsg;
68  debug() << nodeDecisions << endmsg;
69  break;
70  }
71  info() << " Iteration #" << cntr << " finished, total algorithms executed: " << visitor.m_nodesSucceeded << endmsg;
72 
74  s << cntr << ", " << (visitor.m_nodesSucceeded-prevAlgosNum) << "\n";
75 
76  std::ofstream myfile;
77  myfile.open("RunSimulation.csv", std::ios::app);
78  myfile << s.str();
79  myfile.close();
80 
81 
82  if (visitor.m_nodesSucceeded != prevAlgosNum)
83  counters.push_back(visitor.m_nodesSucceeded);
84  }
85 
86  info() << "Asymptotical concurrency speedup depth: " << (float) visitor.m_nodesSucceeded / (float) counters.size() << endmsg;
87 
88  // Reset algorithm states and node decisions
90  nodeDecisions.assign(nodeDecisions.size(),-1);
91 
92  }
T open(T...args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::vector< int > & getNodeDecisions(const int &slotNum) const
bool accept(IGraphVisitor &visitor) override
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
STL class.
bool rootDecisionResolved(const std::vector< int > &node_decisions) const
Check whether root decision was resolved.
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
T str(T...args)
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
T size(T...args)
T assign(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
string s
Definition: gaudirun.py:245
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void concurrency::ExecutionFlowManager::touchReadyAlgorithms ( IGraphVisitor visitor) const

Promote all algorithms, ready to be executed, to DataReady state.

Definition at line 127 of file ExecutionFlowManager.cpp.

127  {
128 
129  //auto& states = m_PRGraph->getAlgoStates(visitor.m_slotNum);
130  //auto& decisions = m_PRGraph->getNodeDecisions(visitor.m_slotNum);
131 
132  //m_PRGraph->m_headNode->promoteToControlReadyState(slotNum,states,decisions);
133 
134  m_PRGraph->m_headNode->accept(visitor);
135 
136  }
bool accept(IGraphVisitor &visitor) override
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
void concurrency::ExecutionFlowManager::updateDecision ( const std::string algo_name,
const int &  slotNum,
AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const

Definition at line 101 of file ExecutionFlowManager.cpp.

104  {
105  m_PRGraph->updateDecision(algo_name, slotNum, algo_states, node_decisions);
106  }
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.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
void concurrency::ExecutionFlowManager::updateEventState ( AlgsExecutionStates algo_states,
std::vector< int > &  node_decisions 
) const

Update the state of algorithms to controlready, where possible.

Definition at line 95 of file ExecutionFlowManager.cpp.

96  {
97  m_PRGraph->updateEventState(algo_states, node_decisions);
98  }
void updateEventState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX CF tests. Is needed for older CF implementation.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
void concurrency::ExecutionFlowManager::updateEventState ( AlgsExecutionStates algo_states) const

XXX: CF tests.

Member Data Documentation

std::string concurrency::ExecutionFlowManager::m_name
private

Definition at line 71 of file ExecutionFlowManager.h.

PrecedenceRulesGraph* concurrency::ExecutionFlowManager::m_PRGraph
private

the graph of precedence rules

Definition at line 73 of file ExecutionFlowManager.h.


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