`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, 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.

Examples

#> Initialising default cluster of size 2
# Run code on each cluster and retrieve results cluster_call(cl, Sys.getpid())
#> [[1]] #> [1] 25855 #> #> [[2]] #> [1] 25861 #>
cluster_call(cl, runif(1))
#> [[1]] #> [1] 0.07490883 #> #> [[2]] #> [1] 0.5574378 #>
# use ptype to simplify cluster_call(cl, runif(1), ptype = double())
#> [1] 0.9782521 0.8542038
# use cluster_send() to ignore results cluster_send(cl, x <- runif(1)) cluster_call(cl, x, ptype = double())
#> [1] 0.5579230 0.9696646