The Gaudi Framework  v32r2 (46d42edc)
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 54 of file Promoters.h.

Constructor & Destructor Documentation

◆ Supervisor()

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

Constructor.

Definition at line 57 of file Promoters.h.

58  : m_slot( &slot ), m_cause( cause ), m_trace( ifTrace ){};
EventSlot * m_slot
Definition: Promoters.h:71

Member Function Documentation

◆ visit() [1/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 16 of file IGraphVisitor.h.

16 { return true; };

◆ visit() [2/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 25 of file IGraphVisitor.h.

25 { return true; };

◆ visit() [3/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 19 of file IGraphVisitor.h.

19 { return true; };

◆ visit() [4/6]

virtual bool concurrency::IGraphVisitor::visit
inline

Definition at line 22 of file IGraphVisitor.h.

22 { return true; };

◆ visit() [5/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.getNodeName() ) {
170  oldSlot = m_slot;
172  }
173 
174  // If children are in sub-slots, loop over all
175  auto searchResult = m_slot->subSlotsByNode.find( node.getNodeName() );
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 
302  // Leave sub-slot
304  }
305  } else {
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 
313  if ( oldSlot ) m_slot = oldSlot;
314  return false;
315  }
EventSlot * m_slot
Definition: Promoters.h:71
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Definition: EventSlot.h:84
Class representing an event slot.
Definition: EventSlot.h:14
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
T end(T... args)
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:90
T find(T... args)
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:86
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:88

◆ visit() [6/6]

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 325 of file Promoters.cpp.

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

◆ visitEnter() [1/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 21 of file IGraphVisitor.h.

21 { return true; };

◆ visitEnter() [2/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 24 of file IGraphVisitor.h.

24 { return true; };

◆ visitEnter() [3/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 15 of file IGraphVisitor.h.

15 { return true; };

◆ visitEnter() [4/6]

virtual bool concurrency::IGraphVisitor::visitEnter
inline

Definition at line 18 of file IGraphVisitor.h.

18 { return true; };

◆ visitEnter() [5/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  }
EventSlot * m_slot
Definition: Promoters.h:71
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77

◆ visitEnter() [6/6]

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 318 of file Promoters.cpp.

318  {
319 
320  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
321  return true;
322  }
EventSlot * m_slot
Definition: Promoters.h:71
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77

Member Data Documentation

◆ m_cause

Cause concurrency::Supervisor::m_cause

Definition at line 72 of file Promoters.h.

◆ m_slot

EventSlot* concurrency::Supervisor::m_slot

Definition at line 71 of file Promoters.h.

◆ m_trace

bool concurrency::Supervisor::m_trace

Definition at line 73 of file Promoters.h.


The documentation for this class was generated from the following files: