三天来,我一直在尝试使用多台计算机构建一个集群,但失败得非常厉害。所以现在我要试着说服你们帮我解决我的问题如果一切顺利,我希望我们可以生成一个分步指南,作为将来做这件事的参考,因为到目前为止,我还没有找到一个合适的参考来设置这个(也许这是一个太具体的任务?)
在我的例子中,假设Windows7,PuTTY作为SSH客户端,'localhost‘将作为主服务器。
此外,我们现在假设同一网络上只有两台计算机。我想这个过程会很简单,如果我能让它在两台计算机上工作,我就能让它在三台计算机上工作。因此,我们将在localhost
和remote-computer
上工作。
这是我到目前为止收集到的(参考链接在底部)
在remote-computer
localhost
.
remote-computer
localhost
remote-computer
localhost
和remote-computer
localhost
中的R代码
代码:
library(parallel)
cl <- makePSOCKcluster(c(rep("localhost", 2),
rep("remote-computer", 2)))
到目前为止,我已经完成了步骤1-3,不确定是否需要做4,完成5-7,步骤8的代码不确定地挂起。
当我检查我的SSH服务器日志时,似乎没有从localhost
访问SSH服务器。因此,我的第一个问题似乎是正确配置SSH。有没有人成功地做到了这一点,你愿意分享你的专业知识吗?
编辑对象:引用http://www.milanor.net/blog/wp-content/uploads/2013/10/03.FirstStepinParallelComputing.pdf
R Parallel - connecting to remote cores
https://stat.ethz.ch/pipermail/r-sig-hpc/2010-October/000780.html
发布于 2015-09-24 01:27:49
充其量,这是一个部分的答案。我仍然没有建立集群,但这里描述的步骤很好地记录了我是如何做到这一点的。
配置:
在‘远程计算机’上的'remote-computer'
路径
测试连接:阶段I
C:\PuTTYPath\plink.exe -pw [password] [username]@[remote_ip_address] Rscript -e rnorm(100)
(确认返回100个正态随机变量
C:\PuTTYPath\plink.exe -pw [password] [username]@[remoate_ip_address] RScript -e parallel:::.slaveRSOCK() MASTER=[local_ip_address] PORT=100501 OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE
(确认SSH服务器上的会话已启动,登录在‘远程计算机’上)
测试连接:阶段II
从R会话中运行
system(paste0("C:/PuTTYPath/plink.exe -pw [password] ", "[username]@[remote_ip_address] ", "RScript -e rnorm(100)"))
(确认返回100个正常的随机variates)
system(paste0("C:/PuTTY/plink.exe ", "-pw [password] ", "[username]@[remote_ip_address] ", "RScript -e parallel:::.slaveRSOCK() ", "MASTER=[local_ip_address] ", "PORT=100501 ", "OUT=/dev/null ", "TIMEOUT=2592000 ", "METHODS=TRUE ", "XDR=TRUE"))
(确认在‘远程计算机’上的SSH服务器日志上启动并维护了一个会话
建立集群
从R会话中运行
library(snow)
cl <- makeCluster(spec = c("localhost", "[remote_ip_address]"), rshcmd = "C:/PuTTY/plink.exe -pw [password]", host = "[local_ip_address]")
(会话应在“远程计算机”上的SSH服务器日志上启动和维护。理想情况下,函数将在赋值'cl‘时完成)
建立集群是我失败的地方。我运行makeCluster
并查看我的SSH服务器日志。它显示连接已建立,然后立即关闭。makeCluster
永远不会结束运行,cl
没有被分配,我被困在如何继续运行。在这一点上,我甚至不确定这是R问题还是配置问题。
编辑和解决方案:
无缘无故,我尝试使用snow
包运行此程序,如上面的“建立集群”部分所示。当我使用snow
包时,集群已经构建好了,并且运行稳定。不知道为什么我不能让它与parallel
包一起工作,但至少我有一些功能上的东西。
发布于 2018-06-09 04:05:19
对于那些正在寻找在Windows中的几台计算机上建立群集的人,@Benjamin的答案几乎是正确的,您需要遵循他的说明,直到最后一步,即建立一个群集,并确保前面的步骤都在您的计算机上工作。我的解决方案是基于“Parallel”包而不是“snow”包,它们本质上是相同的。
解决方案
代码模板:
machineAddresses <-list(list(host='[Server address]',user='[user name]',rscript="[The Rscript file in the server]",rshcmd="plink -pw [Your password]"))
cl <- makePSOCKcluster(machineAddresses,manual = F)
你必须在你的代码中填充所有的[]。在我的电脑中,它是:
machineAddresses <-list(list(host='192.168.1.220',user='jeff',rscript="C:/Program Files/R/R-3.3.2/bin/Rscript",rshcmd="plink -pw qwer"))
cl <- makePSOCKcluster(machineAddresses,manual = F)
原因
在Windows下运行集群是非常棘手的,函数makePSOCKcluster通常不能像预期的那样工作。使其正常工作的最简单方法是将manual=F更改为manual=T并手动创建工作器。这里有一个相关的帖子,它讨论了为什么函数makePSOCKcluster将永远挂起,我认为这两个帖子基本上卡在同一个地方。我还发布了我对这个问题的答案,以讨论如何使其工作。
发布于 2018-06-27 06:42:00
因为我没有资格对Jeff的回答发表评论,所以我会把这个作为一个回答来发表:
我发现使用makePSOCKcluster自动启动集群节点在Windows中不起作用,原因是内部parallel
函数newPSOCKnode
中的arg
和outfile
参数被包装在shQuotes
函数中。这会导致cmd.exe和Rscript.exe的组合返回错误,从而导致makePSOCKcluster
永远挂起。
以下两个函数定义支持使用makePSOCKcluter
自动启动群集节点,前提是为基于密钥的无密码登录正确配置了ssh
或putty
/plink
:
makePSOCKcluster <- function (names, ...)
{
if (is.numeric(names)) {
names <- as.integer(names[1L])
if (is.na(names) || names < 1L)
stop("numeric 'names' must be >= 1")
names <- rep("localhost", names)
}
parallel:::.check_ncores(length(names))
options <- parallel:::addClusterOptions(parallel:::defaultClusterOptions, list(...))
cl <- vector("list", length(names))
for (i in seq_along(cl)) cl[[i]] <- newPSOCKnode(names[[i]],
options = options, rank = i)
class(cl) <- c("SOCKcluster", "cluster")
cl
}
newPSOCKnode <- function (machine = "localhost", ..., options = parallel:::defaultClusterOptions,
rank)
{
options <- parallel:::addClusterOptions(options, list(...))
if (is.list(machine)) {
options <- parallel:::addClusterOptions(options, machine)
machine <- machine$host
}
outfile <- parallel:::getClusterOption("outfile", options)
master <- if (machine == "localhost")
"localhost"
else parallel:::getClusterOption("master", options)
port <- parallel:::getClusterOption("port", options)
setup_timeout <- parallel:::getClusterOption("setup_timeout", options)
manual <- parallel:::getClusterOption("manual", options)
timeout <- parallel:::getClusterOption("timeout", options)
methods <- parallel:::getClusterOption("methods", options)
useXDR <- parallel:::getClusterOption("useXDR", options)
env <- paste0("MASTER=", master, " PORT=", port, " OUT=",
#shQuote(outfile), " SETUPTIMEOUT=", setup_timeout, " TIMEOUT=",
(outfile), " SETUPTIMEOUT=", setup_timeout, " TIMEOUT=",
timeout, " XDR=", useXDR)
arg <- "parallel:::.slaveRSOCK()"
rscript <- if (parallel:::getClusterOption("homogeneous", options)) {
shQuote(parallel:::getClusterOption("rscript", options))
}
else "Rscript"
rscript_args <- parallel:::getClusterOption("rscript_args", options)
if (methods)
rscript_args <- c("--default-packages=datasets,utils,grDevices,graphics,stats,methods",
rscript_args)
cmd <- if (length(rscript_args))
paste(rscript, paste(rscript_args, collapse = " "), "-e",
#shQuote(arg), env)
arg, env)
#else paste(rscript, "-e", shQuote(arg), env)
else paste(rscript, "-e", arg, env)
renice <- parallel:::getClusterOption("renice", options)
if (!is.na(renice) && renice)
cmd <- sprintf("nice +%d %s", as.integer(renice), cmd)
if (manual) {
cat("Manually start worker on", machine, "with\n ",
cmd, "\n")
utils::flush.console()
}
else {
if (machine != "localhost") {
rshcmd <- parallel:::getClusterOption("rshcmd", options)
user <- parallel:::getClusterOption("user", options)
cmd <- shQuote(cmd)
cmd <- paste(rshcmd, "-l", user, machine, cmd)
}
if (.Platform$OS.type == "windows") {
system(cmd, wait = FALSE, input = "")
}
else system(cmd, wait = FALSE)
}
con <- socketConnection("localhost", port = port, server = TRUE,
blocking = TRUE, open = "a+b", timeout = timeout)
structure(list(con = con, host = machine, rank = rank), class = if (useXDR)
"SOCKnode"
else "SOCK0node")
}
我计划在有机会的时候用更完整的设置说明来更新这个响应。
https://stackoverflow.com/questions/32571996
复制相似问题