我希望能够将我的Mac连接到我的EC2实例,以便使用parallel
或makePSOCKcluster
通过makeSOCKCluster
包在AWS上执行并行处理。
此刻我的尝试让R'悬挂',所以我调整了makePSOCKcluster
及其一些子程序,以便通过添加-v
选项可以看到它的一些输出到了ssh。我想我已经成功处理了无密码的ssh登录,但是我被困在socketConnection
部分,我认为这会导致问题。
我尝试将弹性IP关联起来并将其用作IP地址无效,还尝试调整安全组,使其包含makePSOCKcluster使用的默认端口无效......在后一种情况下,我没有使用ports参数,并使用了10187的默认端口选项:
Error in socketConnection("localhost", port = port, server = TRUE, blocking = TRUE, :
cannot open the connection
In addition: Warning message:
In socketConnection("localhost", port = port, server = TRUE, blocking = TRUE, :
port 10187 cannot be opened
查看几个hpc邮件列表问题,这似乎是与Windows相关的问题......但鉴于我从Mac连接,我不认为我属于这一类。
hosts
对象只是启动EC2实例后提供的公共DNS。
以下是我目前尝试将makePSOCKcluster
函数中的某些功能调整为makePSOCKcluster1
它们应该大致相同。
我已指定rscript
参数以匹配ubuntu实例上预期的参数,并且我已指定ubuntu
作为登录用户名,如同在ubuntu EC2实例上一样。
makePSOCKcluster1 <- function (names, ...) {
if (is.numeric(names))
names <- rep("localhost", names[1])
options <- parallel:::addClusterOptions(parallel:::defaultClusterOptions, list(...))
cl <- vector("list", length(names))
for (i in seq_along(cl)) cl[[i]] <- newPSOCKnode1(names[[i]],
options = options, rank = i)
class(cl) <- c("SOCKcluster", "cluster")
cl
}
newPSOCKnode1 <- function (machine = "localhost", ..., options = parallel:::defaultClusterOptions,
rank)
{
options <- options
if (is.list(machine)) {
options <- options
machine <- machine$host
}
outfile <- parallel:::getClusterOption("outfile", options)
master <- if (machine == "localhost")
"localhost"
else parallel:::getClusterOption("master", options)
port <- parallel:::getClusterOption("port", options)
manual <- parallel:::getClusterOption("manual", options)
timeout <- parallel:::getClusterOption("timeout", options)
methods <- parallel:::getClusterOption("methods", options)
useXDR <- parallel:::getClusterOption("useXDR", options)
env <- paste("MASTER=", master, " PORT=", port, " OUT=",
outfile, " TIMEOUT=", timeout, " METHODS=", methods,
" XDR=", useXDR, sep = "")
arg <- "parallel:::.slaveRSOCK()"
rscript <- if (parallel:::getClusterOption("homogeneous", options)) {
shQuote(parallel:::getClusterOption("rscript", options))
}
else "Rscript"
cmd <- paste(rscript, "-e", shQuote(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")
flush.console()
}
else {
if (machine != "localhost") {
rshcmd <- parallel:::getClusterOption("rshcmd", options)
user <- parallel:::getClusterOption("user", options)
cmd <- shQuote(cmd)
cmd <- paste(rshcmd, "-v -l", user, machine, cmd)
print(cmd)
}
if (.Platform$OS.type == "windows") {
system(cmd, wait = FALSE, input = "")
}
else system(cmd, wait = FALSE)
}
print("ssh done!!! about to start socketConnection....")
con <- socketConnection("localhost", port = port, server = TRUE,
blocking = TRUE, open = "a+b", timeout = timeout)
print("socketConnection complete!!!")
structure(list(con = con, host = machine, rank = rank), class = if (useXDR)
"SOCKnode"
else "SOCK0node")
}
hosts <- c("ec2-xxx-xx-xxx-xxxx.zone.compute.amazonaws.com","ec2-xx-xxx-xxx-xxx.zone.compute.amazonaws.com")
# the code to try and connect to the actual EC2 instance...
cl1 <- makePSOCKcluster1(hosts, user="ubuntu", rscript="/usr/lib/R/bin/Rscript", port=8787)
[1] "ssh -v -l ubuntu ec2-xxxxxxxxxxx.zone.compute.amazonaws.com \"'/usr/lib/R/bin/Rscript' -e 'parallel:::.slaveRSOCK()' MASTER=local.machine.name PORT=8787 OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE\""
[1] "ssh done!!! about to start socketConnection...."
OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to ec2-xxxxxxxxxxx.zone.compute.amazonaws.com [xx.xxx.xx.x.x] port 22.
debug1: Connection established.
debug1: identity file /Users/username/.ssh/identity type -1
debug1: identity file /Users/username/.ssh/id_rsa type 1
debug1: identity file /Users/username/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
Warning: Permanently added 'ec2-xx-xx-xxx-xxx-xx.ap-southeast-1.compute.amazonaws.com,xx.xxx.xxx.xx.x' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/username/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending command: '/usr/lib/R/bin/Rscript' -e 'parallel:::.slaveRSOCK()' MASTER=local.machine.name PORT=8787 OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Transferred: sent 2352, received 2400 bytes, in 20.0 seconds
Bytes per second: sent 117.5, received 119.9
debug1: Exit status 1
我在OS X 10.6.8上使用Mac连接到Debian Ubunutu实例。如果有更好的方法连接到EC2实例以执行并行处理,人们知道这也是非常有用的。
最终目标是在群集注册后使用foreach
执行此处理。
另外作为一个侧面问题我想知道,与使用MPI并行执行流程相关的速度/处理优缺点是什么?还是其他一些方法?
提前致谢!
编辑如果从单独的EC2实例开始,我已设法让makePSOCKcluster
工作,并且parLapply
函数有效,我甚至可以使用{{注册1}}其中registerDoParallel(cl1)
是群集对象,但出于某种原因cl1
... foreach
不起作用...给出错误:
%dopar%
或
Error in serialize(data, node$con) : error writing to connection
使用以下输出查看Error in unserialize(node$con) : error reading from connection
时连接似乎正常:
showConnections()
其中> showConnections()
description class mode text isopen can read can write
3 "<-ip-xx-xxxx-x-xxx.zone.compute.internal:10187" "sockconn" "a+b" "binary" "opened" "yes" "yes"
4 "<-ip-yy-yyyy-y-yyyy.zone.compute.internal:10187" "sockconn" "a+b" "binary" "opened" "yes" "yes"
5 "<-ip-zz-zzzz-z-zzzz.zone.compute.internal:10187" "sockconn" "a+b" "binary" "opened" "yes" "yes"
>
,x
&amp; y
表示不同的IP地址.... z
示例直接排除了foreach
的帮助文件中提供的示例以及foreach
/ {的一些示例来自clusterCall
包的{1}} / clusterExport
个函数也不起作用...给出与以前类似的错误消息....
我仍然希望能够从Mac连接...但仍然希望能够使用foreach进行并行处理...希望额外的信息有帮助