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


'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.


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

cluster_send(cluster, code)



A cluster.


An expression to execute on each worker.


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.


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


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


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.