diff --git a/forward/scripts/forward_cli.py b/forward/scripts/forward_cli.py index eb44efe..6f23da4 100755 --- a/forward/scripts/forward_cli.py +++ b/forward/scripts/forward_cli.py @@ -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() diff --git a/forward/utils.py b/forward/utils.py index 3ec1ecc..79a835d 100644 --- a/forward/utils.py +++ b/forward/utils.py @@ -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).