The Gaudi Framework  v32r2 (46d42edc)
GaudiMP.Parallel.Task Class Reference
Inheritance diagram for GaudiMP.Parallel.Task:
Collaboration diagram for GaudiMP.Parallel.Task:

Public Member Functions

def __new__ (cls, *args, **kwargs)
 
def initializeLocal (self)
 
def initializeRemote (self)
 
def process (self, item)
 
def finalize (self)
 

Public Attributes

 output
 

Private Member Functions

def _mergeResults (self, result)
 
def _resetOutput (self)
 

Static Private Attributes

bool _initializeDone = False
 

Detailed Description

Basic base class to encapsulate any processing that is going to be porcessed in parallel.
    User class much inherit from it and implement the methods initializeLocal,
    initializeRemote, process and finalize.   

Definition at line 57 of file Parallel.py.

Member Function Documentation

◆ __new__()

def GaudiMP.Parallel.Task.__new__ (   cls,
args,
**  kwargs 
)

Definition at line 63 of file Parallel.py.

63  def __new__(cls, *args, **kwargs):
64  task = object.__new__(cls)
65  task.output = ()
66  task.environ = {}
67  for k, v in os.environ.items():
68  task.environ[k] = v
69  task.cwd = os.getcwd()
70  return task
71 

◆ _mergeResults()

def GaudiMP.Parallel.Task._mergeResults (   self,
  result 
)
private

Definition at line 84 of file Parallel.py.

84  def _mergeResults(self, result):
85  if type(result) is not type(self.output):
86  raise TypeError("output type is not same as obtained result")
87  # --No iteratable---
88  if not hasattr(result, '__iter__'):
89  if hasattr(self.output, 'Add'):
90  self.output.Add(result)
91  elif hasattr(self.output, '__iadd__'):
92  self.output += result
93  elif hasattr(self.output, '__add__'):
94  self.output = self.output + result
95  else:
96  raise TypeError('result cannot be added')
97  # --Dictionary---
98  elif type(result) is dict:
99  if self.output.keys() <= result.keys():
100  minkeys = self.output.keys()
101  else:
102  minkeys = result.keys()
103  for key in result.keys():
104  if key in self.output:
105  if hasattr(self.output[key], 'Add'):
106  self.output[key].Add(result[key])
107  elif hasattr(self.output[key], '__iadd__'):
108  self.output[key] += result[key]
109  elif hasattr(self.output[key], '__add__'):
110  self.output[key] = self.output[key] + result[key]
111  else:
112  raise TypeError('result cannot be added')
113  else:
114  self.output[key] = result[key]
115  # --Anything else (list)
116  else:
117  for i in range(min(len(self.output), len(result))):
118  if hasattr(self.output[i], 'Add'):
119  self.output[i].Add(result[i])
120  elif hasattr(self.output[i], '__iadd__'):
121  self.output[i] += result[i]
122  elif hasattr(self.output[i], '__add__'):
123  self.output[i] = self.output[i] + result[i]
124  else:
125  raise TypeError('result cannot be added')
126 
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:202
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.

◆ _resetOutput()

def GaudiMP.Parallel.Task._resetOutput (   self)
private

Definition at line 127 of file Parallel.py.

127  def _resetOutput(self):
128  output = (type(self.output) is
129  dict) and self.output.values() or self.output
130  for o in output:
131  if hasattr(o, 'Reset'):
132  o.Reset()
133 
134 

◆ finalize()

def GaudiMP.Parallel.Task.finalize (   self)

Definition at line 81 of file Parallel.py.

81  def finalize(self):
82  pass
83 

◆ initializeLocal()

def GaudiMP.Parallel.Task.initializeLocal (   self)

Definition at line 72 of file Parallel.py.

72  def initializeLocal(self):
73  pass
74 

◆ initializeRemote()

def GaudiMP.Parallel.Task.initializeRemote (   self)

Definition at line 75 of file Parallel.py.

75  def initializeRemote(self):
76  pass
77 

◆ process()

def GaudiMP.Parallel.Task.process (   self,
  item 
)

Definition at line 78 of file Parallel.py.

78  def process(self, item):
79  pass
80 

Member Data Documentation

◆ _initializeDone

bool GaudiMP.Parallel.Task._initializeDone = False
staticprivate

Definition at line 61 of file Parallel.py.

◆ output

GaudiMP.Parallel.Task.output

Definition at line 94 of file Parallel.py.


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