Skip to content

Commit

Permalink
Added module variables for thouska#120
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkraft committed Feb 22, 2018
1 parent d82ecbf commit c8a5d68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
18 changes: 10 additions & 8 deletions spotpy/parallel/mproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,44 @@

import pathos.multiprocessing as mp

process_count = None

class PhaseChange(object):
"""
Object to identify a change of a simulation phase
"""
def __init__(self,phase):
self.phase=phase
def __init__(self, phase):
self.phase = phase

class ForEach(object):
"""
ForEach is a classes for multiprocessed work based on a generater object which is given if __call__ is called
We using the pathos multiprocessing module and the orderd map function where results are saved until results in
the given order are caluculated. We yielding back the result so a generator object is created.
"""
def __init__(self,process):
self.size = mp.cpu_count()
def __init__(self, process):
self.size = process_count or mp.cpu_count()
self.process = process
self.phase=None
self.pool = mp.ProcessingPool(self.size)

def is_idle(self):
return False

def terminate(self):
pass

def start(self):
pass

def setphase(self,phasename):
self.phase=phasename

def setphase(self, phasename):
self.phase = phasename

def f(self, job):
data = self.process(job)
return data

def __call__(self,jobs):
def __call__(self, jobs):
results = self.pool.imap(self.f, jobs)
for i in results:
yield i
14 changes: 9 additions & 5 deletions spotpy/parallel/umproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,36 @@

import pathos.multiprocessing as mp

process_count = None

class PhaseChange(object):
"""
Object to identify a change of a simulation phase
"""
def __init__(self,phase):
self.phase=phase
def __init__(self, phase):
self.phase = phase

class ForEach(object):
"""
ForEach is a classes for multiprocessed work based on a generater object which is given if __call__ is called
We using the pathos multiprocessing module and the unordered map function where results are yield back while some
processes are still running.
"""
def __init__(self,process):
self.size = mp.cpu_count()
def __init__(self, process):
self.size = process_count or mp.cpu_count()
self.process = process
self.phase=None
self.phase = None
self.pool = mp.ProcessingPool(self.size)

def is_idle(self):
return False

def terminate(self):
pass

def start(self):
pass

def setphase(self,phasename):
self.phase=phasename

Expand Down

0 comments on commit c8a5d68

Please sign in to comment.