The Gaudi Framework  v36r11 (bdb84f5f)
PrecedenceSvc Class Reference

A service to resolve the task execution precedence. More...

#include <GaudiHive/PrecedenceSvc.h>

Inheritance diagram for PrecedenceSvc:
Collaboration diagram for PrecedenceSvc:

Public Member Functions

 PrecedenceSvc (const std::string &name, ISvcLocator *svcLoc)
 Constructor. More...
 
StatusCode initialize () override
 Initialize. More...
 
StatusCode finalize () override
 Finalize. More...
 
StatusCode iterate (EventSlot &, const Cause &) override
 Infer the precedence effect caused by an execution flow event. More...
 
StatusCode simulate (EventSlot &) const override
 Simulate execution flow. More...
 
bool CFRulesResolved (EventSlot &) const override
 Check if the root CF decision is resolved. More...
 
uint getPriority (const std::string &name) const override
 Get priority of an algorithm. More...
 
bool isBlocking (const std::string &name) const override
 Check if a task is CPU-blocking. More...
 
void dumpControlFlow () const override
 Dump precedence rules. More...
 
void dumpDataFlow () const override
 
const std::string printState (EventSlot &) const override
 
void dumpPrecedenceRules (const EventSlot &) override
 Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding service property) More...
 
void dumpPrecedenceTrace (const EventSlot &) override
 Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding service property) More...
 
const concurrency::PrecedenceRulesGraphgetRules () const
 Precedence rules accessor. More...
 
- Public Member Functions inherited from extends< Service, IPrecedenceSvc >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service
More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service
More...
 
StatusCode sysStart () override
 Initialize Service
More...
 
StatusCode sysStop () override
 Initialize Service
More...
 
StatusCode sysFinalize () override
 Finalize Service
More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor
More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator
More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T >
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Private Member Functions

StatusCode assembleCFRules (Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
 

Private Attributes

SmartIF< IAlgResourcePoolm_algResourcePool
 A shortcut to the algorithm resource pool. More...
 
concurrency::PrecedenceRulesGraph m_PRGraph { "PrecedenceRulesGraph", serviceLocator() }
 Graph of precedence rules. More...
 
Gaudi::Property< std::stringm_mode { this, "TaskPriorityRule", "", "Task avalanche induction strategy." }
 Scheduling strategy. More...
 
Gaudi::Property< bool > m_ignoreDFRules { this, "IgnoreDFRules", false, "Ignore the data flow rules." }
 Scheduling strategy. More...
 
boost::filesystem::path m_dumpDirName
 Precedence analysis facilities. More...
 
Gaudi::Property< bool > m_dumpPrecTrace
 
Gaudi::Property< std::stringm_dumpPrecTraceFile
 
Gaudi::Property< bool > m_dumpPrecRules { this, "DumpPrecedenceRules", false, "Dump task precedence rules." }
 
Gaudi::Property< std::stringm_dumpPrecRulesFile
 
Gaudi::Property< bool > m_verifyRules
 
Gaudi::Property< bool > m_showDataFlow
 

Additional Inherited Members

- Public Types inherited from extends< Service, IPrecedenceSvc >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 Standard Destructor
More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools More...
 
Gaudi::Property< bool > m_auditInit { this, "AuditServices", false, "[[deprecated]] unused" }
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service
More...
 

Detailed Description

A service to resolve the task execution precedence.

Author
Illya Shapoval @created Aug 7, 2017

Definition at line 31 of file PrecedenceSvc.h.

Constructor & Destructor Documentation

◆ PrecedenceSvc()

PrecedenceSvc::PrecedenceSvc ( const std::string name,
ISvcLocator svcLoc 
)
inline

Constructor.

Definition at line 35 of file PrecedenceSvc.h.

35 : base_class( name, svcLoc ) {}

Member Function Documentation

◆ assembleCFRules()

StatusCode PrecedenceSvc::assembleCFRules ( Gaudi::Algorithm algo,
const std::string parentName,
unsigned int  recursionDepth = 0 
)
private

Definition at line 146 of file PrecedenceSvc.cpp.

147  {
148  using namespace concurrency;
149 
151 
152  ++recursionDepth;
153 
154  bool isGaudiSequencer( false );
155  bool isAthSequencer( false );
156 
157  if ( !algo->isSequence() ) {
158  ON_DEBUG debug() << std::string( recursionDepth, ' ' ) << "Algorithm '" << algo->name() << "' discovered" << endmsg;
159  sc = m_PRGraph.addAlgorithmNode( algo, parentName, false, false );
160  return sc;
161  } else {
162  if ( algo->hasProperty( "ShortCircuit" ) )
163  isGaudiSequencer = true;
164  else if ( algo->hasProperty( "StopOverride" ) )
165  isAthSequencer = true;
166  }
167 
168  auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
169  if ( seq == 0 ) {
170  error() << "Algorithm " << algo->name() << " has isSequence==true, but unable to dcast to Sequence" << endmsg;
171  return StatusCode::FAILURE;
172  }
173 
174  auto subAlgorithms = seq->subAlgorithms();
175 
176  // Recursively unroll
177  ON_DEBUG debug() << std::string( recursionDepth, ' ' ) << "Decision hub '" << algo->name() << "' discovered"
178  << endmsg;
179  bool modeOr = false;
180  bool allPass = false;
181  bool promptDecision = false;
182  bool isSequential = false;
183  bool isInverted = false;
184 
185  if ( isGaudiSequencer ) {
186  modeOr = ( algo->getProperty( "ModeOR" ).toString() == "True" );
187  allPass = ( algo->getProperty( "IgnoreFilterPassed" ).toString() == "True" );
188  promptDecision = ( algo->getProperty( "ShortCircuit" ).toString() == "True" );
189  isInverted = ( algo->getProperty( "Invert" ).toString() == "True" );
190  if ( allPass ) promptDecision = false; // standard GaudiSequencer behavior on all pass is to execute everything
191  isSequential = ( algo->hasProperty( "Sequential" ) && ( algo->getProperty( "Sequential" ).toString() == "True" ) );
192  } else if ( isAthSequencer ) {
193  modeOr = ( algo->getProperty( "ModeOR" ).toString() == "True" );
194  allPass = ( algo->getProperty( "IgnoreFilterPassed" ).toString() == "True" );
195  promptDecision = ( algo->getProperty( "StopOverride" ).toString() == "False" );
196  isSequential = ( algo->hasProperty( "Sequential" ) && ( algo->getProperty( "Sequential" ).toString() == "True" ) );
197  }
198  sc = m_PRGraph.addDecisionHubNode( algo, parentName, Concurrent{ !isSequential }, PromptDecision{ promptDecision },
199  ModeOr{ modeOr }, AllPass{ allPass }, Inverted{ isInverted } );
200  if ( sc.isFailure() ) {
201  error() << "Failed to add DecisionHub " << algo->name() << " to graph of precedence rules" << endmsg;
202  return sc;
203  }
204 
205  for ( auto subalgo : *subAlgorithms ) {
206  sc = assembleCFRules( subalgo, algo->name(), recursionDepth );
207  if ( sc.isFailure() ) {
208  error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
209  return sc;
210  }
211  }
212  return sc;
213 }

◆ CFRulesResolved()

bool PrecedenceSvc::CFRulesResolved ( EventSlot slot) const
override

Check if the root CF decision is resolved.

Definition at line 285 of file PrecedenceSvc.cpp.

285  {
286  return ( -1 != slot.controlFlowState[m_PRGraph.getHeadNode()->getNodeIndex()] ? true : false );
287 }

◆ dumpControlFlow()

void PrecedenceSvc::dumpControlFlow ( ) const
override

Dump precedence rules.

Definition at line 290 of file PrecedenceSvc.cpp.

290  {
291 
292  info() << std::endl << "==================== Control Flow Configuration ==================" << std::endl << std::endl;
293  info() << m_PRGraph.dumpControlFlow() << endmsg;
294 }

◆ dumpDataFlow()

void PrecedenceSvc::dumpDataFlow ( ) const
override

Definition at line 296 of file PrecedenceSvc.cpp.

296  {
297  info() << std::endl << "===================== Data Flow Configuration ====================" << std::endl;
298  info() << m_PRGraph.dumpDataFlow() << endmsg;
299 }

◆ dumpPrecedenceRules()

void PrecedenceSvc::dumpPrecedenceRules ( const EventSlot slot)
override

Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding service property)

