The Gaudi Framework  v30r3 (a5ef0a68)
AvalancheSchedulerSvc.cpp
Go to the documentation of this file.
2 
3 #include "AlgoExecutionTask.h"
4 #include "IOBoundAlgTask.h"
5 
6 // Framework includes
7 #include "GaudiKernel/Algorithm.h" // can be removed ASA dynamic casts to Algorithm are removed
10 #include "GaudiKernel/IAlgorithm.h"
13 
14 // C++
15 #include <algorithm>
16 #include <map>
17 #include <queue>
18 #include <sstream>
19 #include <unordered_set>
20 
21 // External libs
22 #include "boost/algorithm/string.hpp"
23 #include "boost/thread.hpp"
24 #include "boost/tokenizer.hpp"
25 // DP waiting for the TBB service
26 #include "tbb/task_scheduler_init.h"
27 
28 // Instantiation of a static factory class used by clients to create instances of this service
30 
31 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
32 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
33 
34 namespace
35 {
36  struct DataObjIDSorter {
37  bool operator()( const DataObjID* a, const DataObjID* b ) { return a->fullKey() < b->fullKey(); }
38  };
39 
40  // Sort a DataObjIDColl in a well-defined, reproducible manner.
41  // Used for making debugging dumps.
42  std::vector<const DataObjID*> sortedDataObjIDColl( const DataObjIDColl& coll )
43  {
45  v.reserve( coll.size() );
46  for ( const DataObjID& id : coll ) v.push_back( &id );
47  std::sort( v.begin(), v.end(), DataObjIDSorter() );
48  return v;
49  }
50 
51  bool subSlotAlgsInStates( const EventSlot& slot, std::initializer_list<AlgsExecutionStates::State> testStates )
52  {
53  return std::any_of( slot.allSubSlots.begin(), slot.allSubSlots.end(),
54  [testStates]( const EventSlot& ss ) { return ss.algsStates.containsAny( testStates ); } );
55  }
56 }
57 
58 //---------------------------------------------------------------------------
59 
66 {
67 
68  // Initialise mother class (read properties, ...)
70  if ( sc.isFailure() ) warning() << "Base class could not be initialized" << endmsg;
71 
72  // Get hold of the TBBSvc. This should initialize the thread pool
73  m_threadPoolSvc = serviceLocator()->service( "ThreadPoolSvc" );
74  if ( !m_threadPoolSvc.isValid() ) {
75  fatal() << "Error retrieving ThreadPoolSvc" << endmsg;
76  return StatusCode::FAILURE;
77  }
78 
79  // Activate the scheduler in another thread.
80  info() << "Activating scheduler in a separate thread" << endmsg;
81  m_thread = std::thread( [this]() { this->activate(); } );
82 
83  while ( m_isActive != ACTIVE ) {
84  if ( m_isActive == FAILURE ) {
85  fatal() << "Terminating initialization" << endmsg;
86  return StatusCode::FAILURE;
87  } else {
88  ON_DEBUG debug() << "Waiting for AvalancheSchedulerSvc to activate" << endmsg;
89  sleep( 1 );
90  }
91  }
92 
93  if ( m_enableCondSvc ) {
94  // Get hold of the CondSvc
95  m_condSvc = serviceLocator()->service( "CondSvc" );
96  if ( !m_condSvc.isValid() ) {
97  warning() << "No CondSvc found, or not enabled. "
98  << "Will not manage CondAlgorithms" << endmsg;
99  m_enableCondSvc = false;
100  }
101  }
102 
103  // Get the algo resource pool
104  m_algResourcePool = serviceLocator()->service( "AlgResourcePool" );
105  if ( !m_algResourcePool.isValid() ) {
106  fatal() << "Error retrieving AlgoResourcePool" << endmsg;
107  return StatusCode::FAILURE;
108  }
109 
110  m_algExecStateSvc = serviceLocator()->service( "AlgExecStateSvc" );
111  if ( !m_algExecStateSvc.isValid() ) {
112  fatal() << "Error retrieving AlgExecStateSvc" << endmsg;
113  return StatusCode::FAILURE;
114  }
115 
116  // Get Whiteboard
117  m_whiteboard = serviceLocator()->service( m_whiteboardSvcName );
118  if ( !m_whiteboard.isValid() ) {
119  fatal() << "Error retrieving EventDataSvc interface IHiveWhiteBoard." << endmsg;
120  return StatusCode::FAILURE;
121  }
122 
123  // Get dedicated scheduler for I/O-bound algorithms
124  if ( m_useIOBoundAlgScheduler ) {
125  m_IOBoundAlgScheduler = serviceLocator()->service( m_IOBoundAlgSchedulerSvcName );
126  if ( !m_IOBoundAlgScheduler.isValid() )
127  fatal() << "Error retrieving IOBoundSchedulerAlgSvc interface IAccelerator." << endmsg;
128  }
129 
130  // Set the MaxEventsInFlight parameters from the number of WB stores
131  m_maxEventsInFlight = m_whiteboard->getNumberOfStores();
132 
133  // Set the number of free slots
134  m_freeSlots = m_maxEventsInFlight;
135 
136  // set global concurrency flags
138 
139  // Get the list of algorithms
140  const std::list<IAlgorithm*>& algos = m_algResourcePool->getFlatAlgList();
141  const unsigned int algsNumber = algos.size();
142  info() << "Found " << algsNumber << " algorithms" << endmsg;
143 
144  /* Dependencies
145  1) Look for handles in algo, if none
146  2) Assume none are required
147  */
148 
149  DataObjIDColl globalInp, globalOutp;
150 
151  // figure out all outputs
152  for ( IAlgorithm* ialgoPtr : algos ) {
153  Algorithm* algoPtr = dynamic_cast<Algorithm*>( ialgoPtr );
154  if ( !algoPtr ) {
155  fatal() << "Could not convert IAlgorithm into Algorithm: this will result in a crash." << endmsg;
156  }
157  for ( auto id : algoPtr->outputDataObjs() ) {
158  auto r = globalOutp.insert( id );
159  if ( !r.second ) {
160  warning() << "multiple algorithms declare " << id << " as output! could be a single instance in multiple paths "
161  "though, or control flow may guarantee only one runs...!"
162  << endmsg;
163  }
164  }
165  }
166 
167  std::ostringstream ostdd;
168  ostdd << "Data Dependencies for Algorithms:";
169 
170  std::map<std::string, DataObjIDColl> algosDependenciesMap;
171  for ( IAlgorithm* ialgoPtr : algos ) {
172  Algorithm* algoPtr = dynamic_cast<Algorithm*>( ialgoPtr );
173  if ( nullptr == algoPtr ) {
174  fatal() << "Could not convert IAlgorithm into Algorithm for " << ialgoPtr->name()
175  << ": this will result in a crash." << endmsg;
176  return StatusCode::FAILURE;
177  }
178 
179  ostdd << "\n " << algoPtr->name();
180 
181  DataObjIDColl algoDependencies;
182  if ( !algoPtr->inputDataObjs().empty() || !algoPtr->outputDataObjs().empty() ) {
183  for ( const DataObjID* idp : sortedDataObjIDColl( algoPtr->inputDataObjs() ) ) {
184  DataObjID id = *idp;
185  ostdd << "\n o INPUT " << id;
186  if ( id.key().find( ":" ) != std::string::npos ) {
187  ostdd << " contains alternatives which require resolution...\n";
188  auto tokens = boost::tokenizer<boost::char_separator<char>>{id.key(), boost::char_separator<char>{":"}};
189  auto itok = std::find_if( tokens.begin(), tokens.end(), [&]( const std::string& t ) {
190  return globalOutp.find( DataObjID{t} ) != globalOutp.end();
191  } );
192  if ( itok != tokens.end() ) {
193  ostdd << "found matching output for " << *itok << " -- updating scheduler info\n";
194  id.updateKey( *itok );
195  } else {
196  error() << "failed to find alternate in global output list"
197  << " for id: " << id << " in Alg " << algoPtr->name() << endmsg;
198  m_showDataDeps = true;
199  }
200  }
201  algoDependencies.insert( id );
202  globalInp.insert( id );
203  }
204  for ( const DataObjID* id : sortedDataObjIDColl( algoPtr->outputDataObjs() ) ) {
205  ostdd << "\n o OUTPUT " << *id;
206  if ( id->key().find( ":" ) != std::string::npos ) {
207  error() << " in Alg " << algoPtr->name() << " alternatives are NOT allowed for outputs! id: " << *id
208  << endmsg;
209  m_showDataDeps = true;
210  }
211  }
212  } else {
213  ostdd << "\n none";
214  }
215  algosDependenciesMap[algoPtr->name()] = algoDependencies;
216  }
217 
218  if ( m_showDataDeps ) {
219  info() << ostdd.str() << endmsg;
220  }
221 
222  // Check if we have unmet global input dependencies, and, optionally, heal them
223  // WARNING: this step must be done BEFORE the Precedence Service is initialized
224  if ( m_checkDeps ) {
225  DataObjIDColl unmetDep;
226  for ( auto o : globalInp )
227  if ( globalOutp.find( o ) == globalOutp.end() ) unmetDep.insert( o );
228 
229  if ( unmetDep.size() > 0 ) {
230 
231  std::ostringstream ost;
232  for ( const DataObjID* o : sortedDataObjIDColl( unmetDep ) ) {
233  ost << "\n o " << *o << " required by Algorithm: ";
234 
235  for ( const auto& p : algosDependenciesMap )
236  if ( p.second.find( *o ) != p.second.end() ) ost << "\n * " << p.first;
237  }
238 
239  if ( !m_useDataLoader.empty() ) {
240 
241  // Find the DataLoader Alg
242  IAlgorithm* dataLoaderAlg( nullptr );
243  for ( IAlgorithm* algo : algos )
244  if ( algo->name() == m_useDataLoader ) {
245  dataLoaderAlg = algo;
246  break;
247  }
248 
249  if ( dataLoaderAlg == nullptr ) {
250  fatal() << "No DataLoader Algorithm \"" << m_useDataLoader.value()
251  << "\" found, and unmet INPUT dependencies "
252  << "detected:\n"
253  << ost.str() << endmsg;
254  return StatusCode::FAILURE;
255  }
256 
257  info() << "Will attribute the following unmet INPUT dependencies to \"" << dataLoaderAlg->type() << "/"
258  << dataLoaderAlg->name() << "\" Algorithm" << ost.str() << endmsg;
259 
260  // Set the property Load of DataLoader Alg
261  Algorithm* dataAlg = dynamic_cast<Algorithm*>( dataLoaderAlg );
262  if ( !dataAlg ) {
263  fatal() << "Unable to dcast DataLoader \"" << m_useDataLoader.value() << "\" IAlg to Algorithm" << endmsg;
264  return StatusCode::FAILURE;
265  }
266 
267  for ( auto& id : unmetDep ) {
268  ON_DEBUG debug() << "adding OUTPUT dep \"" << id << "\" to " << dataLoaderAlg->type() << "/"
269  << dataLoaderAlg->name() << endmsg;
271  }
272 
273  } else {
274  fatal() << "Auto DataLoading not requested, "
275  << "and the following unmet INPUT dependencies were found:" << ost.str() << endmsg;
276  return StatusCode::FAILURE;
277  }
278 
279  } else {
280  info() << "No unmet INPUT data dependencies were found" << endmsg;
281  }
282  }
283 
284  // Get the precedence service
285  m_precSvc = serviceLocator()->service( "PrecedenceSvc" );
286  if ( !m_precSvc.isValid() ) {
287  fatal() << "Error retrieving PrecedenceSvc" << endmsg;
288  return StatusCode::FAILURE;
289  }
290  const PrecedenceSvc* precSvc = dynamic_cast<const PrecedenceSvc*>( m_precSvc.get() );
291  if ( !precSvc ) {
292  fatal() << "Unable to dcast PrecedenceSvc" << endmsg;
293  return StatusCode::FAILURE;
294  }
295 
296  // Fill the containers to convert algo names to index
297  m_algname_vect.resize( algsNumber );
298  for ( IAlgorithm* algo : algos ) {
299  const std::string& name = algo->name();
300  auto index = precSvc->getRules()->getAlgorithmNode( name )->getAlgoIndex();
301  m_algname_index_map[name] = index;
302  m_algname_vect.at( index ) = name;
303  }
304 
305  // Shortcut for the message service
306  SmartIF<IMessageSvc> messageSvc( serviceLocator() );
307  if ( !messageSvc.isValid() ) error() << "Error retrieving MessageSvc interface IMessageSvc." << endmsg;
308 
309  m_eventSlots.assign( m_maxEventsInFlight,
310  EventSlot( algsNumber, precSvc->getRules()->getControlFlowNodeCounter(), messageSvc ) );
311  std::for_each( m_eventSlots.begin(), m_eventSlots.end(), []( EventSlot& slot ) { slot.complete = true; } );
312  m_actionsCounts.assign( m_maxEventsInFlight, 0 );
313 
314  if ( m_threadPoolSize > 1 ) {
315  m_maxAlgosInFlight = (size_t)m_threadPoolSize;
316  }
317 
318  // Clearly inform about the level of concurrency
319  info() << "Concurrency level information:" << endmsg;
320  info() << " o Number of events in flight: " << m_maxEventsInFlight << endmsg;
321  info() << " o TBB thread pool size: " << m_threadPoolSize << endmsg;
322 
323  if ( m_showControlFlow ) m_precSvc->dumpControlFlow();
324 
325  if ( m_showDataFlow ) m_precSvc->dumpDataFlow();
326 
327  // Simulate execution flow
328  if ( m_simulateExecution ) m_precSvc->simulate( m_eventSlots[0] );
329 
330  return sc;
331 }
332 //---------------------------------------------------------------------------
333 
338 {
339 
341  if ( sc.isFailure() ) warning() << "Base class could not be finalized" << endmsg;
342 
343  sc = deactivate();
344  if ( sc.isFailure() ) warning() << "Scheduler could not be deactivated" << endmsg;
345 
346  info() << "Joining Scheduler thread" << endmsg;
347  m_thread.join();
348 
349  // Final error check after thread pool termination
350  if ( m_isActive == FAILURE ) {
351  error() << "problems in scheduler thread" << endmsg;
352  return StatusCode::FAILURE;
353  }
354 
355  return sc;
356 }
357 //---------------------------------------------------------------------------
358 
370 {
371 
372  ON_DEBUG debug() << "AvalancheSchedulerSvc::activate()" << endmsg;
373 
374  if ( m_threadPoolSvc->initPool( m_threadPoolSize ).isFailure() ) {
375  error() << "problems initializing ThreadPoolSvc" << endmsg;
376  m_isActive = FAILURE;
377  return;
378  }
379 
380  // Wait for actions pushed into the queue by finishing tasks.
381  action thisAction;
383 
384  m_isActive = ACTIVE;
385 
386  // Continue to wait if the scheduler is running or there is something to do
387  ON_DEBUG debug() << "Start checking the actionsQueue" << endmsg;
388  while ( m_isActive == ACTIVE || m_actionsQueue.size() != 0 ) {
389  m_actionsQueue.pop( thisAction );
390  sc = thisAction();
391  ON_VERBOSE
392  {
393  if ( sc != StatusCode::SUCCESS )
394  verbose() << "Action did not succeed (which is not bad per se)." << endmsg;
395  else
396  verbose() << "Action succeeded." << endmsg;
397  }
398  }
399 
400  ON_DEBUG debug() << "Terminating thread-pool resources" << endmsg;
401  if ( m_threadPoolSvc->terminatePool().isFailure() ) {
402  error() << "Problems terminating thread pool" << endmsg;
403  m_isActive = FAILURE;
404  }
405 }
406 
407 //---------------------------------------------------------------------------
408 
416 {
417 
418  if ( m_isActive == ACTIVE ) {
419 
420  // Set the number of slots available to an error code
421  m_freeSlots.store( 0 );
422 
423  // Empty queue
424  action thisAction;
425  while ( m_actionsQueue.try_pop( thisAction ) ) {
426  };
427 
428  // This would be the last action
429  m_actionsQueue.push( [this]() -> StatusCode {
430  ON_VERBOSE verbose() << "Deactivating scheduler" << endmsg;
431  m_isActive = INACTIVE;
432  return StatusCode::SUCCESS;
433  } );
434  }
435 
436  return StatusCode::SUCCESS;
437 }
438 
439 //---------------------------------------------------------------------------
440 
441 // Utils and shortcuts
442 
443 inline const std::string& AvalancheSchedulerSvc::index2algname( unsigned int index ) { return m_algname_vect[index]; }
444 
445 //---------------------------------------------------------------------------
446 
447 inline unsigned int AvalancheSchedulerSvc::algname2index( const std::string& algoname )
448 {
449  unsigned int index = m_algname_index_map[algoname];
450  return index;
451 }
452 
453 //---------------------------------------------------------------------------
454 
455 // EventSlot management
463 {
464 
465  if ( !eventContext ) {
466  fatal() << "Event context is nullptr" << endmsg;
467  return StatusCode::FAILURE;
468  }
469 
470  if ( m_freeSlots.load() == 0 ) {
471  ON_DEBUG debug() << "A free processing slot could not be found." << endmsg;
472  return StatusCode::FAILURE;
473  }
474 
475  // no problem as push new event is only called from one thread (event loop manager)
476  --m_freeSlots;
477 
478  auto action = [this, eventContext]() -> StatusCode {
479  // Event processing slot forced to be the same as the wb slot
480  const unsigned int thisSlotNum = eventContext->slot();
481  EventSlot& thisSlot = m_eventSlots[thisSlotNum];
482  if ( !thisSlot.complete ) {
483  fatal() << "The slot " << thisSlotNum << " is supposed to be a finished event but it's not" << endmsg;
484  return StatusCode::FAILURE;
485  }
486 
487  ON_DEBUG debug() << "Executing event " << eventContext->evt() << " on slot " << thisSlotNum << endmsg;
488  thisSlot.reset( eventContext );
489 
490  // Result status code:
492 
493  // promote to CR and DR the initial set of algorithms
494  Cause cs = {Cause::source::Root, "RootDecisionHub"};
495  if ( m_precSvc->iterate( thisSlot, cs ).isFailure() ) {
496  error() << "Failed to call IPrecedenceSvc::iterate for slot " << thisSlotNum << endmsg;
497  result = StatusCode::FAILURE;
498  }
499 
500  if ( this->updateStates( thisSlotNum ).isFailure() ) {
501  error() << "Failed to call AvalancheSchedulerSvc::updateStates for slot " << thisSlotNum << endmsg;
502  result = StatusCode::FAILURE;
503  }
504 
505  return result;
506  }; // end of lambda
507 
508  // Kick off the scheduling!
509  ON_VERBOSE
510  {
511  verbose() << "Pushing the action to update the scheduler for slot " << eventContext->slot() << endmsg;
512  verbose() << "Free slots available " << m_freeSlots.load() << endmsg;
513  }
514 
515  m_actionsQueue.push( action );
516 
517  return StatusCode::SUCCESS;
518 }
519 
520 //---------------------------------------------------------------------------
521 
523 {
524  StatusCode sc;
525  for ( auto context : eventContexts ) {
526  sc = pushNewEvent( context );
527  if ( sc != StatusCode::SUCCESS ) return sc;
528  }
529  return sc;
530 }
531 
532 //---------------------------------------------------------------------------
533 
534 unsigned int AvalancheSchedulerSvc::freeSlots() { return std::max( m_freeSlots.load(), 0 ); }
535 
536 //---------------------------------------------------------------------------
541 {
542  // ON_DEBUG debug() << "popFinishedEvent: queue size: " << m_finishedEvents.size() << endmsg;
543  if ( m_freeSlots.load() == (int)m_maxEventsInFlight || m_isActive == INACTIVE ) {
544  // ON_DEBUG debug() << "freeslots: " << m_freeSlots << "/" << m_maxEventsInFlight
545  // << " active: " << m_isActive << endmsg;
546  return StatusCode::FAILURE;
547  } else {
548  // ON_DEBUG debug() << "freeslots: " << m_freeSlots << "/" << m_maxEventsInFlight
549  // << " active: " << m_isActive << endmsg;
550  m_finishedEvents.pop( eventContext );
551  ++m_freeSlots;
552  ON_DEBUG debug() << "Popped slot " << eventContext->slot() << " (event " << eventContext->evt() << ")" << endmsg;
553  return StatusCode::SUCCESS;
554  }
555 }
556 
557 //---------------------------------------------------------------------------
562 {
563  if ( m_finishedEvents.try_pop( eventContext ) ) {
564  ON_DEBUG debug() << "Try Pop successful slot " << eventContext->slot() << "(event " << eventContext->evt() << ")"
565  << endmsg;
566  ++m_freeSlots;
567  return StatusCode::SUCCESS;
568  }
569  return StatusCode::FAILURE;
570 }
571 
572 //--------------------------------------------------------------------------
573 // States Management
574 
584 StatusCode AvalancheSchedulerSvc::updateStates( int si, const int algo_index, EventContext* inputContext )
585 {
586 
587  StatusCode global_sc( StatusCode::SUCCESS );
588 
589  // Sort from the oldest to the newest event
590  // Prepare a vector of pointers to the slots to avoid copies
591  std::vector<EventSlot*> eventSlotsPtrs;
592 
593  // Consider all slots if si <0 or just one otherwise
594  if ( si < 0 ) {
595  const int eventsSlotsSize( m_eventSlots.size() );
596  eventSlotsPtrs.reserve( eventsSlotsSize );
597  for ( auto slotIt = m_eventSlots.begin(); slotIt != m_eventSlots.end(); ++slotIt ) {
598  if ( !slotIt->complete ) eventSlotsPtrs.push_back( &( *slotIt ) );
599  }
600  std::sort( eventSlotsPtrs.begin(), eventSlotsPtrs.end(),
601  []( EventSlot* a, EventSlot* b ) { return a->eventContext->evt() < b->eventContext->evt(); } );
602  } else {
603  eventSlotsPtrs.push_back( &m_eventSlots[si] );
604  }
605 
606  for ( EventSlot* thisSlotPtr : eventSlotsPtrs ) {
607  int iSlot = thisSlotPtr->eventContext->slot();
608 
609  // Cache the states of the algos to improve readability and performance
610  auto& thisSlot = m_eventSlots[iSlot];
611  AlgsExecutionStates& thisAlgsStates = thisSlot.algsStates;
612 
613  // Perform the I->CR->DR transitions
614  if ( algo_index >= 0 ) {
615  Cause cs = {Cause::source::Task, index2algname( algo_index )};
616 
617  // Pass sub-slots to precedence service if necessary
618  if ( !inputContext || iSlot != (int)inputContext->slot() || inputContext == thisSlot.eventContext ) {
619  if ( m_precSvc->iterate( thisSlot, cs ).isFailure() ) {
620  error() << "Failed to call IPrecedenceSvc::iterate for slot " << iSlot << endmsg;
621  global_sc = StatusCode::FAILURE;
622  }
623  } else {
624  // An input context that doesn't match the event context for that slot number implies a sub-slot
625  unsigned int const subSlotIndex = thisSlot.contextToSlot.at( inputContext );
626  if ( m_precSvc->iterate( thisSlot.allSubSlots[subSlotIndex], cs ).isFailure() ) {
627  error() << "Failed to call IPrecedenceSvc::iterate for sub-slot of " << iSlot << endmsg;
628  global_sc = StatusCode::FAILURE;
629  }
630  }
631  }
632 
633  StatusCode partial_sc( StatusCode::FAILURE, true );
634 
635  // Perform DR->SCHEDULED
636  if ( !m_optimizationMode.empty() ) {
637  auto comp_nodes = [this]( const uint& i, const uint& j ) {
638  return ( m_precSvc->getPriority( index2algname( i ) ) < m_precSvc->getPriority( index2algname( j ) ) );
639  };
641  comp_nodes, std::vector<uint>() );
642  for ( auto it = thisAlgsStates.begin( AState::DATAREADY ); it != thisAlgsStates.end( AState::DATAREADY ); ++it )
643  buffer.push( *it );
644  while ( !buffer.empty() ) {
645  bool IOBound = false;
646  if ( m_useIOBoundAlgScheduler ) IOBound = m_precSvc->isBlocking( index2algname( buffer.top() ) );
647 
648  if ( !IOBound )
649  partial_sc = promoteToScheduled( buffer.top(), iSlot, thisSlotPtr->eventContext );
650  else
651  partial_sc = promoteToAsyncScheduled( buffer.top(), iSlot, thisSlotPtr->eventContext );
652 
653  ON_VERBOSE if ( partial_sc.isFailure() ) verbose() << "Could not apply transition from " << AState::DATAREADY
654  << " for algorithm " << index2algname( buffer.top() )
655  << " on processing slot " << iSlot << endmsg;
656 
657  buffer.pop();
658  }
659 
660  } else {
661  for ( auto it = thisAlgsStates.begin( AState::DATAREADY ); it != thisAlgsStates.end( AState::DATAREADY ); ++it ) {
662  uint algIndex = *it;
663 
664  bool IOBound = false;
665  if ( m_useIOBoundAlgScheduler ) IOBound = m_precSvc->isBlocking( index2algname( algIndex ) );
666 
667  if ( !IOBound )
668  partial_sc = promoteToScheduled( algIndex, iSlot, thisSlotPtr->eventContext );
669  else
670  partial_sc = promoteToAsyncScheduled( algIndex, iSlot, thisSlotPtr->eventContext );
671 
672  ON_VERBOSE if ( partial_sc.isFailure() ) verbose() << "Could not apply transition from " << AState::DATAREADY
673  << " for algorithm " << index2algname( algIndex )
674  << " on processing slot " << iSlot << endmsg;
675  }
676  }
677 
678  // Check for algorithms ready in sub-slots
679  for ( auto& subslot : thisSlot.allSubSlots ) {
680  auto& subslotStates = subslot.algsStates;
681  for ( auto it = subslotStates.begin( AState::DATAREADY ); it != subslotStates.end( AState::DATAREADY ); ++it ) {
682  uint algIndex{*it};
683  partial_sc = promoteToScheduled( algIndex, iSlot, subslot.eventContext );
684  ON_VERBOSE if ( partial_sc.isFailure() ) verbose()
685  << "Could not apply transition from " << AState::DATAREADY << " for algorithm " << index2algname( algIndex )
686  << " on processing subslot " << subslot.eventContext->slot() << endmsg;
687  }
688  }
689 
690  if ( m_dumpIntraEventDynamics ) {
692  s << index2algname( algo_index ) << ", " << thisAlgsStates.sizeOfSubset( AState::CONTROLREADY ) << ", "
693  << thisAlgsStates.sizeOfSubset( AState::DATAREADY ) << ", " << thisAlgsStates.sizeOfSubset( AState::SCHEDULED )
694  << ", " << std::chrono::high_resolution_clock::now().time_since_epoch().count() << "\n";
695  auto threads = ( m_threadPoolSize != -1 ) ? std::to_string( m_threadPoolSize )
696  : std::to_string( tbb::task_scheduler_init::default_num_threads() );
697  std::ofstream myfile;
698  myfile.open( "IntraEventConcurrencyDynamics_" + threads + "T.csv", std::ios::app );
699  myfile << s.str();
700  myfile.close();
701  }
702 
703  // Not complete because this would mean that the slot is already free!
704  if ( m_precSvc->CFRulesResolved( thisSlot ) &&
705  !thisSlot.algsStates.containsAny( {AState::CONTROLREADY, AState::DATAREADY, AState::SCHEDULED} ) &&
706  !subSlotAlgsInStates( thisSlot, {AState::CONTROLREADY, AState::DATAREADY, AState::SCHEDULED} ) &&
707  !thisSlot.complete ) {
708 
709  thisSlot.complete = true;
710  // if the event did not fail, add it to the finished events
711  // otherwise it is taken care of in the error handling
712  if ( m_algExecStateSvc->eventStatus( *thisSlot.eventContext ) == EventStatus::Success ) {
713  m_finishedEvents.push( thisSlot.eventContext );
714  ON_DEBUG debug() << "Event " << thisSlot.eventContext->evt() << " finished (slot "
715  << thisSlot.eventContext->slot() << ")." << endmsg;
716  }
717 
718  // now let's return the fully evaluated result of the control flow
719  ON_DEBUG debug() << m_precSvc->printState( thisSlot ) << endmsg;
720 
721  thisSlot.eventContext = nullptr;
722 
723  } else if ( isStalled( thisSlot ) ) {
724  m_algExecStateSvc->setEventStatus( EventStatus::AlgStall, *thisSlot.eventContext );
725  eventFailed( thisSlot.eventContext );
726  }
727  } // end loop on slots
728 
729  ON_VERBOSE verbose() << "States Updated." << endmsg;
730 
731  return global_sc;
732 }
733 
734 //---------------------------------------------------------------------------
735 
743 {
744 
745  if ( m_actionsCounts[slot.eventContext->slot()] == 0 &&
746  !slot.algsStates.containsAny( {AState::DATAREADY, AState::SCHEDULED} ) &&
747  !subSlotAlgsInStates( slot, {AState::DATAREADY, AState::SCHEDULED} ) ) {
748 
749  error() << "*** Stall detected in slot " << slot.eventContext->slot() << "! ***" << endmsg;
750 
751  return true;
752  }
753  return false;
754 }
755 
756 //---------------------------------------------------------------------------
757 
763 {
764 
765  const uint slotIdx = eventContext->slot();
766 
767  error() << "Event " << eventContext->evt() << " on slot " << slotIdx << " failed" << endmsg;
768 
769  dumpSchedulerState( msgLevel( MSG::VERBOSE ) ? -1 : slotIdx );
770 
771  // dump temporal and topological precedence analysis (if enabled in the PrecedenceSvc)
772  m_precSvc->dumpPrecedenceRules( m_eventSlots[slotIdx] );
773 
774  // Push into the finished events queue the failed context
775  m_eventSlots[slotIdx].complete = true;
776  m_finishedEvents.push( eventContext );
777 }
778 
779 //---------------------------------------------------------------------------
780 
786 {
787 
788  // To have just one big message
789  std::ostringstream outputMS;
790 
791  outputMS << "Dumping scheduler state\n"
792  << "=========================================================================================\n"
793  << "++++++++++++++++++++++++++++++++++++ SCHEDULER STATE ++++++++++++++++++++++++++++++++++++\n"
794  << "=========================================================================================\n\n";
795 
796  //===========================================================================
797 
798  outputMS << "------------------ Last schedule: Task/Event/Slot/Thread/State Mapping "
799  << "------------------\n\n";
800 
801  // Figure if TimelineSvc is available (used below to detect threads IDs)
802  auto timelineSvc = serviceLocator()->service<ITimelineSvc>( "TimelineSvc", false );
803  if ( !timelineSvc.isValid() || !timelineSvc->isEnabled() ) {
804  outputMS << "WARNING Enable TimelineSvc in record mode (RecordTimeline = True) to trace the mapping\n";
805  } else {
806 
807  // Figure optimal printout layout
808  size_t indt( 0 );
809  for ( auto& slot : m_eventSlots )
810  for ( auto it = slot.algsStates.begin( AState::SCHEDULED ); it != slot.algsStates.end( AState::SCHEDULED ); ++it )
811  if ( index2algname( (uint)*it ).length() > indt ) indt = index2algname( (uint)*it ).length();
812 
813  // Figure the last running schedule across all slots
814  for ( auto& slot : m_eventSlots ) {
815  for ( auto it = slot.algsStates.begin( AState::SCHEDULED ); it != slot.algsStates.end( AState::SCHEDULED );
816  ++it ) {
817 
818  const std::string algoName{index2algname( (uint)*it )};
819 
820  outputMS << " task: " << std::setw( indt ) << algoName << " evt/slot: " << slot.eventContext->evt() << "/"
821  << slot.eventContext->slot();
822 
823  // Try to get POSIX threads IDs the currently running tasks are scheduled to
824  if ( timelineSvc.isValid() ) {
825  TimelineEvent te{};
826  te.algorithm = algoName;
827  te.slot = slot.eventContext->slot();
828  te.event = slot.eventContext->evt();
829 
830  if ( timelineSvc->getTimelineEvent( te ) )
831  outputMS << " thread.id: 0x" << std::hex << te.thread << std::dec;
832  else
833  outputMS << " thread.id: [unknown]"; // this means a task has just
834  // been signed off as SCHEDULED,
835  // but has not been assigned to a thread yet
836  // (i.e., not running yet)
837  }
838  outputMS << " state: [" << m_algExecStateSvc->algExecState( algoName, *( slot.eventContext ) ) << "]\n";
839  }
840  }
841  }
842 
843  //===========================================================================
844 
845  outputMS << "\n---------------------------- Task/CF/FSM Mapping "
846  << ( 0 > iSlot ? "[all slots] --" : "[target slot] " ) << "--------------------------\n\n";
847 
848  int slotCount = -1;
849  for ( auto& slot : m_eventSlots ) {
850  ++slotCount;
851  if ( slot.complete ) continue;
852 
853  outputMS << "[ slot: "
854  << ( slot.eventContext->valid() ? std::to_string( slot.eventContext->slot() ) : "[ctx invalid]" )
855  << " event: "
856  << ( slot.eventContext->valid() ? std::to_string( slot.eventContext->evt() ) : "[ctx invalid]" )
857  << " ]:\n\n";
858 
859  if ( 0 > iSlot || iSlot == slotCount ) {
860 
861  // Snapshot of the Control Flow and FSM states
862  outputMS << m_precSvc->printState( slot ) << "\n";
863 
864  // Mention sub slots
865  if ( slot.allSubSlots.size() ) {
866  outputMS << "\nNumber of sub-slots: " << slot.allSubSlots.size() << "\n";
867  auto slotID = slot.eventContext->valid() ? std::to_string( slot.eventContext->slot() ) : "[ctx invalid]";
868  for ( auto& ss : slot.allSubSlots ) {
869  outputMS << "[ slot: " << slotID << " sub-slot entry: " << ss.entryPoint << " event: "
870  << ( ss.eventContext->valid() ? std::to_string( ss.eventContext->evt() ) : "[ctx invalid]" )
871  << " ]:\n\n";
872  outputMS << m_precSvc->printState( ss ) << "\n";
873  }
874  }
875  }
876  }
877 
878  //===========================================================================
879 
880  if ( 0 <= iSlot ) {
881  outputMS << "\n------------------------------ Algorithm Execution States -----------------------------\n\n";
882  m_algExecStateSvc->dump( outputMS, *( m_eventSlots[iSlot].eventContext ) );
883  }
884 
885  outputMS << "\n=========================================================================================\n"
886  << "++++++++++++++++++++++++++++++++++++++ END OF DUMP ++++++++++++++++++++++++++++++++++++++\n"
887  << "=========================================================================================\n\n";
888 
889  info() << outputMS.str() << endmsg;
890 }
891 
892 //---------------------------------------------------------------------------
893 
894 StatusCode AvalancheSchedulerSvc::promoteToScheduled( unsigned int iAlgo, int si, EventContext* eventContext )
895 {
896 
897  if ( m_algosInFlight == m_maxAlgosInFlight ) return StatusCode::FAILURE;
898 
899  const std::string& algName( index2algname( iAlgo ) );
900  IAlgorithm* ialgoPtr = nullptr;
901  StatusCode sc( m_algResourcePool->acquireAlgorithm( algName, ialgoPtr ) );
902 
903  if ( sc.isSuccess() ) { // if we managed to get an algorithm instance try to schedule it
904 
905  ++m_algosInFlight;
906  auto promote2ExecutedClosure = [this, iAlgo, ialgoPtr, eventContext]() {
907  this->m_actionsQueue.push( [this, iAlgo, ialgoPtr, eventContext]() {
908  return this->AvalancheSchedulerSvc::promoteToExecuted( iAlgo, eventContext->slot(), ialgoPtr, eventContext );
909  } );
910  return StatusCode::SUCCESS;
911  };
912 
913  // Avoid to use tbb if the pool size is 1 and run in this thread
914  if ( -100 != m_threadPoolSize ) {
915  // the child task that executes an Algorithm
916  tbb::task* algoTask = new ( tbb::task::allocate_root() )
917  AlgoExecutionTask( ialgoPtr, eventContext, serviceLocator(), m_algExecStateSvc, promote2ExecutedClosure );
918  // schedule the algoTask
919  tbb::task::enqueue( *algoTask );
920 
921  } else {
922  AlgoExecutionTask theTask( ialgoPtr, eventContext, serviceLocator(), m_algExecStateSvc, promote2ExecutedClosure );
923  theTask.execute();
924  }
925 
926  ON_DEBUG debug() << "Algorithm " << algName << " was submitted on event " << eventContext->evt() << " in slot "
927  << si << ". Algorithms scheduled are " << m_algosInFlight << endmsg;
928 
929  // Update states in the appropriate event slot
930  StatusCode updateSc;
931  EventSlot& thisSlot = m_eventSlots[si];
932  if ( eventContext == thisSlot.eventContext ) {
933  // Event level (standard behaviour)
934  updateSc = thisSlot.algsStates.set( iAlgo, AState::SCHEDULED );
935  } else {
936  // Sub-slot
937  unsigned int const subSlotIndex = thisSlot.contextToSlot.at( eventContext );
938  updateSc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, AState::SCHEDULED );
939  }
940 
941  ON_VERBOSE dumpSchedulerState( -1 );
942 
943  if ( updateSc.isSuccess() )
944  ON_VERBOSE verbose() << "Promoting " << algName << " to SCHEDULED on slot " << si << endmsg;
945  return updateSc;
946  } else {
947  ON_DEBUG debug() << "Could not acquire instance for algorithm " << index2algname( iAlgo ) << " on slot " << si
948  << endmsg;
949  return sc;
950  }
951 }
952 
953 //---------------------------------------------------------------------------
954 
955 StatusCode AvalancheSchedulerSvc::promoteToAsyncScheduled( unsigned int iAlgo, int si, EventContext* eventContext )
956 {
957 
958  if ( m_IOBoundAlgosInFlight == m_maxIOBoundAlgosInFlight ) return StatusCode::FAILURE;
959 
960  // bool IOBound = m_precSvc->isBlocking(algName);
961 
962  const std::string& algName( index2algname( iAlgo ) );
963  IAlgorithm* ialgoPtr = nullptr;
964  StatusCode sc( m_algResourcePool->acquireAlgorithm( algName, ialgoPtr ) );
965 
966  if ( sc.isSuccess() ) { // if we managed to get an algorithm instance try to schedule it
967 
968  ++m_IOBoundAlgosInFlight;
969  auto promote2ExecutedClosure = [this, iAlgo, ialgoPtr, eventContext]() {
970  this->m_actionsQueue.push( [this, iAlgo, ialgoPtr, eventContext]() {
971  return this->AvalancheSchedulerSvc::promoteToAsyncExecuted( iAlgo, eventContext->slot(), ialgoPtr,
972  eventContext );
973  } );
974  return StatusCode::SUCCESS;
975  };
976  // Can we use tbb-based overloaded new-operator for a "custom" task (an algorithm wrapper, not derived from
977  // tbb::task)? it seems it works..
978  IOBoundAlgTask* theTask = new ( tbb::task::allocate_root() )
979  IOBoundAlgTask( ialgoPtr, eventContext, serviceLocator(), m_algExecStateSvc, promote2ExecutedClosure );
980  m_IOBoundAlgScheduler->push( *theTask );
981 
982  ON_DEBUG debug() << "[Asynchronous] Algorithm " << algName << " was submitted on event " << eventContext->evt()
983  << " in slot " << si << ". algorithms scheduled are " << m_IOBoundAlgosInFlight << endmsg;
984 
985  // Update states in the appropriate event slot
986  StatusCode updateSc;
987  EventSlot& thisSlot = m_eventSlots[si];
988  if ( eventContext == thisSlot.eventContext ) {
989  // Event level (standard behaviour)
990  updateSc = thisSlot.algsStates.set( iAlgo, AState::SCHEDULED );
991  } else {
992  // Sub-slot
993  unsigned int const subSlotIndex = thisSlot.contextToSlot.at( eventContext );
994  updateSc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, AState::SCHEDULED );
995  }
996 
997  ON_VERBOSE if ( updateSc.isSuccess() ) verbose() << "[Asynchronous] Promoting " << algName
998  << " to SCHEDULED on slot " << si << endmsg;
999  return updateSc;
1000  } else {
1001  ON_DEBUG debug() << "[Asynchronous] Could not acquire instance for algorithm " << index2algname( iAlgo )
1002  << " on slot " << si << endmsg;
1003  return sc;
1004  }
1005 }
1006 
1007 //---------------------------------------------------------------------------
1008 
1013  EventContext* eventContext )
1014 {
1015  Gaudi::Hive::setCurrentContext( eventContext );
1016  StatusCode sc = m_algResourcePool->releaseAlgorithm( algo->name(), algo );
1017 
1018  if ( sc.isFailure() ) {
1019  error() << "[Event " << eventContext->evt() << ", Slot " << eventContext->slot() << "] "
1020  << "Instance of algorithm " << algo->name() << " could not be properly put back." << endmsg;
1021  return StatusCode::FAILURE;
1022  }
1023 
1024  --m_algosInFlight;
1025 
1026  EventSlot& thisSlot = m_eventSlots[si];
1027 
1028  ON_DEBUG debug() << "Trying to handle execution result of " << algo->name() << " on slot " << si << endmsg;
1029 
1030  const AlgExecState& algstate = m_algExecStateSvc->algExecState( algo, *eventContext );
1031  AState state = algstate.execStatus().isSuccess()
1032  ? ( algstate.filterPassed() ? AState::EVTACCEPTED : AState::EVTREJECTED )
1033  : AState::ERROR;
1034 
1035  // Update states in the appropriate slot
1036  if ( eventContext == thisSlot.eventContext ) {
1037  // Event level (standard behaviour)
1038  sc = thisSlot.algsStates.set( iAlgo, state );
1039  } else {
1040  // Sub-slot
1041  unsigned int const subSlotIndex = thisSlot.contextToSlot.at( eventContext );
1042  sc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, state );
1043  }
1044 
1045  ON_VERBOSE if ( sc.isSuccess() ) verbose() << "Promoting " << algo->name() << " on slot " << si << " to " << state
1046  << endmsg;
1047 
1048  ON_DEBUG debug() << "Algorithm " << algo->name() << " executed in slot " << si << ". Algorithms scheduled are "
1049  << m_algosInFlight << endmsg;
1050 
1051  // Schedule an update of the status of the algorithms
1052  ++m_actionsCounts[si];
1053  m_actionsQueue.push( [this, si, iAlgo, eventContext]() {
1054  --this->m_actionsCounts[si]; // no bound check needed as decrements/increments are balanced in the current setup
1055  return this->updateStates( -1, iAlgo, eventContext );
1056  } );
1057 
1058  return sc;
1059 }
1060 
1061 //---------------------------------------------------------------------------
1062 
1067  EventContext* eventContext )
1068 {
1069  Gaudi::Hive::setCurrentContext( eventContext );
1070  StatusCode sc = m_algResourcePool->releaseAlgorithm( algo->name(), algo );
1071 
1072  if ( sc.isFailure() ) {
1073  error() << "[Asynchronous] [Event " << eventContext->evt() << ", Slot " << eventContext->slot() << "] "
1074  << "Instance of algorithm " << algo->name() << " could not be properly put back." << endmsg;
1075  return StatusCode::FAILURE;
1076  }
1077 
1078  --m_IOBoundAlgosInFlight;
1079 
1080  EventSlot& thisSlot = m_eventSlots[si];
1081 
1082  ON_DEBUG debug() << "[Asynchronous] Trying to handle execution result of " << algo->name() << " on slot " << si
1083  << endmsg;
1084 
1085  const AlgExecState& algstate = m_algExecStateSvc->algExecState( algo, *eventContext );
1086  AState state = algstate.execStatus().isSuccess()
1087  ? ( algstate.filterPassed() ? AState::EVTACCEPTED : AState::EVTREJECTED )
1088  : AState::ERROR;
1089 
1090  // Update states in the appropriate slot
1091  if ( eventContext == thisSlot.eventContext ) {
1092  // Event level (standard behaviour)
1093  sc = thisSlot.algsStates.set( iAlgo, state );
1094  } else {
1095  // Sub-slot
1096  unsigned int const subSlotIndex = thisSlot.contextToSlot.at( eventContext );
1097  sc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, state );
1098  }
1099 
1100  ON_VERBOSE if ( sc.isSuccess() ) verbose() << "[Asynchronous] Promoting " << algo->name() << " on slot " << si
1101  << " to " << state << endmsg;
1102 
1103  ON_DEBUG debug() << "[Asynchronous] Algorithm " << algo->name() << " executed in slot " << si
1104  << ". Algorithms scheduled are " << m_IOBoundAlgosInFlight << endmsg;
1105 
1106  // Schedule an update of the status of the algorithms
1107  ++m_actionsCounts[si];
1108  m_actionsQueue.push( [this, si, iAlgo, eventContext]() {
1109  --this->m_actionsCounts[si]; // no bound check needed as decrements/increments are balanced in the current setup
1110  return this->updateStates( -1, iAlgo, eventContext );
1111  } );
1112 
1113  return sc;
1114 }
1115 
1116 //---------------------------------------------------------------------------
1117 
1118 // Method to inform the scheduler about event views
1119 
1121  EventContext* viewContext )
1122 {
1123  // Find the top-level slot, to attach the sub-slot to
1124  int const topSlotIndex = sourceContext->slot();
1125  EventSlot& topSlot = m_eventSlots[topSlotIndex];
1126 
1127  // Prevent view nesting - this doesn't work because EventContext is copied when passed to algorithm
1128  /*if ( sourceContext != topSlot.eventContext )
1129  {
1130  fatal() << "Attempted to nest EventViews at node " << nodeName << ": this is not supported" << endmsg;
1131  return StatusCode::FAILURE;
1132  }*/
1133 
1134  if ( viewContext ) {
1135  // Make new slot by copying the top slot
1136  unsigned int lastIndex = topSlot.allSubSlots.size();
1137  topSlot.allSubSlots.push_back( EventSlot( m_eventSlots[topSlotIndex], viewContext ) );
1138  topSlot.allSubSlots.back().entryPoint = nodeName;
1139  topSlot.allSubSlots.back().algsStates.reset();
1140 
1141  // Store index of the new slot in lookup structures
1142  topSlot.contextToSlot[viewContext] = lastIndex;
1143  topSlot.subSlotsByNode[nodeName].push_back( lastIndex );
1144  } else {
1145  // Disable the view node if there are no views
1146  topSlot.subSlotsByNode[nodeName] = std::vector<unsigned int>( 0 );
1147  }
1148 
1149  return StatusCode::SUCCESS;
1150 }
const concurrency::PrecedenceRulesGraph * getRules() const
Precedence rules accessor.
Definition: PrecedenceSvc.h:65
#define ON_DEBUG
Wrapper around I/O-bound Gaudi-algorithms.
StatusCode tryPopFinishedEvent(EventContext *&eventContext) override
Try to fetch an event from the scheduler.
constexpr static const auto FAILURE
Definition: StatusCode.h:88
StatusCode initialize() override
Definition: Service.cpp:63
const unsigned int & getAlgoIndex() const
Get algorithm index.
T empty(T...args)
T open(T...args)
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:765
StatusCode finalize() override
Definition: Service.cpp:173
ContextID_t slot() const
Definition: EventContext.h:40
StatusCode initialize() override
Initialise.
void dumpSchedulerState(int iSlot)
Dump the state of the scheduler.
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:49
const DataObjIDColl & outputDataObjs() const override
bool isSuccess() const
Definition: StatusCode.h:287
EventContext * eventContext
Cache for the eventContext.
Definition: EventSlot.h:44
A service to resolve the task execution precedence.
Definition: PrecedenceSvc.h:21
T to_string(T...args)
std::string algorithm
Definition: ITimelineSvc.h:21
void activate()
Activate scheduler.
T end(T...args)
std::string entryPoint
Name of the node this slot is attached to ("" for top level)
Definition: EventSlot.h:57
size_t sizeOfSubset(State state) const
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
STL class.
bool isFailure() const
Definition: StatusCode.h:139
unsigned int algname2index(const std::string &algoname)
Convert a name to an integer.
T setw(T...args)
virtual const std::string & type() const =0
The type of the algorithm.
tbb::task * execute() override
ContextEvt_t evt() const
Definition: EventContext.h:39
STL class.
#define DECLARE_COMPONENT(type)
T at(T...args)
virtual StatusCode scheduleEventView(EventContext const *sourceContext, std::string const &nodeName, EventContext *viewContext) override
Method to inform the scheduler about event views.
StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts) override
bool containsAny(std::initializer_list< State > l) const
check if the collection contains at least one state of any listed types
T push_back(T...args)
STL class.
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
StatusCode promoteToScheduled(unsigned int iAlgo, int si, EventContext *)
Algorithm promotion.
StatusCode updateStates(int si=-1, int algo_index=-1, EventContext *=nullptr)
Loop on algorithm in the slots and promote them to successive states (-1 for algo_index means skippin...
StatusCode popFinishedEvent(EventContext *&eventContext) override
Blocks until an event is available.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
const DataObjIDColl & inputDataObjs() const override
T close(T...args)
StatusCode set(unsigned int iAlgo, State newState)
StatusCode finalize() override
Finalise.
bool complete
Flags completion of the event.
Definition: EventSlot.h:51
T max(T...args)
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
State
Execution states of the algorithms.
GAUDI_API void setCurrentContext(const EventContext *ctx)
std::map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
Definition: EventSlot.h:55
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
StatusCode promoteToAsyncScheduled(unsigned int iAlgo, int si, EventContext *)
T insert(T...args)
void addDependency(const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
T find_if(T...args)
T size(T...args)
StatusCode pushNewEvent(EventContext *eventContext) override
Make an event available to the scheduler.
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:63
STL class.
void reset(EventContext *theeventContext)
Reset all resources in order to reuse the slot.
Definition: EventSlot.h:33
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
T begin(T...args)
Iterator begin(State kind)
T any_of(T...args)
const std::string & index2algname(unsigned int index)
Convert an integer to a name.
Class representing the event slot.
Definition: EventSlot.h:10
T back(T...args)
string s
Definition: gaudirun.py:253
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm *algo, EventContext *)
The call to this method is triggered only from within the AlgoExecutionTask.
T hex(T...args)
void eventFailed(EventContext *eventContext)
Method to execute if an event failed.
unsigned int freeSlots() override
Get free slots number.
T sort(T...args)
StatusCode promoteToAsyncExecuted(unsigned int iAlgo, int si, IAlgorithm *algo, EventContext *)
The call to this method is triggered only from within the IOBoundAlgTask.
StatusCode deactivate()
Deactivate scheduler.
bool filterPassed() const
T for_each(T...args)
std::string fullKey() const
Definition: DataObjID.cpp:99
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
std::map< EventContext *, unsigned int > contextToSlot
Quick lookup for sub-slots by event context (top level only)
Definition: EventSlot.h:61
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
const StatusCode & execStatus() const
static GAUDI_API void setNumConcEvents(const std::size_t &nE)
bool isStalled(const EventSlot &) const
Check if scheduling in a particular slot is in a stall.
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
T reserve(T...args)
#define ON_VERBOSE
Iterator end(State kind)