| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ExecutionFlowManager.cpp
Go to the documentation of this file.
1 #include "ExecutionFlowManager.h"
2
3 namespace concurrency {
4
5 //---------------------------------------------------------------------------
6 StatusCode ExecutionFlowManager::initialize(ExecutionFlowGraph* ef_graph,
7 const std::unordered_map<std::string,unsigned int>& algname_index_map){
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 }
15
16 //---------------------------------------------------------------------------
17 StatusCode ExecutionFlowManager::initialize(ExecutionFlowGraph* ef_graph,
18 const std::unordered_map<std::string,unsigned int>& algname_index_map,
19 std::vector<EventSlot>& eventSlots,
20 const std::string& mode){
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") {
30 auto ranker = concurrency::RankerByProductConsumption();
31 m_EFGraph->rankAlgorithms(ranker);
32 } else if (mode == "COD") {
33 auto ranker = concurrency::RankerByCummulativeOutDegree();
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") {
42 auto ranker = concurrency::RankerByDataRealmEccentricity();
43 m_EFGraph->rankAlgorithms(ranker);
44 } else if (!mode.empty()){
45 error() << "Requested optimization mode '" << mode << "' is not known." << endmsg;
46 sc = StatusCode::FAILURE;
47 }
48
49 return sc;
50 }
51
52 //---------------------------------------------------------------------------
53 void ExecutionFlowManager::simulateExecutionFlow(IGraphVisitor& visitor) const {
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
73 std::stringstream s;
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
89 m_EFGraph->getAlgoStates(0).reset();
90 nodeDecisions.assign(nodeDecisions.size(),-1);
91
92 }
93
94 //---------------------------------------------------------------------------
95 void ExecutionFlowManager::updateEventState(AlgsExecutionStates& algo_states,
96 std::vector<int>& node_decisions) const {
97 m_EFGraph->updateEventState(algo_states, node_decisions);
98 }
99
100 //---------------------------------------------------------------------------
101 void ExecutionFlowManager::updateDecision(const std::string& algo_name,
102 const int& slotNum,
103 AlgsExecutionStates& algo_states,
104 std::vector<int>& node_decisions) const {
105 m_EFGraph->updateDecision(algo_name, slotNum, algo_states, node_decisions);
106 }
107
108 //---------------------------------------------------------------------------
109 void ExecutionFlowManager::promoteToControlReadyState(AlgsExecutionStates& algo_states,
110 std::vector<int>& node_decisions,
111 const int& slotNum) const {
112 m_EFGraph->m_headNode->promoteToControlReadyState(slotNum, algo_states, node_decisions);
113 }
114
115 //---------------------------------------------------------------------------
116 bool ExecutionFlowManager::algoDataDependenciesSatisfied(const std::string& algo_name, const int& slotNum) const {
117 return m_EFGraph->getAlgorithmNode(algo_name)->dataDependenciesSatisfied(slotNum);
118 }
119
120 //---------------------------------------------------------------------------
121 bool ExecutionFlowManager::rootDecisionResolved(const std::vector<int>& node_decisions) const {
122
123 return (-1 != node_decisions[m_EFGraph->m_headNode->getNodeIndex()]) ? true : false;
124 }
125
126 //---------------------------------------------------------------------------
127 void ExecutionFlowManager::touchReadyAlgorithms(IGraphVisitor& visitor) const {
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 }
137 }
concurrency::ExecutionFlowManager::simulateExecutionFlow
void simulateExecutionFlow(IGraphVisitor &visitor) const
Definition: ExecutionFlowManager.cpp:53
std::string::empty
T empty(T...args)
concurrency::ExecutionFlowGraph::initialize
StatusCode initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize graph.
Definition: ExecutionFlowGraph.cpp:405
std::ofstream::open
T open(T...args)
concurrency::ExecutionFlowManager::updateEventState
void updateEventState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions) const
Update the state of algorithms to controlready, where possible.
Definition: ExecutionFlowManager.cpp:95
ExecutionFlowManager.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
concurrency::DecisionNode::accept
virtual bool accept(IGraphVisitor &visitor)
Definition: ExecutionFlowGraph.cpp:177
concurrency::ExecutionFlowManager::algoDataDependenciesSatisfied
bool algoDataDependenciesSatisfied(const std::string &algo_name, const int &slotNum) const
Check all data dependencies of an algorithm are satisfied.
Definition: ExecutionFlowManager.cpp:116
concurrency::AlgorithmNode::dataDependenciesSatisfied
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
Definition: ExecutionFlowGraph.cpp:264
concurrency
Definition: EFGraphVisitors.cpp:3
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
concurrency::ExecutionFlowGraph::updateDecision
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.
Definition: ExecutionFlowGraph.cpp:699
concurrency::ExecutionFlowManager::touchReadyAlgorithms
void touchReadyAlgorithms(IGraphVisitor &visitor) const
Promote all algorithms, ready to be executed, to DataReady state.
Definition: ExecutionFlowManager.cpp:127
concurrency::ExecutionFlowGraph::getNodeDecisions
std::vector< int > & getNodeDecisions(const int &slotNum) const
Definition: ExecutionFlowGraph.h:339
merge_files.sc
int sc
Definition: merge_files.py:167
std::stringstream
STL class.
std::string
STL class.
concurrency::ExecutionFlowGraph::getAlgoStates
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
Definition: ExecutionFlowGraph.h:337
std::vector::push_back
T push_back(T...args)
concurrency::ExecutionFlowManager::updateDecision
void updateDecision(const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
Definition: ExecutionFlowManager.cpp:101
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
std::ofstream
STL class.
concurrency::RankerByTiming
Definition: EFGraphVisitors.h:118
concurrency::ExecutionFlowManager::rootDecisionResolved
bool rootDecisionResolved(const std::vector< int > &node_decisions) const
Check whether root decision was resolved.
Definition: ExecutionFlowManager.cpp:121
concurrency::RankerByDataRealmEccentricity
Definition: EFGraphVisitors.h:170
concurrency::ExecutionFlowGraph::m_headNode
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
Definition: ExecutionFlowGraph.h:349
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:28
StatusCode::FAILURE
Definition: StatusCode.h:29
concurrency::ExecutionFlowManager::promoteToControlReadyState
void promoteToControlReadyState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions, const int &slotNum=-1) const
XXX: CF tests.
Definition: ExecutionFlowManager.cpp:109
concurrency::ExecutionFlowManager::m_EFGraph
ExecutionFlowGraph * m_EFGraph
the control flow graph
Definition: ExecutionFlowManager.h:73
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
concurrency::RankerByEccentricity
Definition: EFGraphVisitors.h:144
std::stringstream::str
T str(T...args)
concurrency::IGraphVisitor
Definition: IGraphVisitor.h:9
std::vector::size
T size(T...args)
concurrency::ExecutionFlowGraph::rankAlgorithms
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
Definition: ExecutionFlowGraph.cpp:708
std::vector::assign
T assign(T...args)
std::vector< EventSlot >
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
concurrency::ExecutionFlowGraph
Definition: ExecutionFlowGraph.h:271
concurrency::RankerByProductConsumption
Definition: EFGraphVisitors.h:64
concurrency::IGraphVisitor::m_nodesSucceeded
int m_nodesSucceeded
Definition: IGraphVisitor.h:23
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:52
gaudirun.s
string s
Definition: gaudirun.py:245
concurrency::ControlFlowNode::getNodeIndex
const unsigned int & getNodeIndex() const
XXX: CF tests.
Definition: ExecutionFlowGraph.h:70
concurrency::ExecutionFlowManager::initialize
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...
Definition: ExecutionFlowManager.cpp:6
concurrency::ExecutionFlowGraph::updateEventState
void updateEventState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX CF tests. Is needed for older CF implementation.
Definition: ExecutionFlowGraph.cpp:693
concurrency::ExecutionFlowGraph::getAlgorithmNode
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
Definition: ExecutionFlowGraph.cpp:614
AthenaScenario.app
tuple app
Definition: AthenaScenario.py:89
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
concurrency::RankerByCummulativeOutDegree
Definition: EFGraphVisitors.h:90
std::unordered_map< std::string, unsigned int >
concurrency::DecisionNode::promoteToControlReadyState
virtual bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.
Definition: ExecutionFlowGraph.cpp:155