Skip to contents

Internal function to determine if an operation should use parallel processing based on the number of items to process and current configuration.

Usage

should_parallelize(n, threshold = 10)

Arguments

n

Integer specifying the number of items to process.

threshold

Integer specifying the minimum number of items required for parallel processing to be beneficial (default: 10). Below this threshold, sequential processing is used even if parallelization is enabled.

Value

Logical value: TRUE if parallel processing should be used, FALSE otherwise.

Details

This function returns TRUE only if:

  1. Parallel processing is enabled (via set_parallel_plan())

  2. The number of items n is at least threshold

For small numbers of items, the overhead of parallelization typically outweighs the benefits, so sequential processing is used.

Examples

if (FALSE) { # \dontrun{
# With parallel processing enabled
set_parallel_plan("multisession")
should_parallelize(5)    # FALSE (below threshold)
should_parallelize(20)   # TRUE (above threshold)

# With parallel processing disabled
set_parallel_plan("sequential")
should_parallelize(100)  # FALSE (sequential plan)
} # }