首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用sfInit和makeCluster类型的"MPI“/消息传递在集群上的R/并行化中

如何使用sfInit和makeCluster类型的"MPI“/消息传递在集群上的R/并行化中
EN

Stack Overflow用户
提问于 2018-08-11 05:40:18
回答 1查看 336关注 0票数 0

我正在尝试使这个用于速度测试的R脚本适应集群的工作。

当使用带有类型sfInitmakecluster函数的"SOCK"时,脚本成功地在集群上运行,但是没有任何速度的提高--不像在我的计算机上:当我将detectcores()更改为1时,脚本运行速度要比4个内核慢得多。

不过,我非常肯定需要将类型更改为"MPI",以使节点以内存的方式相互通信。

但是:如果我这样做了,那么脚本将停止使用以下错误代码:

代码语言:javascript
复制
Loading required package: Rmpi
Error: package or namespace load failed for ‘Rmpi’:
 .onLoad failed in loadNamespace() for 'Rmpi', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/cluster/sfw/R/3.5.1-gcc73-base/lib64/R/library/Rmpi/libs/Rmpi.so':
  libmpi.so.20: cannot open shared object file: No such file or directory
Failed to load required library: Rmpi for parallel mode MPI
Fallback to sequential execution
snowfall 1.84-6.1 initialized: sequential execution, one CPU.

我认为“小菜一碟,容易”,并增加了以下几行:

代码语言:javascript
复制
install.packages('Rmpi', repos = "http://cran.us.r-project.org",
dependencies = TRUE, lib = '/personalpath') install.packages('doMPI',
repos = "http://cran.us.r-project.org", dependencies = TRUE, lib = '/personalpath') library(topicmodels, lib.loc = '/personalpath')
library(Rmpi, lib.loc = '/personalpath')

这导致安装成功,但:

代码语言:javascript
复制
Error in library(Rmpi, lib.loc = "/personalpath") :
there is no package called ‘Rmpi’

1.如何安装这些软件包?

2.我真的需要安装它们吗?还是这是一个完全错误的方法?

任何帮助都是非常感谢的!我知道这里有几个问题(参见)。但我不熟悉Linux中的调用,更重要的是,我对集群没有任何权限。所以我需要在R中想出一个解决方案。

所以..。这是我的密码:

代码语言:javascript
复制
sfInit(parallel=TRUE, cpus=detectCores(), type="MPI")

cl <- makeCluster(detectCores(), type = "MPI")
registerDoSNOW(cl) 

sfExport('dtm_stripped', 'control_LDA_Gibbs')
sfLibrary(topicmodels)

clusterEvalQ(cl, library(topicmodels))
clusterExport(cl, c("dtm_stripped", "control_LDA_Gibbs"))

BASE <- system.time(best.model.BASE <<- lapply(seq, function(d){LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', d)}))
PLYR_S <- system.time(best.model.PLYR_S <<- llply(seq, function(d){LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', d)}, .progress = "text"))

wrapper <- function (d) topicmodels:::LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', d)
PARLAP <- system.time(best.model.PARLAP <<- parLapply(cl, seq, wrapper))
DOPAR <- system.time(best.model.DOPAR <<- foreach(i = seq, .export = c("dtm_stripped", "control_LDA_Gibbs"), .packages = "topicmodels", .verbose = TRUE) %dopar% (LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', k=i)))
SFLAPP <- system.time(best.model.SFLAPP <<- sfLapply(seq, function(d){topicmodels:::LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', d)})) 
SFCLU <- system.time(best.model.SFCLU <<- sfClusterApplyLB(seq, function(d){topicmodels:::LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', d)})) 
PLYRP <- system.time(best.model.PLYRP <<- llply(seq, function(d){topicmodels:::LDA(dtm_stripped, control = control_LDA_Gibbs, method ='Gibbs', d)}, .parallel = TRUE))

results_speedtest <- rbind(BASE, PLYR_S, PARLAP, DOPAR, SFLAPP, SFCLU, PLYRP)
print(results_speedtest)
EN

回答 1

Stack Overflow用户

发布于 2019-02-05 12:48:34

在R中还有其他并行化方法,也许正如第二页所解释的那样,这个链接有助于实现这些集群类型,比如socket、mpi和fork:https://stat.ethz.ch/R-manual/R-devel/library/parallel/doc/parallel.pdf

否则,我也可以重新评论包foreach,因为语法更像是一个普通的for-循环。请注意,有些并行化包并不适用于所有操作系统。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51796825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档