make_chunks: Divide number of tasks into chunks

View source: R/miscellaneous_functions.R

make_chunksR Documentation

Divide number of tasks into chunks

Description

Create a list that contains chunks of indices (that reference tasks by position) of either

  • a specified number of chunks n_chunks, useful, e.g., if we have a fixed number of processing units, or

  • a specified number of tasks per chunk chunk_size, useful, e.g., if we have a (upper) fixed number of elements than can be processed at a time.

The

Usage

make_chunks(nx, n_chunks, chunk_size = 1000L)

Arguments

nx

An integer value. Number of tasks.

n_chunks

An integer value or missing. The number of chunks.

chunk_size

An integer value or missing. The number of tasks per chunk.

Value

A list of integer vectors (chunks) that contain indices of all nx tasks; either, the number of chunks is <= n_chunks, or the number of tasks/indices per chunk is <= chunk_size.

See Also

splitIndices

Examples

nx <- 16

## Create list of indices by number of chunks,
(ids <- make_chunks(nx, n_chunks = 3))
print(length(ids))

## Create list of indices by size per chunk,
(ids <- make_chunks(nx, chunk_size = 5))
print(lengths(ids))

DrylandEcology/rSW2utils documentation built on Dec. 9, 2023, 10:44 p.m.