The Gaudi Framework  master (53dee381)
Loading...
Searching...
No Matches
GaudiMP.pTools.Syncer Class Reference

Public Member Functions

 __init__ (self, nWorkers, log, manyEvents=False, limit=None, step=None, firstEvent=None)
 syncAll (self, step="Not specified")
 syncAllRolling (self)
 processHang (self)
 checkAll (self)
 checkLastEvents (self)

Public Attributes

 limit = limit
 step = step
dict d = {}
 manyEvents = manyEvents
 limitFirst = firstEvent
 keys = list(self.d.keys())
 nWorkers = nWorkers
 log = log

Detailed Description

Definition at line 621 of file pTools.py.

Constructor & Destructor Documentation

◆ __init__()

GaudiMP.pTools.Syncer.__init__ ( self,
nWorkers,
log,
manyEvents = False,
limit = None,
step = None,
firstEvent = None )

Definition at line 622 of file pTools.py.

624 ):
625 # Class to help synchronise the sub-processes
626 self.limit = limit
627 self.step = step
628 self.d = {}
629 self.manyEvents = manyEvents
630
631 for i in range(-2, nWorkers):
632 self.d[i] = SyncMini(Event(), lastEvent=Event())
633 if self.manyEvents:
634 self.limitFirst = firstEvent
635
636 self.keys = list(self.d.keys())
637 self.nWorkers = nWorkers
638 self.log = log
639

Member Function Documentation

◆ checkAll()

GaudiMP.pTools.Syncer.checkAll ( self)

Definition at line 727 of file pTools.py.

727 def checkAll(self):
728 # Check the status of each Sync object
729 # return True or False
730 currentStatus = [mini.check() for mini in self.d.values()]
731 return all(currentStatus)
732

◆ checkLastEvents()

GaudiMP.pTools.Syncer.checkLastEvents ( self)

Definition at line 733 of file pTools.py.

733 def checkLastEvents(self):
734 # check if all of the lastEvents are set to true in self.d[k][1]
735 stat = [sMini.checkLast() for sMini in self.d.values()]
736 return all(stat)
737
738
739# =========================== Methods =========================================
740
741

◆ processHang()

GaudiMP.pTools.Syncer.processHang ( self)

Definition at line 721 of file pTools.py.

721 def processHang(self):
722 self.log.critical("Some proc is hanging during Event processing!")
723 for k in self.keys:
724 self.log.critical(f"Proc/Stat : {k} / {self.d[k].check()}")
725 return
726

◆ syncAll()

GaudiMP.pTools.Syncer.syncAll ( self,
step = "Not specified" )

Definition at line 640 of file pTools.py.

640 def syncAll(self, step="Not specified"):
641 # is it this method, or is it the rolling version needed?
642 # if so, drop through...
643
644 if self.manyEvents:
645 sc = self.syncAllRolling()
646 return sc
647
648 # Regular version ----------------------------
649 for i in range(0, self.limit, self.step):
650 if self.checkAll():
651 self.log.info(f"{step} : All procs done @ {i} s")
652 break
653 else:
654 time.sleep(self.step)
655
656 # Now the time limit is up... check the status one final time
657 if self.checkAll():
658 self.log.info(f"All processes : {step} ok.")
659 return SUCCESS
660 else:
661 self.log.critical(f"Some process is hanging on : {step}")
662 for k in self.keys:
663 self.log.critical(f"{step} : Proc/Stat : {k}/{self.d[k].check()}")
664 return FAILURE
665

◆ syncAllRolling()

GaudiMP.pTools.Syncer.syncAllRolling ( self)

Definition at line 666 of file pTools.py.

666 def syncAllRolling(self):
667 # Keep track of the progress of Event processing
668 # Each process syncs after each event, so keep clearing
669 # the sync Event, and re-checking
670 # Note the time between True checks too, if the time
671 # between events exceeds singleEvent, this is considered a hang
672
673 # set the initial time
674 begin = time.time()
675 firstEv = {}
676 timers = {}
677 for k in self.keys:
678 self.d[k].reset()
679 firstEv[k] = False
680 timers[k] = 0.0
681
682 active = self.keys
683 while True:
684 # check the status of each sync object
685 for k in active:
686 sMini = self.d[k]
687
688 if sMini.check() or sMini.checkLast():
689 if sMini.checkLast() and sMini.check():
690 # if last Event set,then event loop finished
691 active.remove(k)
692 alive = time.time() - begin
693 self.log.info(f"Audit : Node {k} alive for {alive:5.2}")
694 else:
695 sMini.reset()
696 else:
697 # the event still has not been checked, how long is that?
698 # is it the first Event?
699 wait = time.time() - sMini.getTime()
700 cond = wait > self.limit
701 if not firstEv[k]:
702 cond = wait > self.limitFirst
703 firstEv[k] = True
704 if cond:
705 # It is hanging!
706 self.log.critical(f"Single event wait : {wait:5.2f}")
707 self.processHang()
708 return FAILURE
709
710 # Termination Criteria : if all procs have been removed, we're done
711 if self.checkLastEvents():
712 self.log.info("TC met for event loop")
713 break
714 else:
715 # sleep, loop again
716 time.sleep(self.step)
717
718 self.log.info("All processes Completed all Events ok")
719 return SUCCESS
720

Member Data Documentation

◆ d

dict GaudiMP.pTools.Syncer.d = {}

Definition at line 628 of file pTools.py.

◆ keys

GaudiMP.pTools.Syncer.keys = list(self.d.keys())

Definition at line 636 of file pTools.py.

◆ limit

GaudiMP.pTools.Syncer.limit = limit

Definition at line 626 of file pTools.py.

◆ limitFirst

GaudiMP.pTools.Syncer.limitFirst = firstEvent

Definition at line 634 of file pTools.py.

◆ log

GaudiMP.pTools.Syncer.log = log

Definition at line 638 of file pTools.py.

◆ manyEvents

GaudiMP.pTools.Syncer.manyEvents = manyEvents

Definition at line 629 of file pTools.py.

◆ nWorkers

GaudiMP.pTools.Syncer.nWorkers = nWorkers

Definition at line 637 of file pTools.py.

◆ step

GaudiMP.pTools.Syncer.step = step

Definition at line 627 of file pTools.py.


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