Skip to content

Commit

Permalink
Merge pull request #64 from nikobockerman/improve-parallel-execution
Browse files Browse the repository at this point in the history
Improve parallel execution
  • Loading branch information
nikobockerman authored Oct 17, 2024
2 parents 53a8897 + 25e1a70 commit 3e7b1cd
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions adventofcode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,28 @@ def _specific_problem(

def _multiple_problems(days: Iterable[int], day_suffix: str) -> int:
all_passed = None
slowest = None
start = time.perf_counter()
with joblib.Parallel(n_jobs=-1) as parallel:
slowest = None
for day in days:
problems = ANSWERS.get(day, {})
inputs = [
_get_problem_input(day, day_suffix, problem) for problem in problems
]
outputs = parallel(joblib.delayed(_exec_problem)(x) for x in inputs)
results = (_process_output(x) for x in outputs)
for result in results:
passed = _report_one_of_many_problems(result)
if all_passed is None:
all_passed = passed
all_passed &= passed
assert result.duration is not None
if slowest is None:
with joblib.Parallel(n_jobs=-1, return_as="generator") as parallel:
inputs = [
_get_problem_input(day, day_suffix, problem)
for day in days
for problem in ANSWERS.get(day, {})
]
outputs = parallel(joblib.delayed(_exec_problem)(x) for x in inputs)
results = (_process_output(x) for x in outputs)
for result in results:
passed = _report_one_of_many_problems(result)
if all_passed is None:
all_passed = passed
all_passed &= passed
assert result.duration is not None
if slowest is None:
slowest = result
else:
assert slowest.duration is not None
if result.duration > slowest.duration:
slowest = result
else:
assert slowest.duration is not None
if result.duration > slowest.duration:
slowest = result

duration = time.perf_counter() - start

Expand Down

0 comments on commit 3e7b1cd

Please sign in to comment.