The Gaudi Framework  v36r16 (ea80daf8)
concurrency::Supervisor Class Reference

#include </builds/gaudi/Gaudi/GaudiHive/src/PRGraph/Visitors/Promoters.h>

Inheritance diagram for concurrency::Supervisor:
Collaboration diagram for concurrency::Supervisor:

Public Member Functions

 Supervisor (EventSlot &slot, const Cause &cause, bool ifTrace=false)
 Constructor. More...
 
bool visitEnter (DecisionNode &) const override
 
bool visit (DecisionNode &) override
 
bool visitEnter (AlgorithmNode &) const override
 
bool visit (AlgorithmNode &) override
 
virtual bool visit (DecisionNode &)
 
virtual bool visit (AlgorithmNode &)
 
virtual bool visit (DataNode &)
 
virtual bool visit (ConditionNode &)
 
virtual bool visitEnter (DecisionNode &) const
 
virtual bool visitEnter (AlgorithmNode &) const
 
virtual bool visitEnter (DataNode &) const
 
virtual bool visitEnter (ConditionNode &) const
 
- Public Member Functions inherited from concurrency::IGraphVisitor
virtual ~IGraphVisitor ()=default
 
virtual bool visitEnter (DataNode &) const
 
virtual bool visit (DataNode &)
 
virtual bool visitEnter (ConditionNode &) const
 
virtual bool visit (ConditionNode &)
 
virtual void reset ()
 

Public Attributes

EventSlotm_slot
 
Cause m_cause
 
bool m_trace
 

Detailed Description

Definition at line 64 of file Promoters.h.

Constructor & Destructor Documentation

◆ Supervisor()

concurrency::Supervisor::Supervisor ( EventSlot slot,
const Cause cause,
bool  ifTrace = false 
)
inline

Constructor.

Definition at line 67 of file Promoters.h.

68  : m_slot( &slot ), m_cause( cause ), m_trace( ifTrace ){};

Member Function Documentation

