cluster_call: Call a function on each node of a cluster

View source: R/cluster-call.R

cluster_callR Documentation

Call a function on each node of a cluster

Description

'cluster_call()' executes the code on each worker and returns the results; 'cluster_send()' executes the code ignoring the result. Jobs are submitted to workers in parallel, and then we wait until they're complete.

Usage

cluster_call(cluster, code, simplify = FALSE, ptype = NULL)

cluster_send(cluster, code)

Arguments

cluster

A cluster.

code

An expression to execute on each worker.

simplify

Should the results be simplified from a list? * 'TRUE': simplify or die trying. * 'NA': simplify if possible. * 'FALSE': never try to simplify, always leaving as a list.

'code' must return a vector of length one in order for simplification to succeed.

ptype

If 'simplify' is 'TRUE', use 'ptype' to enforce the desired output type.

Value

A list of results with one element for each worker in 'cluster'.

Examples

cl <- default_cluster()

# Run code on each cluster and retrieve results
cluster_call(cl, Sys.getpid())
cluster_call(cl, runif(1))

# use ptype to simplify
cluster_call(cl, runif(1), simplify = TRUE)

# use cluster_send() to ignore results
cluster_send(cl, x <- runif(1))
cluster_call(cl, x, simplify = TRUE)

multidplyr documentation built on Sept. 27, 2022, 1:06 a.m.