Skip to content

Commit

Permalink
Fixed some bugs on Mac OS.
Browse files Browse the repository at this point in the history
  • Loading branch information
legaultmarc committed Oct 27, 2015
1 parent 9d5e563 commit 97e78b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions forward/scripts/forward_cli.py
Expand Up @@ -26,9 +26,9 @@ def run_from_configuration(yaml_file):
experiment.run_tasks()

print()
print("To view the interactive report, use the forward-cli.py script:")
print("To view the interactive report, use the forward-cli script:")
print()
print("forward-cli.py report {}".format(experiment.name))
print("forward-cli report {}".format(experiment.name))
print()


Expand Down
35 changes: 34 additions & 1 deletion forward/utils.py
Expand Up @@ -104,7 +104,40 @@ def check_rpy2():
return False


class Parallel(object):
def Parallel(num_cpu, f):
if num_cpu == 1:
return SingleCoreWorkQueue(f)
elif num_cpu > 1:
return MultiprocessingQueue(num_cpu, f)
else:
raise ValueError("Invalid number of CPUs to use ({}).".format(num_cpu))


class SingleCoreWorkQueue(object):
"""Emulates the Parallel interface without using multiple CPUs.
:param f: The target function.
:type f: function
See :py:class:`Parallel` for more details.
"""
def __init__(self, f):
self.f = f
self.results = []

def push_work(self, tu):
self.results.append(self.f(*tu))

def get_result(self):
if self.results:
return self.results.pop()

def done_pushing(self):
pass


class MultiprocessingQueue(object):
"""Class used to parallelize computation.
:param num_cpu: Number of CPUs to use (size of the worker pool).
Expand Down

0 comments on commit 97e78b8

Please sign in to comment.