The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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

 _initializeDone
 

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 66 of file Parallel.py.

Member Function Documentation

◆ __new__()

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

Definition at line 73 of file Parallel.py.

73  def __new__(cls, *args, **kwargs):
74  task = object.__new__(cls)
75  task.output = ()
76  task.environ = {}
77  for k, v in os.environ.items():
78  task.environ[k] = v
79  task.cwd = os.getcwd()
80  return task
81 

◆ _mergeResults()

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

Definition at line 94 of file Parallel.py.

94  def _mergeResults(self, result):
95  if not isinstance(result, type(self.output)):
96  raise TypeError("output type is not same as obtained result")
97  # --No iteratable---
98  if not hasattr(result, "__iter__"):
99  if hasattr(self.output, "Add"):
100  self.output.Add(result)
101  elif hasattr(self.output, "__iadd__"):
102  self.output += result
103  elif hasattr(self.output, "__add__"):
104  self.output = self.output + result
105  else:
106  raise TypeError("result cannot be added")
107  # --Dictionary---
108  elif isinstance(result, dict):
109  for key in result.keys():
110  if key in self.output:
111  if hasattr(self.output[key], "Add"):
112  self.output[key].Add(result[key])
113  elif hasattr(self.output[key], "__iadd__"):
114  self.output[key] += result[key]
115  elif hasattr(self.output[key], "__add__"):
116  self.output[key] = self.output[key] + result[key]
117  else:
118  raise TypeError("result cannot be added")
119  else:
120  self.output[key] = result[key]
121  # --Anything else (list)
122  else:
123  for i in range(min(len(self.output), len(result))):
124  if hasattr(self.output[i], "Add"):
125  self.output[i].Add(result[i])
126  elif hasattr(self.output[i], "__iadd__"):
127  self.output[i] += result[i]
128  elif hasattr(self.output[i], "__add__"):
129  self.output[i] = self.output[i] + result[i]
130  else:
131  raise TypeError("result cannot be added")
132 

◆ _resetOutput()

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

Definition at line 133 of file Parallel.py.

133  def _resetOutput(self):
134  output = isinstance(self.output, dict) and self.output.values() or self.output
135  for o in output:
136  if hasattr(o, "Reset"):
137  o.Reset()
138 
139 

◆ finalize()

def GaudiMP.Parallel.Task.finalize (   self)

Definition at line 91 of file Parallel.py.

91  def finalize(self):
92  pass
93 

◆ initializeLocal()

def GaudiMP.Parallel.Task.initializeLocal (   self)

Definition at line 82 of file Parallel.py.

82  def initializeLocal(self):
83  pass
84 

◆ initializeRemote()

def GaudiMP.Parallel.Task.initializeRemote (   self)

Definition at line 85 of file Parallel.py.

85  def initializeRemote(self):
86  pass
87 

◆ process()

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

Definition at line 88 of file Parallel.py.

88  def process(self, item):
89  pass
90 

Member Data Documentation

◆ _initializeDone

GaudiMP.Parallel.Task._initializeDone
staticprivate

Definition at line 71 of file Parallel.py.

◆ output

GaudiMP.Parallel.Task.output

Definition at line 104 of file Parallel.py.


The documentation for this class was generated from the following file:
gaudirun.process
process
Definition: gaudirun.py:548
gaudirun.type
type
Definition: gaudirun.py:160
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: details.h:86