| Title: | Utility Functions for Future Map-Reduce API Packages |
|---|---|
| Description: | Utility functions for other packages implementing map-reduce APIs on top of the future framework - specifically 'future.apply', 'furrr', and 'doFuture'. This package and its functions are intended for those packages only and should not be used elsewhere. |
| Authors: | Henrik Bengtsson [aut, cre, cph], R Core Team [cph, ctb] |
| Maintainer: | Henrik Bengtsson <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.0.1-9004 |
| Built: | 2026-11-22 01:18:56 UTC |
| Source: | https://github.com/futureverse/future.mapreduce |
Identify Globals and Packages of a Map-Reduce Function Call
get_globals_and_packages_xapply( fun, fun_name = as.character(substitute(fun)), args = NULL, args_name = "...", globals = TRUE, packages = NULL, envir = parent.frame() )get_globals_and_packages_xapply( fun, fun_name = as.character(substitute(fun)), args = NULL, args_name = "...", globals = TRUE, packages = NULL, envir = parent.frame() )
fun |
A function that takes one or more arguments. |
fun_name |
The name of the argument that |
args |
(optional) A list of arguments passed to |
args_name |
If |
globals |
(optional) a logical, a character vector, a named list, or a Globals object. If TRUE, globals are identified by code inspection based on |
packages |
(optional) a character vector specifying packages to be attached in the R environment evaluating the future. |
envir |
The environment from where globals should be searched. |
A names list with elements:
globals - a FutureGlobals object
packages - a character vector of package names
This is an internal function.
make_chunks(nelements, nworkers, scheduling = 1, chunk_size = NULL)make_chunks(nelements, nworkers, scheduling = 1, chunk_size = NULL)
nelements |
(integer) Total number of elements to iterate over. |
nworkers |
(integer) Number of workers available. |
scheduling |
(numeric) A strictly positive scalar.
Only used if argument |
chunk_size |
(numeric) The maximum number of elements per
chunk, or |
A list of chunks, where each chunk is an integer vector of
unique indices in [1, nelements]. The union of all chunks
holds nelements elements and equals 1:nelements.
If nelements == 0, then an empty list is returned.
Attribute ordering of chunk_size or scheduling can
be used to control the ordering the elements are iterated over, which
only affects the processing order not the order values are returned.
This attribute can take the following values:
index vector - an numeric vector of length nelements specifying
how elements are remapped
function - an function taking one argument which is called as
ordering(nelements) and which must return an
index vector of length nelements, e.g.
function(n) rev(seq_len(n)) for reverse ordering.
"random" - this will randomize the ordering via random index
vector sample.int(nelements).
Produce Reproducible Seeds for Parallel Random Number Generation
make_rng_seeds(count, seed = FALSE)make_rng_seeds(count, seed = FALSE)
count |
The number of RNG seeds to produce. |
seed |
A logical specifying whether RNG seeds should be generated
or not. ( |
This function generates count independent
L'Ecuyer-CMRG random seeds that can be used as
.Random.seed for parallel processing. These seeds are produced with
help of parallel::nextRNGSubStream() and
parallel::nextRNGStream() using a strategy that
seed <- <initial RNG seed>
for (ii in seq_len(count)) {
seeds[[ii]] <- parallel::nextRNGSubStream(seed)
seed <- parallel::nextRNGStream(seed)
}
This function forwards the RNG state 1 + count times if seed = TRUE.
Returns a non-named list of count independent
L'Ecuyer-CMRG random seeds.
If seed is NULL or FALSE, then NULL is returned.
## Set up L'Ecuyer-CMRG random seeds for 100 parallel tasks ## based on .Random.seed in the current R process seeds <- make_rng_seeds(100L, seed = TRUE) str(seeds)## Set up L'Ecuyer-CMRG random seeds for 100 parallel tasks ## based on .Random.seed in the current R process seeds <- make_rng_seeds(100L, seed = TRUE) str(seeds)