The Gaudi Framework  master (37c0b60a)
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 330 of file Promoters.cpp.

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

◆ 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 159 of file Promoters.cpp.

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

◆ 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 323 of file Promoters.cpp.

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

◆ 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 152 of file Promoters.cpp.

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

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:496
concurrency::Supervisor::m_trace
bool m_trace
Definition: Promoters.h:83
EventSlot::algsStates
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:85