The Gaudi Framework  v36r6 (b1ee9983)
GaudiMP.Parallel.WorkManager Class Reference
Inheritance diagram for GaudiMP.Parallel.WorkManager:
Collaboration diagram for GaudiMP.Parallel.WorkManager:

Public Member Functions

def __init__ (self, ncpus="autodetect", ppservers=None)
 
def __del__ (self)
 
def process (self, task, items, timeout=90000)
 

Public Attributes

 ncpus
 
 ppservers
 
 sessions
 
 server
 
 mode
 
 pool
 
 stats
 

Private Member Functions

def _printStatistics (self)
 
def _mergeStatistics (self, stat)
 

Detailed Description

Class to in charge of managing the tasks and distributing them to
the workers. They can be local (using other cores) or remote
using other nodes in the local cluster

Definition at line 145 of file Parallel.py.

Constructor & Destructor Documentation

◆ __init__()

def GaudiMP.Parallel.WorkManager.__init__ (   self,
  ncpus = "autodetect",
  ppservers = None 
)

Definition at line 150 of file Parallel.py.

150  def __init__(self, ncpus="autodetect", ppservers=None):
151  if ncpus == "autodetect":
152  self.ncpus = multiprocessing.cpu_count()
153  else:
154  self.ncpus = ncpus
155  if ppservers:
156  import pp
157 
158  self.ppservers = ppservers
159  self.sessions = [SshSession(srv) for srv in ppservers]
160  self.server = pp.Server(ncpus=self.ncpus, ppservers=self.ppservers)
161  self.mode = "cluster"
162  else:
163  self.pool = multiprocessing.Pool(self.ncpus)
164  self.mode = "multicore"
165  self.stats = {}
166 

◆ __del__()

def GaudiMP.Parallel.WorkManager.__del__ (   self)

Definition at line 167 of file Parallel.py.

167  def __del__(self):
168  if hasattr(self, "server"):
169  self.server.destroy()
170  if hasattr(self, "pool"):
171  self.pool.close()
172 

Member Function Documentation

◆ _mergeStatistics()

def GaudiMP.Parallel.WorkManager._mergeStatistics (   self,
  stat 
)
private

Definition at line 225 of file Parallel.py.

225  def _mergeStatistics(self, stat):
226  if stat.name not in self.stats:
227  self.stats[stat.name] = Statistics()
228  s = self.stats[stat.name]
229  s.time += stat.time
230  s.njob += 1
231 
232 

◆ _printStatistics()

def GaudiMP.Parallel.WorkManager._printStatistics (   self)
private

Definition at line 207 of file Parallel.py.

207  def _printStatistics(self):
208  njobs = 0
209  for stat in self.stats.values():
210  njobs += stat.njob
211  print("Job execution statistics:")
212  print("job count | % of all jobs | job time sum | time per job | job server")
213  for name, stat in self.stats.items():
214  print(
215  " %d | %6.2f | %8.3f | %8.3f | %s"
216  % (
217  stat.njob,
218  100.0 * stat.njob / njobs,
219  stat.time,
220  stat.time / stat.njob,
221  name,
222  )
223  )
224 

◆ process()

def GaudiMP.Parallel.WorkManager.process (   self,
  task,
  items,
  timeout = 90000 
)

Definition at line 173 of file Parallel.py.

173  def process(self, task, items, timeout=90000):
174  if not isinstance(task, Task):
175  raise TypeError("task argument needs to be an 'Task' instance")
176  # --- Call the Local initialialization
177  task.initializeLocal()
178  # --- Schedule all the jobs ....
179  if self.mode == "cluster":
180  jobs = [
181  self.server.submit(
182  _prefunction,
183  (_ppfunction, task, item),
184  (),
185  ("GaudiMP.Parallel", "time"),
186  )
187  for item in items
188  ]
189  for job in jobs:
190  result, stat = job()
191  task._mergeResults(result)
192  self._mergeStatistics(stat)
193  self._printStatistics()
194  self.server.print_stats()
195  elif self.mode == "multicore":
196  start = time.time()
197  jobs = self.pool.map_async(_ppfunction, zip([task for i in items], items))
198  for result, stat in jobs.get(timeout):
199  task._mergeResults(result)
200  self._mergeStatistics(stat)
201  end = time.time()
202  self._printStatistics()
203  print("Time elapsed since server creation %f" % (end - start))
204  # --- Call the Local Finalize
205  task.finalize()
206 

Member Data Documentation

◆ mode

GaudiMP.Parallel.WorkManager.mode

Definition at line 161 of file Parallel.py.

◆ ncpus

GaudiMP.Parallel.WorkManager.ncpus

Definition at line 152 of file Parallel.py.

◆ pool

GaudiMP.Parallel.WorkManager.pool

Definition at line 163 of file Parallel.py.

◆ ppservers

GaudiMP.Parallel.WorkManager.ppservers

Definition at line 158 of file Parallel.py.

◆ server

GaudiMP.Parallel.WorkManager.server

Definition at line 160 of file Parallel.py.

◆ sessions

GaudiMP.Parallel.WorkManager.sessions

Definition at line 159 of file Parallel.py.

◆ stats

GaudiMP.Parallel.WorkManager.stats

Definition at line 165 of file Parallel.py.


The documentation for this class was generated from the following file:
gaudirun.process
process
Definition: gaudirun.py:545
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546