简体   繁体   English

R并行 - 连接到远程核心

[英]R Parallel - connecting to remote cores

Working in R 2.14.1, on Windows 7 在Windows 7上使用R 2.14.1

Using the package parallel in R, I'm trying to take advantage of cores outside of my local machine available on my network, where all remote hosts I am connecting to are identical Windows machines. 使用R中的并行程序包,我正在尝试利用我的网络上可用的本地计算机之外的核心,我连接的所有远程主机都是相同的Windows计算机。

The basic form of the commands are as such to make the connection. 命令的基本形式就是建立连接。

library(parallel)
#assume 8 cores per machine
cl<-makePSOCKcluster(c(rep("localhost", 8), rep("otherhost", 8)))

Of course, trying to debug these things can be pretty tricky, but here is where I'm at with it. 当然,试图调试这些东西可能会非常棘手,但这就是我所处的位置。

If I specify the manual = TRUE flag as below 如果我指定manual = TRUE标志如下

cl<-makePSOCKcluster(c(rep("localhost", 8), rep("otherhost", 8)), manual=TRUE)

there are no problems connecting to the remote host, and running a parallel process. 连接到远程主机并运行并行进程没有问题。 The computers have identical setups to the one that I am working on. 计算机与我正在使用的计算机具有相同的设置。 Yet, when this manual flag is not set, the connection command hangs. 但是,如果未设置此手动标志,则连接命令将挂起。

This seems to indicate to me that since the manual flag bypasses ssh to make the connection to the host, that ssh is the problem when manual=FALSE. 这似乎向我表明,由于手动标志绕过ssh以建立与主机的连接,因此当手动= FALSE时,ssh是问题。

It is not guaranteed at the moment that the remote computers have ssh on them. 目前无法保证远程计算机上有ssh。 The question is, given that I have all the pertinent windows login information for my remote hosts, and that I cannot change the settings on the remote computers, how would I connect to cores on remote machines with the package parallel in R without specifying manual = true? 问题是,鉴于我拥有远程主机的所有相关Windows登录信息,并且我无法更改远程计算机上的设置,如何在没有指定manual =的情况下将包并行连接到远程计算机上的核心?真正?

Alternatively, if ssh must be installed for this to happen, let's assume all computers have ssh on them. 或者,如果必须安装ssh才能实现此目的,让我们假设所有计算机都有ssh。 How would I connect to cores on the remote machines without circumventing ssh? 如何在绕过ssh的情况下连接到远程计算机上的核心?

If you need any more information please let me know, I appreciate the time. 如果您需要更多信息,请告诉我,我很感激时间。

UPDATE 1 更新1

8-26-14 14年8月26日

Thanks to Steve Weston for his insights. 感谢Steve Weston的见解。 I will provide an update with the exact tools and setup I use to get my system working when it's up and running. 我将提供一个更新,其中包含我使用的确切工具和设置,以便在系统启动并运行时使其正常工作。

Feel free to comment or post if you have anything else to add as to what may be the best route to go in remote connecting to a windows machine from a windows machine via makePSOCKcluster, where the manual flag is set to FALSE. 如果您还有其他任何可以添加的内容,可以通过makePSOCKcluster从Windows机器远程连接到Windows机器的最佳路径,其中手动标志设置为FALSE,请随意发表评论或发布。

When creating a PSOCK cluster with manual=FALSE , the only way to start a worker on a remote machine is with "ssh", "rsh", or something command-line compatible, such as "plink" from PuTTY. 在使用manual=FALSE创建PSOCK群集时,在远程计算机上启动worker的唯一方法是使用“ssh”,“rsh”或命令行兼容,例如PuTTY中的“plink”。 The reason is that makePSOCKcluster starts the remote workers using the "system" function to execute commands of the form: 原因是makePSOCKcluster使用“系统”函数启动远程工作程序来执行以下形式的命令:

ssh -l user otherhost '/usr/lib/R/bin/Rscript' -e 'parallel:::.slaveRSOCK()' MASTER=myhost PORT=10187 OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE

You can confirm this by looking at the source code for the newPSOCKnode function in the file snowSOCK.R from the parallel package. 您可以通过查看并行程序包中snowSOCK.R文件中newPSOCKnode函数的源代码来确认这一点。

For this to work, the ssh-compatible command must be available on the local machine and a corresponding ssh daemon must be running on each of the remote machines, otherwise makePSOCKcluster will simply hang. 为此,ssh-compatible命令必须在本地计算机上可用,并且必须在每台远程计算机上运行相应的ssh守护程序,否则makePSOCKcluster将挂起。 I've found that installing a good, working ssh daemon is the difficult part on Windows. 我发现在Windows上安装一个好的,工作正常的ssh守护进程是困难的部分。

Unfortunately, manual=TRUE is generally the easiest way to create a PSOCK cluster on multiple Windows machines. 不幸的是, manual=TRUE通常是在多台Windows机器上创建PSOCK群集的最简单方法。

