libparallel: multiprocessing helping functions

Module in charge of parallelizing the execution of tasks.

class haddock.libs.libparallel.Scheduler(tasks: list[SupportsRunT], ncores: int | None = None, max_cpus: bool = False)[source]

Bases: object

Schedules tasks to run in multiprocessing.

property num_processes: int

Number of processors to use.

run() None[source]

Run tasks in parallel.

terminate() None[source]

Terminate tasks in a controlled way.

class haddock.libs.libparallel.Worker(tasks: Sequence[SupportsRunT])[source]

Bases: Process

Work on tasks.

run() None[source]

Execute tasks.

haddock.libs.libparallel.get_index_list(nmodels, ncores)[source]

Optimal distribution of models among cores

Parameters:
  • nmodels (int) – Number of models to be distributed.

  • ncores (int) – Number of cores to be used.

Returns:

index_list (list) – List of model indexes to be used for the parallel scanning.

haddock.libs.libparallel.split_tasks(lst: Sequence[AnyT], n: int) Generator[Sequence[AnyT], None, None][source]

Split tasks into N-sized chunks.