pymkm.utils.parallel

Parallelization utility for determining optimal worker count.

This module provides a helper function:

  • optimal_worker_count(): Computes the optimal number of worker processes to use for parallel tasks, based on workload size and available CPU cores.

It ensures at least one worker is used, avoids oversubscription, and supports both iterable and integer inputs for task sizing.

Intended for internal use in MKTable computation and other parallel workflows.

pymkm.utils.parallel.optimal_worker_count(workload) int[source]

Determine the optimal number of worker processes based on workload size and CPU availability.

If the workload size is smaller than the number of CPU cores, the number of workers is set equal to the workload size. Otherwise, one core is reserved to avoid oversubscription.

Parameters:

workload (iterable or int) – The total number of tasks to process. Can be an iterable or an integer.

Returns:

Optimal number of worker processes (always at least 1).

Return type:

int