我使用 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 进程)以查看是否有帮助,但没有效果。有什么建议么?