I have a script in R that takes advantage of the doParallel package and the parallelized foreach function. I am currently registering my cluster by using a variation of the detectCores() command, which works quite well as the machine I am using has 32 cores.
My question is, if I have access to HPC resources with multiple Linux machines, is it possible to detectCores() from multiple machines and implement them in a single foreach call?
For example, if I submit my HPC job so that it uses two nodes, is it possible to get the detectCores() function to produce a value of 64 rather than 32?
Example summarizing solution in the comments of the top post:
library("parallel")
find_workers <- function(nodes) {
nodes <- unique(nodes)
cl <- makeCluster(nodes)
on.exit(stopCluster(cl))
ns <- clusterCall(cl, fun = detectCores)
rep(nodes, times = ns)
}
workers <- find_workers(c("n1", "n2", "n3"))
cl <- makeCluster(workers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With