powered by
Create shard descriptors for parallel execution with autotuning.
Produces shard descriptors (index ranges) for use with shard_map(). Supports autotuning based on worker count and memory constraints.
shard_map()
shards( n, block_size = "auto", workers = NULL, strategy = c("contiguous", "strided"), min_shards_per_worker = 4L, max_shards_per_worker = 64L, scratch_bytes_per_item = 0, scratch_budget = 0 )
A shard_descriptor object containing:
shard_descriptor
n: Total items
n
block_size: Computed block size
block_size
strategy: Strategy used
strategy
shards: List of shard descriptors with id, start, end, idx fields
shards
id
start
end
idx
Integer. Total number of items to shard.
Block size specification. Can be:
"auto" (default): Autotune based on worker count
"auto"
Integer: Explicit number of items per shard
Character: Human-readable like "1K", "10K"
"1K"
"10K"
Integer. Number of workers for autotuning (default: pool size or detectCores - 1).
Sharding strategy: "contiguous" (default) or "strided".
"contiguous"
"strided"
Integer. Minimum shards per worker for load balancing (default 4).
Integer. Maximum shards per worker to limit overhead (default 64).
Numeric. Expected scratch memory per item for memory budgeting.
Character or numeric. Total scratch memory budget (e.g., "1GB").
blocks <- shards(1e6, workers = 8) length(blocks$shards) blocks <- shards(1000, block_size = 100) blocks$shards[[1]]$idx
Run the code above in your browser using DataLab