Definition at line 310 of file PrecedenceSvc.cpp.

310  {
311 
312  if ( !m_dumpPrecRules ) {
313  warning() << "To trace temporal and topological aspects of execution flow, "
314  << "set DumpPrecedenceRules property to True " << endmsg;
315  return;
316  }
317 
318  ON_DEBUG debug() << "Dumping temporal precedence rules" << endmsg;
319 
320  std::string fileName;
321  if ( m_dumpPrecRulesFile.empty() ) {
322  const auto& eventID = slot.eventContext->eventID();
323  fileName = "rules_evt-" + std::to_string( eventID.event_number() ) + "_slot-" +
324  std::to_string( slot.eventContext->slot() ) + "_run-" + std::to_string( eventID.run_number() ) +
325  ".graphml";
326  } else {
327  fileName = m_dumpPrecRulesFile;
328  }
329 
331  pth.append( fileName );
332 
333  m_PRGraph.dumpPrecRules( pth, slot );
334 }

◆ dumpPrecedenceTrace()

void PrecedenceSvc::dumpPrecedenceTrace ( const EventSlot slot)
override

Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding service property)

Definition at line 337 of file PrecedenceSvc.cpp.

337  {
338 
339  if ( !m_dumpPrecTrace ) {
340  warning() << "To trace task precedence patterns, set DumpPrecedenceTrace "
341  << "property to True " << endmsg;
342  return;
343  }
344 
345  ON_DEBUG debug() << "Dumping temporal precedence trace" << endmsg;
346 
347  std::string fileName;
348  if ( m_dumpPrecTraceFile.empty() ) {
349  const auto& eventID = slot.eventContext->eventID();
350  fileName = "trace_evt-" + std::to_string( eventID.event_number() ) + "_slot-" +
351  std::to_string( slot.eventContext->slot() ) + "_run-" + std::to_string( eventID.run_number() ) +
352  ".graphml";
353  } else {
354  fileName = m_dumpPrecTraceFile;
355  }
356 
358  pth.append( fileName );
359 
360  m_PRGraph.dumpPrecTrace( pth, slot );
361 }

◆ finalize()

StatusCode PrecedenceSvc::finalize ( )
override

Finalize.

Definition at line 366 of file PrecedenceSvc.cpp.

366 { return Service::finalize(); }

◆ getPriority()

uint PrecedenceSvc::getPriority ( const std::string name) const
inlineoverride

Get priority of an algorithm.

Definition at line 53 of file PrecedenceSvc.h.

53  {
54  return (int)m_PRGraph.getAlgorithmNode( name )->getRank();
55  }

◆ getRules()

const concurrency::PrecedenceRulesGraph* PrecedenceSvc::getRules ( ) const
inline

Precedence rules accessor.

Definition at line 73 of file PrecedenceSvc.h.

73 { return &m_PRGraph; };

◆ initialize()

StatusCode PrecedenceSvc::initialize ( )
override

Initialize.

Definition at line 28 of file PrecedenceSvc.cpp.

28  {
29  using namespace concurrency;
30 
31  auto sc = Service::initialize(); // parent class must be initialized first
32  if ( sc.isFailure() ) {
33  fatal() << "Base class failed to initialize" << endmsg;
34  return sc;
35  }
36 
37  // prepare a directory to dump precedence analysis files to.
39  if ( !boost::filesystem::create_directory( m_dumpDirName ) ) {
40  error() << "Could not create directory " << m_dumpDirName
41  << "required "
42  "for task precedence tracing"
43  << endmsg;
44  return StatusCode::FAILURE;
45  }
46  }
47 
49 
50  // Get the algo resource pool
51  m_algResourcePool = serviceLocator()->service( "AlgResourcePool" );
52  if ( !m_algResourcePool.isValid() ) {
53  fatal() << "Error retrieving AlgoResourcePool" << endmsg;
54  return StatusCode::FAILURE;
55  }
56 
57  info() << "Assembling CF and DF task precedence rules" << endmsg;
58 
59  ON_DEBUG debug() << "Assembling CF precedence realm:" << endmsg;
60  // create the root CF node
61  m_PRGraph.addHeadNode( "RootDecisionHub", Concurrent{ true }, PromptDecision{ false }, ModeOr{ true },
62  AllPass{ true }, Inverted{ false } );
63  // assemble the CF rules
64  for ( const auto& ialgoPtr : m_algResourcePool->getTopAlgList() ) {
65  auto algorithm = dynamic_cast<Gaudi::Algorithm*>( ialgoPtr );
66  if ( !algorithm ) fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
67  sc = assembleCFRules( algorithm, "RootDecisionHub" );
68  if ( sc.isFailure() ) {
69  fatal() << "Could not assemble the CF precedence realm" << endmsg;
70  return sc;
71  }
72  }
73 
74  if ( m_ignoreDFRules ) {
75  warning() << "Ignoring DF precedence rules, disabling all associated features" << endmsg;
76  return StatusCode::SUCCESS;
77  }
78 
79  ON_DEBUG debug() << "Assembling DF precedence realm:" << endmsg;
80  sc = m_PRGraph.initialize();
81  if ( sc.isFailure() ) {
82  fatal() << "Could not assemble the DF precedence realm" << endmsg;
83  return sc;
84  }
85 
86  // Rank algorithms if a prioritization rule is supplied
87  if ( m_mode == "PCE" ) {
89  m_PRGraph.rankAlgorithms( ranker );
90  } else if ( m_mode == "COD" ) {
92  m_PRGraph.rankAlgorithms( ranker );
93  } else if ( m_mode == "E" ) {
94  auto ranker = concurrency::RankerByEccentricity();
95  m_PRGraph.rankAlgorithms( ranker );
96  } else if ( m_mode == "T" ) {
97  auto ranker = concurrency::RankerByTiming();
98  m_PRGraph.rankAlgorithms( ranker );
99  } else if ( m_mode == "DRE" ) {
101  m_PRGraph.rankAlgorithms( ranker );
102  } else if ( !m_mode.empty() ) {
103  error() << "Requested prioritization rule '" << m_mode << "' is unknown" << endmsg;
104  return StatusCode::FAILURE;
105  }
106 
107  if ( m_showDataFlow ) { debug() << m_PRGraph.dumpDataFlow() << endmsg; }
108 
109  if ( m_verifyRules ) {
110  ON_DEBUG debug() << "Verifying task precedence rules" << endmsg;
111 
112  // Check if CF properties are self-consistent
113  auto propValidator = concurrency::NodePropertiesValidator();
114  m_PRGraph.accept( propValidator );
115  if ( !propValidator.passed() )
116  warning() << propValidator.reply() << endmsg;
117  else
118  ON_DEBUG debug() << propValidator.reply() << endmsg;
119 
120  // Check for violations in the DF topology
121  auto prodValidator = concurrency::ProductionAmbiguityFinder();
122  m_PRGraph.accept( prodValidator );
123  if ( !prodValidator.passed() ) {
124  error() << prodValidator.reply() << endmsg;
125  return StatusCode::FAILURE;
126  } else {
127  ON_DEBUG debug() << prodValidator.reply() << endmsg;
128  }
129 
130  auto sccFinder = concurrency::TarjanSCCFinder();
131  m_PRGraph.accept( sccFinder );
132  if ( !sccFinder.passed() ) {
133  error() << sccFinder.reply() << endmsg;
134  return StatusCode::FAILURE;
135  } else {
136  ON_DEBUG debug() << sccFinder.reply() << endmsg;
137  }
138  }
139 
140  if ( sc.isSuccess() ) info() << "PrecedenceSvc initialized successfully" << endmsg;
141 
142  return sc;
143 }

