Skip to content

Commit

Permalink
use multiprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Aug 13, 2024
1 parent efa66cb commit 8664d70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/depiction/parallel_ops/parallel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ParallelConfig:
"""Encapsulates the configuration for parallel processing, and some common functionality to use this information.
:param n_jobs: the number of parallel jobs to run
:param task_size: the size of each task, if None, the number of tasks will be divided by the number of jobs
:param verbose: the verbosity level of the parallel processing (passed to joblib currently)
:param verbose: the verbosity level of the parallel processing (TODO currently unused)
"""

n_jobs: int
Expand Down
10 changes: 4 additions & 6 deletions src/depiction/parallel_ops/parallel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import functools
import operator

import joblib

from typing import TypeVar, TYPE_CHECKING, Callable, Any

import multiprocess.pool

if TYPE_CHECKING:
from depiction.parallel_ops import ParallelConfig

Expand Down Expand Up @@ -41,9 +40,8 @@ def __call__(
reduce_fn: Callable[[list[T]], U] | None = None,
) -> list[T] | U:
reduce_fn = reduce_fn if reduce_fn is not None else list
joblib_parallel = joblib.Parallel(n_jobs=self.config.n_jobs, verbose=self.config.verbose)
operation = self._bind(operation=operation, bind_kwargs=bind_kwargs)
return reduce_fn(joblib_parallel(joblib.delayed(operation)(task) for task in tasks))
with multiprocess.pool.Pool(self.config.n_jobs) as pool:
return reduce_fn(pool.map(self._bind(operation=operation, bind_kwargs=bind_kwargs), tasks))

def _bind(
self,
Expand Down

0 comments on commit 8664d70

Please sign in to comment.