5

我希望能够将我的 Mac 连接到我的 EC2 实例,以通过使用或的parallel包在 AWS 上执行并行处理。makePSOCKclustermakeSOCKCluster

目前我的尝试让 R '挂起',所以我已经调整了makePSOCKcluster, 和它的一些子例程,以便通过向-vssh 添加一个选项可以看到它的一些输出。我想我已经设法处理了无密码的 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 相比,并行执行进程的速度/处理优缺点是什么?或其他一些方法?

提前致谢!

编辑makePSOCKcluster如果从一个单独的 EC2 实例开始,我已经设法让它工作,并且该parLapply功能有效,我什至可以使用集群对象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, y&z代表不同的 ip 地址....这些foreach示例直接来自帮助文件中给出的示例,foreach而且包中的一些clusterCall//函数也不起作用...给出类似的错误消息前....clusterExportclusterEvalQparallel

我仍然希望能够从 Mac 连接...但也希望能够使用 foreach 进行并行处理...希望额外的信息有所帮助

4

0 回答 0