【发布时间】:2014-06-11 17:49:39
【问题描述】:
我使用 parLapply 在 4 核计算机上成功处理了一些数据,使用如下代码:
require("parallel")
setwd("C:/...")
file_summary<-read.table("file_summary",header=T,sep=" ",stringsAsFactors=F)
new_filename<-sub(".asc",".dat",file_summary$filename)
file_list<-list.files()
myfunction <- function(k) {
x<-M$x[k]
y<-M$y[k]
for (i in 1:length(file_summary[,1])) {
if ( # logical condition on x and y ) {
new_file<-new_filename[i]
new_data<-read.table(new_file,header=T,sep=" ")
eval<-matrix(,nrow=length(new_data$x),ncol=1)
for (j in 1:length(new_data$x)) {
eval[j]<-(new_data$x[j]-x)^2+(new_data$y[j]-y)^2
}
index<-which(eval == max(eval))
out<-c(new_data$x[index],new_data$y[index],new_data$mean[index],new_data$S[index])
}
rm(eval)
gc()
}
return(out)
}
n_tasks <- length(M$x)
n_cores <- 8
Cl = makeCluster(n_cores, type = "PSOCK")
clusterExport(Cl, "M")
clusterExport(Cl, "file_summary")
clusterExport(Cl, "new_filename")
clusterExport(Cl, "file_list")
Results <- parLapply(Cl, c(1:n_tasks), myfunction)
stopCluster(Cl)
现在使用完全相同的代码以及相同的数据和目录结构(即路径),我试图在 8 核机器上运行分析以进一步加快速度。但是,在我第一次尝试时,我收到以下错误:
8 nodes produced errors; first error: cannot open the connection
我尝试稍微清除一下 RAM(对于非 R 进程),看看它是否有帮助,但没有。有什么建议吗?
【问题讨论】:
-
愚蠢的问题,但是你的机器有 8 个内核吗?
-
嗯,我正在连接到远程计算机来执行此操作,通过检查设备管理器它显示 8... 负责人不久前还告诉我有 8 个内核。不过,我可能想再次与他们核实。
标签: r parallel-processing core