Skip to content

Commit

Permalink
Merge pull request #34 from chrhansk/feature-parallel-process-count
Browse files Browse the repository at this point in the history
Add processor count argument to runners
  • Loading branch information
chrhansk authored Jan 17, 2024
2 parents 925a5cb + 23c4759 commit 79eb47a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
project = "pygradflow"
copyright = "2023, Christoph Hansknecht"
author = "Christoph Hansknecht"
release = "0.3.4"
release = "0.3.5"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
15 changes: 11 additions & 4 deletions pygradflow/runners/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,23 @@ def solve(self, instances, args):
def log_filename(instance):
return self.output_filename(args, f"{instance.name}.log")

if args.parallel:
if args.parallel is not None:
import itertools
from multiprocessing import Pool
from multiprocessing import Pool, cpu_count

if args.parallel is True:
num_procs = cpu_count()
else:
num_procs = args.parallel

run_logger.info("Solving in parallel with up to %d processes", num_procs)

all_params = itertools.repeat(params)
all_log_filenames = [log_filename(instance) for instance in instances]

solve_args = zip(instances, all_params, all_log_filenames)

with Pool() as pool:
with Pool(num_procs) as pool:
results = pool.starmap(try_solve_instance, solve_args)

else:
Expand Down Expand Up @@ -100,7 +107,7 @@ def parser(self):
parser.add_argument("--output", type=str)
parser.add_argument("--max_size", type=int)
parser.add_argument("--name", type=str)
parser.add_argument("--parallel", action="store_true")
parser.add_argument("--parallel", nargs="?", type=int, const=True)

group = parser.add_argument_group(title="parameters")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pygradflow"
version = "0.3.4"
version = "0.3.5"
description = "PyGradFlow is a simple implementation of the sequential homotopy method to be used to solve general nonlinear programs."
authors = ["Christoph Hansknecht <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 79eb47a

Please sign in to comment.