library(partools)

cls <- makeCluster(2)
setclsinfo(cls)

cls <- makeCluster(2)
setclsinfo(cls)
clusterEvalQ(cls,library(randomForest))
# https://archive.ics.uci.edu/ml/datasets/covertype
cvr <- read.csv(file="/Users/robinyancey/desktop/covtype.data",sep=',',header=F)
cvr <- cvr[,c(1:10,55)]
cvr$V55 <- as.numeric(cvr$V55 == 1)
testidxs <- sample(1:nrow(cvr),10000)
cvrtest <- as.matrix(cvr[testidxs,1:10])

clusterExport(cls,'cvrtest')
cvrtrain <- cvr[-testidxs,]
distribsplit(cls,'cvrtrain',scramble=T)

print(system.time(clusterEvalQ(cls,logitout <- glm(V55 ~ ., data=cvrtrain,family=binomial))))
print(system.time(logitout <- glm(V55 ~ .,data=cvrtrain,family=binomial)))

yprob <- predict(logitout,cvrtest,type='response')
dyprob <- clusterEvalQ(cls,predict(logitout,cvrtest,type='response'))
dyprob <- Reduce('+',dyprob) / 2
z <- round(yprob)
dz <- round(dyprob)
print(mean(z == cvrtest$V55))
print(mean(dz == cvrtest$V55)) 