Create a cluster of nodes for parallel computation
makeCluster(
numberOfThreads,
singleThreadToMain = TRUE,
setAndromedaTempFolder = TRUE
)
Number of parallel threads.
If numberOfThreads
is 1, should we fall back to running the
process in the main thread?
When TRUE, the andromedaTempFolder option will be copied to each thread.
An object representing the cluster.
fun <- function(x) {
return (x^2)
}
cluster <- makeCluster(numberOfThreads = 3)
clusterApply(cluster, 1:10, fun)
#> | | | 0% | |======= | 10% | |============== | 20% | |===================== | 30% | |============================ | 40% | |=================================== | 50% | |========================================== | 60% | |================================================= | 70% | |======================================================== | 80% | |=============================================================== | 90% | |======================================================================| 100%
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 4
#>
#> [[3]]
#> [1] 9
#>
#> [[4]]
#> [1] 16
#>
#> [[5]]
#> [1] 25
#>
#> [[6]]
#> [1] 36
#>
#> [[7]]
#> [1] 49
#>
#> [[8]]
#> [1] 64
#>
#> [[9]]
#> [1] 81
#>
#> [[10]]
#> [1] 100
#>
stopCluster(cluster)