Helle everyone, I had the same problem and I managed to solve it. 帮助大家,我有同样的问题,我设法解决它。 It is June 2018 when I'm writing this answer, my OS is windows 10 and the R version is 3.2.2. 2018年6月,当我写这个答案时,我的操作系统是Windows 10,R版本是3.2.2。 It is surprising to see this problem still exists after 4 years. 令人惊讶的是,这个问题在4年后仍然存在。 I hope it can be fixed in the following release. 我希望它可以在以下版本中修复。

Before you move on, please make sure you can access the server in cmd using ssh. 在继续之前,请确保您可以使用ssh访问cmd中的服务器。 I didn't put any password in my code because I have the private key, you don't need to do that and you will see the reason later. 我没有在我的代码中输入任何密码,因为我有私钥,你不需要这样做,你会在以后看到原因。

Fixing The problem 解决问题

  1. File directory 文件目录

Since the function makePSOCKcluster works when manually start the workers, my first trying is to let manual=TRUE, and see what's the output. 由于函数makePSOCKcluster在手动启动worker时起作用,我的第一个尝试是让manual = TRUE,看看是什么输出。 Here is my result: 这是我的结果:

machineAddresses <-list(list(host='192.168.1.220',user='jeff'))
cl <- makePSOCKcluster(spec,manual = F)
> Manually start worker on 192.168.1.220 with
     "C:/PROGRA~1/R/R-32~1.2/bin/x64/Rscript" -e 
"parallel:::.slaveRSOCK()" MASTER=DESKTOP-U5JA32O PORT=11756 
OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE 

Ok, Here is the first problem. 好的,这是第一个问题。 The Rscript location is incorrect(The location of Rscript in the server). Rscript位置不正确(服务器中Rscript的位置)。 Generally, it locates in C:\\Program Files. 通常,它位于C:\\ Program Files中。 In my server is C:\\Program Files\\R\\R-3.2.2\\bin. 在我的服务器是C:\\ Program Files \\ R \\ R-3.2.2 \\ bin。 So we need to correct them by adding more option to tell this stupid code where the Rscript is: 所以我们需要通过添加更多选项来纠正它们,以告诉这个愚蠢的代码,其中Rscript是:

machineAddresses <-list(list(host='192.168.1.220',
user='jeff',rscript="C:/Program Files/R/R-3.3.2/bin/Rscript"))
  1. CMD problem CMD问题

Once you fix the directory problem, you will find that the code still hangs forever. 修复目录问题后,您会发现代码仍然永远挂起。 Then we need to check if we can manually access the server in R, my code is: 然后我们需要检查是否可以手动访问R中的服务器,我的代码是:

system("ssh jeff@192.168.1.220")
> GetConsoleMode on STD_INPUT_HANDLE failed with 6

I honestly don't know what does this error mean, but we just need to fix that. 老实说,我不知道这个错误意味着什么,但我们只需要解决这个问题。 Inspired by @Steve Weston, I decide to use PuTTY, so I install it, and change my code to: 在@Steve Weston的启发下,我决定使用PuTTY,所以我安装它,并将我的代码更改为:

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"))

The option -pw means the password. 选项-pw表示密码。 Because I'm a newbie to PuTTY, I don't know how to let the private key automatically work in PuTTY. 因为我是PuTTY的新手,我不知道如何让私钥在PuTTY中自动运行。 Therefore, I use the easiest way to deal with that: put your password! 因此,我用最简单的方法来处理:输入你的密码! The above code is equivalent to the following in cmd: 上面的代码相当于cmd中的以下代码:

plink -pw qwer jeff@192.168.1.220 Rscript -e parallel:::.slaveRSOCK() MASTER=DESKTOP-U5JA32O PORT=11063 OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE

And this is exactly what we will do if we manually create the workers. 如果我们手动创建工作人员,这正是我们要做的。 For those who are new like me, you need to add the PuTTY directory in PATH in your environmental variables to run plink. 对于像我这样的新手,你需要在环境变量的PATH中添加PuTTY目录来运行plink。 Here are my final codes: 这是我的最终代码:

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)

I run it with no problem at all. 我毫无问题地运行它。 In summary, the function makePSOCKcluster makes two mistakes: 总之,函数makePSOCKcluster犯了两个错误:

  1. Assuming a wrong R directory in the server(At least it should assume the same directory as my local computer, but it didn't! I don't know where that strange directory comes from) 假设服务器中有一个错误的R目录(至少它应该假设与我的本地计算机相同的目录,但它没有!我不知道那个奇怪的目录来自哪里)

  2. Using ssh command to start the connection, which does not work in R. It works well in cmd, but not in R. I don't know the reason. 使用ssh命令启动连接,这在R中不起作用。它在cmd中运行良好,但在R中不运行。我不知道原因。

If you are still not able to use makePSOCKcluster, here is one trick: Try to connect to the server in R using system function first. 如果您仍然无法使用makePSOCKcluster,这里有一个技巧:尝试首先使用系统函数连接到R中的服务器。 It can give you some error code, that may instruct you where the problem is. 它可以为您提供一些错误代码,可以指示您问题所在。 Here is my debugging code: 这是我的调试代码:

system("plink -pw qwer jeff@192.168.1.220 Rscript -e parallel:::.slaveRSOCK() MASTER=DESKTOP-U5JA32O PORT=11063 OUT=/dev/null TIMEOUT=2592000 METHODS=TRUE XDR=TRUE")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM