concurrency::ExecutionFlowManager Class Reference

Manage the execution flow using an execution flow graph 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 (ExecutionFlowGraph *CFGraph, 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 (ExecutionFlowGraph *CFGraph, const std::unordered_map< std::string, unsigned int > &algname_index_map, std::vector< EventSlot > &eventSlots, const std::string &mode)
 
void simulateExecutionFlow (IGraphVisitor &visitor) const
 
ExecutionFlowGraphgetExecutionFlowGraph () 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
 
ExecutionFlowGraphm_EFGraph
 the control flow graph 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 an execution flow graph 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_EFGraph(0) {};
ExecutionFlowGraph * m_EFGraph
the control flow graph
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_EFGraph->getAlgorithmNode(algo_name)->dataDependenciesSatisfied(slotNum);
118  }
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
ExecutionFlowGraph * m_EFGraph
the control flow graph
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
ExecutionFlowGraph* concurrency::ExecutionFlowManager::getExecutionFlowGraph ( ) const
inline

Get the flow graph instance.

Definition at line 38 of file ExecutionFlowManager.h.

38 {return m_EFGraph;}
ExecutionFlowGraph * m_EFGraph
the control flow graph
StatusCode concurrency::ExecutionFlowManager::initialize ( ExecutionFlowGraph CFGraph,
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  {
8  m_EFGraph = ef_graph;
9  StatusCode sc = ef_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)
ExecutionFlowGraph * m_EFGraph
the control flow graph
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode concurrency::ExecutionFlowManager::initialize ( ExecutionFlowGraph CFGraph,
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_EFGraph = ef_graph;
22  StatusCode sc = ef_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_EFGraph->rankAlgorithms(ranker);
32  } else if (mode == "COD") {
34  m_EFGraph->rankAlgorithms(ranker);
35  } else if (mode == "E") {
36  auto ranker = concurrency::RankerByEccentricity();
37  m_EFGraph->rankAlgorithms(ranker);
38  } else if (mode == "T") {
39  auto ranker = concurrency::RankerByTiming();
40  m_EFGraph->rankAlgorithms(ranker);
41  } else if (mode == "DRE") {
43  m_EFGraph->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
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
ExecutionFlowGraph * m_EFGraph
the control flow graph
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
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_EFGraph->printState(ss,states,node_decisions,recursionLevel);}
ExecutionFlowGraph * m_EFGraph
the control flow graph
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.
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_EFGraph->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...
ExecutionFlowGraph * m_EFGraph
the control flow graph
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.
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_EFGraph->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...
ExecutionFlowGraph * m_EFGraph
the control flow graph
const unsigned int & getNodeIndex() const
XXX: CF tests.
SmartIF<ISvcLocator>& concurrency::ExecutionFlowManager::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 69 of file ExecutionFlowManager.h.

69 {return m_EFGraph->serviceLocator();}
ExecutionFlowGraph * m_EFGraph
the control flow graph
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
void concurrency::ExecutionFlowManager::simulateExecutionFlow ( IGraphVisitor visitor) const

Definition at line 53 of file ExecutionFlowManager.cpp.

53  {
54 
55  std::vector<int>& nodeDecisions = m_EFGraph->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_EFGraph->getNodeDecisions(0);
65  m_EFGraph->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
AlgsExecutionStates & getAlgoStates(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...
ExecutionFlowGraph * m_EFGraph
the control flow graph
T str(T...args)
T size(T...args)
T assign(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
string s
Definition: gaudirun.py:245
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_EFGraph->getAlgoStates(visitor.m_slotNum);
130  //auto& decisions = m_EFGraph->getNodeDecisions(visitor.m_slotNum);
131 
132  //m_EFGraph->m_headNode->promoteToControlReadyState(slotNum,states,decisions);
133 
134  m_EFGraph->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...
ExecutionFlowGraph * m_EFGraph
the control flow graph
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_EFGraph->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.
ExecutionFlowGraph * m_EFGraph
the control flow graph
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_EFGraph->updateEventState(algo_states, node_decisions);
98  }
ExecutionFlowGraph * m_EFGraph
the control flow graph
void updateEventState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX CF tests. Is needed for older CF implementation.
void concurrency::ExecutionFlowManager::updateEventState ( AlgsExecutionStates algo_states) const

XXX: CF tests.

Member Data Documentation

ExecutionFlowGraph* concurrency::ExecutionFlowManager::m_EFGraph
private

the control flow graph

Definition at line 73 of file ExecutionFlowManager.h.

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

Definition at line 71 of file ExecutionFlowManager.h.


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