Learn R Programming

riemtan (version 0.2.5)

should_parallelize: Decide Whether to Use Parallel Processing

Description

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)

Value

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

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.

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.

See Also

set_parallel_plan(), is_parallel_enabled()

Examples

Run this code
if (FALSE) {
# 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)
}

Run the code above in your browser using DataLab