是否可以在并行模式下运行 biglm?我尝试使用 doMC,然后将 biglm 嵌入到 foreach 循环中,但似乎所有内核都将同时处理相同的数据块。我如何并行化这个?
library(doMC)
RegisterDoMC(4)
require(ffbase)
sample <- read.table.ffdf(file="sample_output.csv", FUN = "read.csv", na.strings = "")
library(biglm)
model<-list()
biglmupdate<-function(dataset,start,end) {
if (start==1) {
model <<- biglm(a~b+c, data=dataset[start:end,])
}
else {
model <<- update(model,dataset[start:end,])
}
}
chunks <- floor(dim(sample)[1]/220000)+1
start<-0; end<-0;
foreach (i = 1: chunks) %dopar% {
start = end +1; end =ifelse (i == chunks, dim(sample)[1], start+220000);
print(paste("chunk ",i," ",start,":",end," started at:", Sys.time()));
biglmupdate(dataset = sample, start, end);
print(paste("chunk ",i,"ended at:", Sys.time()));
}