我已成功處理使用parLapply一個4芯計算機上的一些數據,使用如下面的碼:無法打開連接錯誤與parLapply
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個內核。不過,我可能想再次與他們覈對。 – Neodyme