◆ visit() [1/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 29 of file IGraphVisitor.h.

29 { return true; };

◆ visit() [2/6]

bool concurrency::Supervisor::visit ( AlgorithmNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 331 of file Promoters.cpp.

331  {
332 
333  bool result = false;
334 
335  auto& states = m_slot->algsStates;
336  auto& state = states[node.getAlgoIndex()];
337 
338  // Promote with INITIAL->CR
339  if ( AState::INITIAL == state ) states.set( node.getAlgoIndex(), AState::CONTROLREADY ).ignore();
340 
341  // Try to promote with CR->DR
342  if ( AState::CONTROLREADY == state ) {
343  auto promoter = DataReadyPromoter( *m_slot, m_cause, m_trace );
344  result = promoter.visit( node );
345  } else {
346  result = true;
347  }
348 
349  // return true only when an algorithm is not lower than DR in its FSM
350  // i.e., the visitor has done everything it could with this algorithm
351  return result;
352  }

◆ visit() [3/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 35 of file IGraphVisitor.h.

35 { return true; };

◆ visit() [4/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 32 of file IGraphVisitor.h.

32 { return true; };

◆ visit() [5/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 26 of file IGraphVisitor.h.

26 { return true; };

◆ visit() [6/6]

bool concurrency::Supervisor::visit ( DecisionNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 160 of file Promoters.cpp.

160  {
161 
162  bool foundNonResolvedChild = false;
163  bool foundNegativeChild = false;
164  bool foundPositiveChild = false;
165  int decision = -1;
166 
167  // Leave a sub-slot if this is the exit node
168  EventSlot* oldSlot = nullptr;
169  if ( m_slot->parentSlot && m_slot->entryPoint == node.name() ) {
170  oldSlot = m_slot;
172  }
173 
174  // If children are in sub-slots, loop over all
175  auto searchResult = m_slot->subSlotsByNode.find( node.name() );
176  if ( searchResult != m_slot->subSlotsByNode.end() ) {
177  bool breakout = false;
178  for ( unsigned int slotIndex : searchResult->second ) {
179 
180  // Enter the sub-slot
181  m_slot = &( m_slot->allSubSlots[slotIndex] );
182 
183  for ( auto child : node.getDaughters() ) {
184 
185  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
186 
187  if ( childDecision == -1 )
188  foundNonResolvedChild = true;
189  else if ( childDecision == 1 )
190  foundPositiveChild = true;
191  else
192  foundNegativeChild = true;
193 
194  if ( node.m_modePromptDecision ) {
195  if ( node.m_modeOR && foundPositiveChild ) {
196  decision = 1;
197  breakout = true;
198  break;
199  } else if ( !node.m_modeOR && foundNegativeChild ) {
200  decision = 0;
201  breakout = true;
202  break;
203  }
204  } else {
205  if ( foundNonResolvedChild ) {
206  breakout = true;
207  break;
208  }
209  }
210  }
211 
212  // Leave the sub-slot
214  if ( breakout ) break;
215  }
216  } else {
217  for ( auto child : node.getDaughters() ) {
218  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
219 
220  if ( childDecision == -1 )
221  foundNonResolvedChild = true;
222  else if ( childDecision == 1 )
223  foundPositiveChild = true;
224  else
225  foundNegativeChild = true;
226 
227  if ( node.m_modePromptDecision ) {
228  if ( node.m_modeOR && foundPositiveChild ) {
229  decision = 1;
230  break;
231  } else if ( !node.m_modeOR && foundNegativeChild ) {
232  decision = 0;
233  break;
234  }
235  } else {
236  if ( foundNonResolvedChild ) break;
237  }
238  }
239  } // end monitoring children
240 
241  if ( !foundNonResolvedChild && decision == -1 ) {
242  if ( node.m_modeOR ) { // OR
243  if ( foundPositiveChild )
244  decision = 1;
245  else
246  decision = 0;
247  } else { // AND
248  if ( foundNegativeChild )
249  decision = 0;
250  else
251  decision = 1;
252  }
253  }
254 
255  if ( node.m_inverted && decision == 1 )
256  decision = 0;
257  else if ( node.m_inverted && decision == 0 )
258  decision = 1;
259 
260  if ( node.m_allPass && !foundNonResolvedChild ) decision = 1;
261 
262  if ( decision != -1 ) {
263  m_slot->controlFlowState[node.getNodeIndex()] = decision;
264 
265  // propagate aggregated decision upward to active regions of the graph
266  if ( node.m_parents.size() == 1 ) {
267  node.m_parents[0]->accept( *this );
268  } else if ( m_slot->parentSlot ) {
269  auto scout = SubSlotScout( m_slot, node );
270  for ( auto& p : node.m_parents ) {
271  p->accept( scout );
272  if ( scout.reply() ) p->accept( *this );
273  scout.reset();
274  }
275  } else {
276  auto scout = ActiveLineageScout( m_slot, node );
277  for ( auto& p : node.m_parents ) {
278  p->accept( scout );
279  if ( scout.reply() ) p->accept( *this );
280  scout.reset();
281  }
282  }
283 
284  if ( oldSlot ) m_slot = oldSlot;
285  return true;
286  }
287 
288  // if no decision can be made yet, request further information downwards
289  // Enter subslots for children if needed
290  if ( searchResult != m_slot->subSlotsByNode.end() ) {
291  for ( unsigned int slotIndex : searchResult->second ) {
292 
293  // Enter sub-slot
294  m_slot = &( m_slot->allSubSlots[slotIndex] );
295 
296  for ( auto child : node.getDaughters() ) {
297  bool result = child->accept( *this );
298  if ( !node.m_modeConcurrent )
299  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
300 
301  // Check that this node may stil be evaluated
302  if ( node.m_modePromptDecision && m_slot->controlFlowState[node.getNodeIndex()] > -1 ) break;
303  }
304 
305  // Leave sub-slot
307  }
308  } else {
309  for ( auto child : node.getDaughters() ) {
310  bool result = child->accept( *this );
311  if ( !node.m_modeConcurrent )
312  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
313 
314  // Check that this node may stil be evaluated
315  if ( node.m_modePromptDecision && m_slot->controlFlowState[node.getNodeIndex()] > -1 ) break;
316  }
317  }
318 
319  if ( oldSlot ) m_slot = oldSlot;
320  return false;
321  }

◆ visitEnter() [1/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 28 of file IGraphVisitor.h.

28 { return true; };

◆ visitEnter() [2/6]

bool concurrency::Supervisor::visitEnter ( AlgorithmNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 324 of file Promoters.cpp.

324  {
325 
326  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
327  return true;
328  }

◆ visitEnter() [3/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 34 of file IGraphVisitor.h.

34 { return true; };

◆ visitEnter() [4/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 31 of file IGraphVisitor.h.

31 { return true; };

◆ visitEnter() [5/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 25 of file IGraphVisitor.h.

25 { return true; };

◆ visitEnter() [6/6]

bool concurrency::Supervisor::visitEnter ( DecisionNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 153 of file Promoters.cpp.

153  {
154 
155  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
156  return true;
157  }

Member Data Documentation

◆ m_cause

Cause concurrency::Supervisor::m_cause

Definition at line 82 of file Promoters.h.

◆ m_slot

EventSlot* concurrency::Supervisor::m_slot

Definition at line 81 of file Promoters.h.

◆ m_trace

bool concurrency::Supervisor::m_trace

Definition at line 83 of file Promoters.h.


The documentation for this class was generated from the following files:
EventSlot::subSlotsByNode
std::unordered_map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
Definition: EventSlot.h:98
std::unordered_map::find
T find(T... args)
EventSlot
Class representing an event slot.
Definition: EventSlot.h:24
EventSlot::entryPoint
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Definition: EventSlot.h:94
EventSlot::parentSlot
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:96
concurrency::Supervisor::m_slot
EventSlot * m_slot
Definition: Promoters.h:81
concurrency::Supervisor::m_cause
Cause m_cause
Definition: Promoters.h:82
EventSlot::allSubSlots
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:100
EventSlot::controlFlowState
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:87
std::unordered_map::end
T end(T... args)
compareRootHistos.state
state
Definition: compareRootHistos.py:498
concurrency::Supervisor::m_trace
bool m_trace
Definition: Promoters.h:83
EventSlot::algsStates
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:85