Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pyevolve/GPopulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def __init__(self, genome):
self.allSlots = [self.scaleMethod]

self.internalParams = {}
self.multiProcessing = (False, False)
self.multiProcessing = (False, False, None)

# Statistics
self.statted = False
self.stats = Statistics()

def setMultiProcessing(self, flag=True, full_copy=False):
def setMultiProcessing(self, flag=True, full_copy=False, max_processes=None):
""" Sets the flag to enable/disable the use of python multiprocessing module.
Use this option when you have more than one core on your CPU and when your
evaluation function is very slow.
Expand All @@ -168,6 +168,7 @@ def setMultiProcessing(self, flag=True, full_copy=False):

:param flag: True (default) or False
:param full_copy: True or False (default)
:param max_processes: None (default) or an integer value

.. warning:: Use this option only when your evaluation function is slow, se you
will get a good tradeoff between the process communication speed and the
Expand All @@ -177,7 +178,7 @@ def setMultiProcessing(self, flag=True, full_copy=False):
The `setMultiProcessing` method.

"""
self.multiProcessing = (flag, full_copy)
self.multiProcessing = (flag, full_copy, max_processes)

def setMinimax(self, minimax):
""" Sets the population minimax
Expand Down Expand Up @@ -385,7 +386,7 @@ def evaluate(self, **args):
# We have multiprocessing
if self.multiProcessing[0] and MULTI_PROCESSING:
logging.debug("Evaluating the population using the multiprocessing method")
proc_pool = Pool()
proc_pool = Pool(processes=self.multiProcessing[2])

# Multiprocessing full_copy parameter
if self.multiProcessing[1]:
Expand Down
5 changes: 3 additions & 2 deletions pyevolve/GSimpleGA.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def __repr__(self):
ret += "\n"
return ret

def setMultiProcessing(self, flag=True, full_copy=False):
def setMultiProcessing(self, flag=True, full_copy=False, max_processes=None):
""" Sets the flag to enable/disable the use of python multiprocessing module.
Use this option when you have more than one core on your CPU and when your
evaluation function is very slow.
Expand All @@ -403,6 +403,7 @@ def setMultiProcessing(self, flag=True, full_copy=False):

:param flag: True (default) or False
:param full_copy: True or False (default)
:param max_processes: None (default) or an integer value

.. warning:: Use this option only when your evaluation function is slow, so you'll
get a good tradeoff between the process communication speed and the
Expand All @@ -424,7 +425,7 @@ def setMultiProcessing(self, flag=True, full_copy=False):
if type(full_copy) != BooleanType:
Util.raiseException("Multiprocessing 'full_copy' option must be True or False", TypeError)

self.internalPop.setMultiProcessing(flag, full_copy)
self.internalPop.setMultiProcessing(flag, full_copy, max_processes)

def setMigrationAdapter(self, migration_adapter=None):
""" Sets the Migration Adapter
Expand Down