cluster_call: Call a function on each node of a cluster

Description Usage Arguments Value Examples

View source: R/cluster-call.R

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

1
2
3
cluster_call(cluster, code, ptype = list())

cluster_send(cluster, code)

Arguments

cluster

A cluster.

code

An expression to execute on each worker.

ptype

Determines the output type. The default returns a list, which will always succeed. Set to a narrower type to simplify the output.

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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), ptype = double())

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

multidplyr documentation built on Feb. 9, 2021, 1:07 a.m.