The Gaudi Framework  v33r1 (b1225454)
concurrency::Supervisor Class Reference

#include <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 ){};
EventSlot * m_slot
Definition: Promoters.h:81

Member Function Documentation

◆ visit() [1/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 26 of file IGraphVisitor.h.

26 { return true; };

◆ visit() [2/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 35 of file IGraphVisitor.h.

35 { return true; };

◆ visit() [3/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 29 of file IGraphVisitor.h.

29 { 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]

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 170 of file Promoters.cpp.

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

◆ visit() [6/6]

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 335 of file Promoters.cpp.

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

◆ visitEnter() [1/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 31 of file IGraphVisitor.h.

31 { return true; };

◆ visitEnter() [2/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 34 of file IGraphVisitor.h.

34 { return true; };

◆ visitEnter() [3/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 25 of file IGraphVisitor.h.

25 { return true; };

◆ visitEnter() [4/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 28 of file IGraphVisitor.h.

28 { return true; };

◆ visitEnter() [5/6]

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 163 of file Promoters.cpp.

163  {
164 
165  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
166  return true;
167  }
EventSlot * m_slot
Definition: Promoters.h:81
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:87

◆ visitEnter() [6/6]

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 328 of file Promoters.cpp.

328  {
329 
330  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
331  return true;
332  }
EventSlot * m_slot
Definition: Promoters.h:81
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:87

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: