8 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 9 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 20 if ( sc.isFailure() ) {
21 fatal() <<
"Base class failed to initialize" <<
endmsg;
26 if ( m_dumpPrecTrace || m_dumpPrecRules ) {
27 if ( !boost::filesystem::create_directory( m_dumpDirName ) ) {
28 error() <<
"Could not create directory " << m_dumpDirName
30 "for task precedence tracing" 36 if ( m_dumpPrecRules ) m_PRGraph.enableAnalysis();
39 m_algResourcePool = serviceLocator()->service(
"AlgResourcePool" );
40 if ( !m_algResourcePool.isValid() ) {
41 fatal() <<
"Error retrieving AlgoResourcePool" <<
endmsg;
45 info() <<
"Assembling CF and DF task precedence rules" <<
endmsg;
52 for (
const auto& ialgoPtr : m_algResourcePool->getTopAlgList() ) {
54 if ( !algorithm ) fatal() <<
"Conversion from IAlgorithm to Gaudi::Algorithm failed" <<
endmsg;
55 sc = assembleCFRules( algorithm,
"RootDecisionHub" );
56 if ( sc.isFailure() ) {
57 fatal() <<
"Could not assemble the CF precedence realm" <<
endmsg;
62 if ( m_ignoreDFRules ) {
63 warning() <<
"Ignoring DF precedence rules, disabling all associated features" <<
endmsg;
68 sc = m_PRGraph.initialize();
69 if ( sc.isFailure() ) {
70 fatal() <<
"Could not assemble the DF precedence realm" <<
endmsg;
75 if ( m_mode ==
"PCE" ) {
77 m_PRGraph.rankAlgorithms( ranker );
78 }
else if ( m_mode ==
"COD" ) {
80 m_PRGraph.rankAlgorithms( ranker );
81 }
else if ( m_mode ==
"E" ) {
83 m_PRGraph.rankAlgorithms( ranker );
84 }
else if ( m_mode ==
"T" ) {
86 m_PRGraph.rankAlgorithms( ranker );
87 }
else if ( m_mode ==
"DRE" ) {
89 m_PRGraph.rankAlgorithms( ranker );
90 }
else if ( !m_mode.empty() ) {
91 error() <<
"Requested prioritization rule '" << m_mode <<
"' is unknown" <<
endmsg;
97 if ( sc.isSuccess() ) info() <<
"PrecedenceSvc initialized successfully" <<
endmsg;
104 unsigned int recursionDepth ) {
111 bool isGaudiSequencer(
false );
112 bool isAthSequencer(
false );
116 sc = m_PRGraph.addAlgorithmNode( algo, parentName,
false,
false );
120 isGaudiSequencer =
true;
122 isAthSequencer =
true;
127 error() <<
"Algorithm " << algo->
name() <<
" has isSequence==true, but unable to dcast to Sequence" <<
endmsg;
131 auto subAlgorithms =
seq->subAlgorithms();
137 bool allPass =
false;
138 bool promptDecision =
false;
139 bool isSequential =
false;
140 bool isInverted =
false;
142 if ( isGaudiSequencer ) {
143 modeOr = ( algo->
getProperty(
"ModeOR" ).toString() ==
"True" );
144 allPass = ( algo->
getProperty(
"IgnoreFilterPassed" ).toString() ==
"True" );
145 promptDecision = ( algo->
getProperty(
"ShortCircuit" ).toString() ==
"True" );
146 isInverted = ( algo->
getProperty(
"Invert" ).toString() ==
"True" );
147 if ( allPass ) promptDecision =
false;
148 isSequential = ( algo->
hasProperty(
"Sequential" ) && ( algo->
getProperty(
"Sequential" ).toString() ==
"True" ) );
149 }
else if ( isAthSequencer ) {
150 modeOr = ( algo->
getProperty(
"ModeOR" ).toString() ==
"True" );
151 allPass = ( algo->
getProperty(
"IgnoreFilterPassed" ).toString() ==
"True" );
152 promptDecision = ( algo->
getProperty(
"StopOverride" ).toString() ==
"False" );
153 isSequential = ( algo->
hasProperty(
"Sequential" ) && ( algo->
getProperty(
"Sequential" ).toString() ==
"True" ) );
158 error() <<
"Failed to add DecisionHub " << algo->
name() <<
" to graph of precedence rules" <<
endmsg;
162 for (
auto subalgo : *subAlgorithms ) {
163 sc = assembleCFRules( subalgo, algo->
name(), recursionDepth );
165 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
178 m_PRGraph.getAlgorithmNode( cause.
m_sourceName )->accept( visitor );
182 m_PRGraph.getHeadNode()->accept( visitor );
208 while ( !CFRulesResolved( slot ) ) {
210 int prevAlgosNum = visitor.m_nodesSucceeded;
211 ON_DEBUG debug() <<
" Proceeding with iteration #" << cntr <<
endmsg;
213 m_PRGraph.getHeadNode()->accept( visitor );
214 if ( prevNodeDecisions == nodeDecisions ) {
215 error() <<
" No progress on iteration " << cntr <<
" detected, node decisions are:" << nodeDecisions <<
endmsg;
218 info() <<
" Iteration #" << cntr <<
" finished, total algorithms executed: " << visitor.m_nodesSucceeded
222 s << cntr <<
", " << ( visitor.m_nodesSucceeded - prevAlgosNum ) <<
"\n";
225 myfile.
open(
"RunSimulation.csv", std::ios::app );
229 if ( visitor.m_nodesSucceeded != prevAlgosNum ) counters.
push_back( visitor.m_nodesSucceeded );
232 info() <<
"Asymptotical intra-event speedup: " << (float)visitor.m_nodesSucceeded / (
float)counters.
size() <<
endmsg;
236 nodeDecisions.assign( nodeDecisions.size(), -1 );
243 return ( -1 != slot.
controlFlowState[m_PRGraph.getHeadNode()->getNodeIndex()] ?
true : false );
250 info() << m_PRGraph.dumpControlFlow() <<
endmsg;
254 info() <<
std::endl <<
"===================== Data Flow Configuration ====================" <<
std::endl;
255 info() << m_PRGraph.dumpDataFlow() <<
endmsg;
269 if ( !m_dumpPrecRules ) {
270 warning() <<
"To trace temporal and topological aspects of execution flow, " 271 <<
"set DumpPrecedenceRules property to True " <<
endmsg;
275 ON_DEBUG debug() <<
"Dumping temporal precedence rules" <<
endmsg;
278 if ( m_dumpPrecRulesFile.empty() ) {
280 fileName =
"rules.evt-" +
std::to_string( eventID.event_number() ) +
"." +
"run-" +
283 fileName = m_dumpPrecRulesFile;
287 pth.append( fileName );
289 m_PRGraph.dumpPrecRules( pth, slot );
295 if ( !m_dumpPrecTrace ) {
296 warning() <<
"To trace task precedence patterns, set DumpPrecedenceTrace " 297 <<
"property to True " <<
endmsg;
301 ON_DEBUG debug() <<
"Dumping temporal precedence trace" <<
endmsg;
304 if ( m_dumpPrecTraceFile.empty() ) {
306 fileName =
"trace.evt-" +
std::to_string( eventID.event_number() ) +
"." +
"run-" +
309 fileName = m_dumpPrecTraceFile;
313 pth.append( fileName );
315 m_PRGraph.dumpPrecTrace( pth );
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
StatusCode initialize() override
Class representing an event slot.
void dumpPrecedenceRules(EventSlot &) override
Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding servi...
void dumpDataFlow() const override
StatusCode assembleCFRules(Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
StatusCode finalize() override
const std::string & name() const override
The identifying name of the algorithm object.
bool isSequence() const override
Are we a Sequence?
A service to resolve the task execution precedence.
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
constexpr static const auto SUCCESS
std::vector< int > controlFlowState
State of the control flow.
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
StatusCode iterate(EventSlot &, const Cause &) override
Infer the precedence effect caused by an execution flow event.
#define DECLARE_COMPONENT(type)
Gaudi::tagged_bool< class Inverted_tag > Inverted
StatusCode finalize() override
Finalize.
This class is used for returning status codes from appropriate routines.
void dumpPrecedenceTrace(EventSlot &) override
Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding servi...
bool CFRulesResolved(EventSlot &) const override
Check if the root CF decision is resolved.
StatusCode simulate(EventSlot &) const override
Simulate execution flow.
Gaudi::tagged_bool< class Concurrent_tag > Concurrent
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
Base class from which all concrete algorithm classes should be derived.
Gaudi::tagged_bool< class AllPass_tag > AllPass
constexpr static const auto FAILURE
EventSlot * parentSlot
Pointer to parent slot (null for top level)
const std::string printState(EventSlot &) const override
const EventIDBase & eventID() const
void dumpControlFlow() const override
Dump precedence rules.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
AlgsExecutionStates algsStates
Vector of algorithms states.