`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, 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
cl <- default_cluster()
#> Initialising default cluster of size 2
# Run code on each cluster and retrieve results
cluster_call(cl, Sys.getpid())
#> [[1]]
#> [1] 11493
#>
#> [[2]]
#> [1] 11499
#>
cluster_call(cl, runif(1))
#> [[1]]
#> [1] 0.1755167
#>
#> [[2]]
#> [1] 0.1745636
#>
# use ptype to simplify
cluster_call(cl, runif(1), ptype = double())
#> [1] 0.524041 0.253362
# use cluster_send() to ignore results
cluster_send(cl, x <- runif(1))
cluster_call(cl, x, ptype = double())
#> [1] 0.3277737 0.4468006