◆ isBlocking()

bool PrecedenceSvc::isBlocking ( const std::string name) const
inlineoverride

Check if a task is CPU-blocking.

Definition at line 58 of file PrecedenceSvc.h.

58 { return m_PRGraph.getAlgorithmNode( name )->isBlocking(); }

◆ iterate()

StatusCode PrecedenceSvc::iterate ( EventSlot slot,
const Cause cause 
)
override

Infer the precedence effect caused by an execution flow event.

Definition at line 216 of file PrecedenceSvc.cpp.

216  {
217 
218  if ( Cause::source::Task == cause.m_source ) {
219  ON_VERBOSE verbose() << "Triggering bottom-up traversal at node '" << cause.m_sourceName << "'" << endmsg;
220  auto visitor = concurrency::DecisionUpdater( slot, cause, m_dumpPrecTrace );
221  m_PRGraph.getAlgorithmNode( cause.m_sourceName )->accept( visitor );
222  } else {
223  ON_VERBOSE verbose() << "Triggering top-down traversal at the root node" << endmsg;
224  auto visitor = concurrency::Supervisor( slot, cause, m_dumpPrecTrace );
225  m_PRGraph.getHeadNode()->accept( visitor );
226  }
227 
228  if ( m_dumpPrecTrace )
229  if ( CFRulesResolved( slot.parentSlot ? *slot.parentSlot : slot ) )
230  dumpPrecedenceTrace( slot.parentSlot ? *slot.parentSlot : slot );
231 
232  if ( m_dumpPrecRules )
233  if ( CFRulesResolved( slot.parentSlot ? *slot.parentSlot : slot ) )
234  dumpPrecedenceRules( slot.parentSlot ? *slot.parentSlot : slot );
235 
236  return StatusCode::SUCCESS;
237 }

◆ printState()

const std::string PrecedenceSvc::printState ( EventSlot slot) const
override

Definition at line 302 of file PrecedenceSvc.cpp.

302  {
303 
305  m_PRGraph.printState( ss, slot, 0 );
306  return ss.str();
307 }

◆ simulate()

StatusCode PrecedenceSvc::simulate ( EventSlot slot) const
override

Simulate execution flow.

Definition at line 240 of file PrecedenceSvc.cpp.

240  {
241 
242  Cause cs = { Cause::source::Root, "RootDecisionHub" };
243  auto visitor = concurrency::RunSimulator( slot, cs );
244 
245  auto& nodeDecisions = slot.controlFlowState;
246 
247  std::vector<int> prevNodeDecisions;
248  int cntr = 0;
249  std::vector<int> counters;
250 
251  while ( !CFRulesResolved( slot ) ) {
252  cntr += 1;
253  int prevAlgosNum = visitor.m_nodesSucceeded;
254  ON_DEBUG debug() << " Proceeding with iteration #" << cntr << endmsg;
255  prevNodeDecisions = slot.controlFlowState;
256  m_PRGraph.getHeadNode()->accept( visitor );
257  if ( prevNodeDecisions == nodeDecisions ) {
258  error() << " No progress on iteration " << cntr << " detected, node decisions are:" << nodeDecisions << endmsg;
259  return StatusCode::FAILURE;
260  }
261  info() << " Iteration #" << cntr << " finished, total algorithms executed: " << visitor.m_nodesSucceeded
262  << endmsg;
263 
265  s << cntr << ", " << ( visitor.m_nodesSucceeded - prevAlgosNum ) << "\n";
266 
267  std::ofstream myfile;
268  myfile.open( "RunSimulation.csv", std::ios::app );
269  myfile << s.str();
270  myfile.close();
271 
272  if ( visitor.m_nodesSucceeded != prevAlgosNum ) counters.push_back( visitor.m_nodesSucceeded );
273  }
274 
275  info() << "Asymptotical intra-event speedup: " << (float)visitor.m_nodesSucceeded / (float)counters.size() << endmsg;
276 
277  // Reset algorithm states and node decisions
278  slot.algsStates.reset();
279  nodeDecisions.assign( nodeDecisions.size(), -1 );
280 
281  return StatusCode::SUCCESS;
282 }

