Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Cores from Multiple Nodes

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?

like image 312
amelcher Avatar asked May 28 '26 14:05

amelcher


1 Answers

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)
like image 74
HenrikB Avatar answered May 30 '26 04:05

HenrikB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!