Skip to content

Commit

Permalink
avoid pool creation to get effective number of jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
asiomchen committed Jan 28, 2025
1 parent 65add07 commit a55dd31
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions scikit_mol/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Callable, Optional

import numpy as np
from joblib import Parallel, delayed
from joblib import Parallel, delayed, effective_n_jobs


def parallelized_with_batches(
Expand All @@ -28,12 +28,10 @@ def parallelized_with_batches(
Sequence[Optional[Any]]
A sequence of results from the function executed in parallel.
"""

pool = Parallel(n_jobs=n_jobs, **job_kwargs)
n_jobs = pool._effective_n_jobs()
n_jobs = effective_n_jobs(n_jobs)
if n_jobs > len(inputs_list):
n_jobs = len(inputs_list)
pool = Parallel(n_jobs=n_jobs, **job_kwargs)
pool = Parallel(n_jobs=n_jobs, **job_kwargs)

input_chunks = np.array_split(inputs_list, n_jobs)
results = pool(delayed(fn)(chunk) for chunk in input_chunks)
Expand Down

0 comments on commit a55dd31

Please sign in to comment.