The Gaudi Framework  master (e68eea06)
Loading...
Searching...
No Matches
GaudiMP.Parallel.Task Class Reference
Inheritance diagram for GaudiMP.Parallel.Task:
Collaboration diagram for GaudiMP.Parallel.Task:

Public Member Functions

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

Public Attributes

 output = result
 

Protected Member Functions

 _mergeResults (self, result)
 
 _resetOutput (self)
 

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

Member Function Documentation

◆ __new__()

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()

GaudiMP.Parallel.Task._mergeResults ( self,
result )
protected

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()

GaudiMP.Parallel.Task._resetOutput ( self)
protected

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()

GaudiMP.Parallel.Task.finalize ( self)

Definition at line 91 of file Parallel.py.

91 def finalize(self):
92 pass
93

◆ initializeLocal()

GaudiMP.Parallel.Task.initializeLocal ( self)

Definition at line 82 of file Parallel.py.

82 def initializeLocal(self):
83 pass
84

◆ initializeRemote()

GaudiMP.Parallel.Task.initializeRemote ( self)

Definition at line 85 of file Parallel.py.

85 def initializeRemote(self):
86 pass
87

◆ process()

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

bool GaudiMP.Parallel.Task._initializeDone = False
staticprotected

Definition at line 71 of file Parallel.py.

◆ output

GaudiMP.Parallel.Task.output = result

Definition at line 95 of file Parallel.py.


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