0

我正在尝试调整此 R 脚本以在集群上进行速度测试。

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

不过,我很确定我需要将类型更改为"MPI",以使节点彼此进行内存通信。

但是:如果我这样做了,脚本就会停止并出现以下错误代码:

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.

我想“小菜一碟,很简单”并添加了以下几行:

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

这会导致安装成功,但是:

Error in library(Rmpi, lib.loc = "/personalpath") :
there is no package called ‘Rmpi’

1.如何安装这些包?

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

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

所以..这是我的代码:

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

1 回答 1

0

在 R 中还有其他方法可以并行化。正如第二页所解释的,也许这个链接会有所帮助,这些集群类型(如 socket、mpi 和 fork)的作用: https ://stat.ethz.ch/R-manual/R-开发/库/parallel/doc/parallel.pdf

否则我也可以建议查看包foreach,因为语法更像是一个常规的 for 循环。请注意,某些并行化包并非适用于所有操作系统。

于 2019-02-05T12:48:34.080 回答