Member Data Documentation

◆ m_algResourcePool

SmartIF<IAlgResourcePool> PrecedenceSvc::m_algResourcePool
private

A shortcut to the algorithm resource pool.

Definition at line 80 of file PrecedenceSvc.h.

◆ m_dumpDirName

boost::filesystem::path PrecedenceSvc::m_dumpDirName
private
Initial value:
{
boost::filesystem::unique_path( boost::filesystem::path( "precedence.analysis.%%%%" ) ) }

Precedence analysis facilities.

Definition at line 88 of file PrecedenceSvc.h.

◆ m_dumpPrecRules

Gaudi::Property<bool> PrecedenceSvc::m_dumpPrecRules { this, "DumpPrecedenceRules", false, "Dump task precedence rules." }
private

Definition at line 97 of file PrecedenceSvc.h.

◆ m_dumpPrecRulesFile

Gaudi::Property<std::string> PrecedenceSvc::m_dumpPrecRulesFile
private
Initial value:
{ this, "PrecedenceRulesFile", "",
"Override default name of the GRAPHML precedence rules file." }

Definition at line 98 of file PrecedenceSvc.h.

◆ m_dumpPrecTrace

Gaudi::Property<bool> PrecedenceSvc::m_dumpPrecTrace
private
Initial value:
{ this, "DumpPrecedenceTrace", false,
"Dump task precedence traces for each event." }

Definition at line 90 of file PrecedenceSvc.h.

◆ m_dumpPrecTraceFile

Gaudi::Property<std::string> PrecedenceSvc::m_dumpPrecTraceFile
private
Initial value:
{
this, "PrecedenceTraceFile", "",
"Override default name of the GRAPHML trace file. NOTE: if more than "
"1 event is processed, the setting forces creation of a single file "
"with cumulative precedence trace." }

Definition at line 92 of file PrecedenceSvc.h.

◆ m_ignoreDFRules

Gaudi::Property<bool> PrecedenceSvc::m_ignoreDFRules { this, "IgnoreDFRules", false, "Ignore the data flow rules." }
private

Scheduling strategy.

Definition at line 86 of file PrecedenceSvc.h.

◆ m_mode

Gaudi::Property<std::string> PrecedenceSvc::m_mode { this, "TaskPriorityRule", "", "Task avalanche induction strategy." }
private

Scheduling strategy.

Definition at line 84 of file PrecedenceSvc.h.

◆ m_PRGraph

concurrency::PrecedenceRulesGraph PrecedenceSvc::m_PRGraph { "PrecedenceRulesGraph", serviceLocator() }
private

Graph of precedence rules.

Definition at line 82 of file PrecedenceSvc.h.

◆ m_showDataFlow

Gaudi::Property<bool> PrecedenceSvc::m_showDataFlow
private
Initial value:
{ this, "ShowDataFlow", false,
"Show the configuration of DataFlow between Algorithms" }

Definition at line 102 of file PrecedenceSvc.h.

◆ m_verifyRules

Gaudi::Property<bool> PrecedenceSvc::m_verifyRules
private
Initial value:
{ this, "VerifyTaskPrecedenceRules", true,
"Verify task precedence rules for common errors." }

Definition at line 100 of file PrecedenceSvc.h.


The documentation for this class was generated from the following files:
EventSlot::eventContext
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition: EventSlot.h:83
PrecedenceSvc::m_dumpPrecRules
Gaudi::Property< bool > m_dumpPrecRules
Definition: PrecedenceSvc.h:97
PrecedenceSvc::dumpPrecedenceTrace
void dumpPrecedenceTrace(const EventSlot &) override
Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding servi...
Definition: PrecedenceSvc.cpp:337
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
concurrency::PrecedenceRulesGraph::printState
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
Definition: PrecedenceRulesGraph.cpp:260
std::string
STL class.
concurrency::PrecedenceRulesGraph::dumpPrecTrace
void dumpPrecTrace(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence trace
Definition: PrecedenceRulesGraph.cpp:672
concurrency::Supervisor
Definition: Promoters.h:64
concurrency::PrecedenceRulesGraph::accept
void accept(IGraphVisitor &visitor) const
An entry point to visit all graph nodes.
Definition: PrecedenceRulesGraph.cpp:542
PrecedenceSvc::dumpPrecedenceRules
void dumpPrecedenceRules(const EventSlot &) override
Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding servi...
Definition: PrecedenceSvc.cpp:310
Read.app
app
Definition: Read.py:36
PrecedenceSvc::m_PRGraph
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:82
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:542
PrecedenceSvc::m_dumpPrecTraceFile
Gaudi::Property< std::string > m_dumpPrecTraceFile
Definition: PrecedenceSvc.h:92
EventContext::eventID
const EventIDBase & eventID() const
Definition: EventContext.h:55
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< int >
std::vector::size
T size(T... args)
PrecedenceSvc::assembleCFRules
StatusCode assembleCFRules(Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
Definition: PrecedenceSvc.cpp:146
concurrency::RankerByProductConsumption
Definition: Rankers.h:20
concurrency::PrecedenceRulesGraph::dumpPrecRules
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
Definition: PrecedenceRulesGraph.cpp:631
std::stringstream
STL class.
PropertyHolder::getProperty
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
Definition: PropertyHolder.h:190
concurrency::ProductionAmbiguityFinder
Definition: Validators.h:132
concurrency::PrecedenceRulesGraph::initialize
StatusCode initialize()
Initialize graph.
Definition: PrecedenceRulesGraph.cpp:220
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:222
extends< Service, IPrecedenceSvc >::base_class
extends base_class
Typedef to this class.
Definition: extends.h:24
PrecedenceSvc::m_verifyRules
Gaudi::Property< bool > m_verifyRules
Definition: PrecedenceSvc.h:100
concurrency::AlgorithmNode::accept
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
Definition: PrecedenceRulesGraph.cpp:191
PrecedenceSvc::m_algResourcePool
SmartIF< IAlgResourcePool > m_algResourcePool
A shortcut to the algorithm resource pool.
Definition: PrecedenceSvc.h:80
std::vector::push_back
T push_back(T... args)
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
ON_VERBOSE
#define ON_VERBOSE
Definition: PrecedenceSvc.cpp:21
StatusCode
Definition: StatusCode.h:65
Gaudi::tagged_bool_ns::tagged_bool
Definition: TaggedBool.h:16
PrecedenceSvc::m_dumpDirName
boost::filesystem::path m_dumpDirName
Precedence analysis facilities.
Definition: PrecedenceSvc.h:88
EventSlot::parentSlot
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:96
std::ofstream
STL class.
concurrency::PrecedenceRulesGraph::addAlgorithmNode
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
Definition: PrecedenceRulesGraph.cpp:372
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:51
Cause::m_source
source m_source
Definition: PrecedenceRulesGraph.h:402
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
concurrency::RankerByEccentricity
Definition: Rankers.h:49
std::to_string
T to_string(T... args)
PrecedenceSvc::CFRulesResolved
bool CFRulesResolved(EventSlot &) const override
Check if the root CF decision is resolved.
Definition: PrecedenceSvc.cpp:285
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:961
PrecedenceSvc::m_dumpPrecTrace
Gaudi::Property< bool > m_dumpPrecTrace
Definition: PrecedenceSvc.h:90
concurrency::PrecedenceRulesGraph::rankAlgorithms
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
Definition: PrecedenceRulesGraph.cpp:554
HistogramsTiming.seq
seq
Definition: HistogramsTiming.py:24
std::ofstream::open
T open(T... args)
genconfuser.verbose
verbose
Definition: genconfuser.py:29
concurrency::PrecedenceRulesGraph::addDecisionHubNode
StatusCode addDecisionHubNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which aggregates decisions of direct daughter nodes.
Definition: PrecedenceRulesGraph.cpp:455
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:63
Cause::source::Root
@ Root
concurrency::PrecedenceRulesGraph::dumpControlFlow
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
Definition: PrecedenceRulesGraph.cpp:564
concurrency
Definition: PrecedenceRulesGraph.cpp:38
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
concurrency::DecisionUpdater
Definition: Promoters.h:48
concurrency::PrecedenceRulesGraph::getAlgorithmNode
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
Definition: PrecedenceRulesGraph.h:666
concurrency::PrecedenceRulesGraph::dumpDataFlow
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
Definition: PrecedenceRulesGraph.cpp:597
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Cause::source::Task
@ Task
std::endl
T endl(T... args)
concurrency::NodePropertiesValidator
Definition: Validators.h:28
PrecedenceSvc::m_ignoreDFRules
Gaudi::Property< bool > m_ignoreDFRules
Scheduling strategy.
Definition: PrecedenceSvc.h:86
concurrency::PrecedenceRulesGraph::enableAnalysis
void enableAnalysis()
BGL-based facilities.
Definition: PrecedenceRulesGraph.h:688
PrecedenceSvc::m_dumpPrecRulesFile
Gaudi::Property< std::string > m_dumpPrecRulesFile
Definition: PrecedenceSvc.h:98
concurrency::AlgorithmNode::getRank
const float & getRank() const
Get Algorithm rank.
Definition: PrecedenceRulesGraph.h:520
std::stringstream::str
T str(T... args)
ON_DEBUG
#define ON_DEBUG
Definition: PrecedenceSvc.cpp:20
concurrency::RankerByCummulativeOutDegree
Definition: Rankers.h:28
EventSlot::controlFlowState
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:87
concurrency::DecisionNode::accept
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
Definition: PrecedenceRulesGraph.cpp:65
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Sequence
Definition: Sequence.h:18
PrecedenceSvc::m_showDataFlow
Gaudi::Property< bool > m_showDataFlow
Definition: PrecedenceSvc.h:102
concurrency::AlgorithmNode::isBlocking
bool isBlocking() const
Check if algorithm is CPU-blocking.
Definition: PrecedenceRulesGraph.h:530
concurrency::TarjanSCCFinder
Definition: Validators.h:169
concurrency::PrecedenceRulesGraph::getHeadNode
DecisionNode * getHeadNode() const
Get head node.
Definition: PrecedenceRulesGraph.h:661
PrecedenceSvc::m_mode
Gaudi::Property< std::string > m_mode
Scheduling strategy.
Definition: PrecedenceSvc.h:84
concurrency::PrecedenceRulesGraph::addHeadNode
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
Definition: PrecedenceRulesGraph.cpp:508
EventSlot::algsStates
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:85
Cause
Definition: PrecedenceRulesGraph.h:399
concurrency::RankerByTiming
Definition: Rankers.h:41
Gaudi::Algorithm::isSequence
bool isSequence() const override
Are we a Sequence?
Definition: Algorithm.h:198
concurrency::RunSimulator
Definition: Promoters.h:87
concurrency::ControlFlowNode::getNodeIndex
const unsigned int & getNodeIndex() const
Get node index.
Definition: PrecedenceRulesGraph.h:430
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
Definition: Service.cpp:335
concurrency::RankerByDataRealmEccentricity
Definition: Rankers.h:57
Cause::m_sourceName
std::string m_sourceName
Definition: PrecedenceRulesGraph.h:403
PropertyHolder::hasProperty
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
Definition: PropertyHolder.h:227