This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#generates a cluster specification for the "spec" argument of the parallel::makeCluster() function | |
#ips: vector of computer ips within the local network: c('10.42.0.1', '10.42.0.34', '10.42.0.104') | |
#cores: vector of integers with the number of cores available on each computer, in the same order as ips: cores = c(7, 4, 4) | |
#user: character, name of the user in the different computers. Only one user name allowed. | |
#returns a list that can be used directly as input for the "spec" argument of makeCluster(). | |
cluster_spec <- function( | |
ips, | |
cores, | |
user | |
){ | |
#creating initial list | |
spec <- list() | |
for(i in 1:length(ips)){ | |
spec[[i]] <- list() | |
spec[[i]]$host <- ips[i] | |
spec[[i]]$user <- user | |
spec[[i]]$ncore <- cores[i] | |
} | |
#generating nodes from the list of machines | |
spec <- lapply( | |
spec, | |
function(spec.i) rep( | |
list( | |
list( | |
host = spec.i$host, | |
user = spec.i$user) | |
), | |
spec.i$ncore | |
) | |
) | |
#formating into a list of lists | |
spec <- unlist( | |
spec, | |
recursive = FALSE | |
) | |
return(spec) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment