Parallel processing in R limited

后端 未结 3 916
一向
一向 2020-12-09 21:05

I\'m running ubuntu 12.04 and R 2.15.1 with the parallel and doParallel packages. when I run anything in parallel I\'m limited to 100% of a core, when I should have up to 80

3条回答
  •  既然无缘
    2020-12-09 21:43

    My guess is that you probably had the wrong code. I would like to post one example copied from online http://www.r-bloggers.com/parallel-r-loops-for-windows-and-linux/ :

    library(doMC)
    registerDoMC()
    x<- iris[which(iris[,5]!='setosa'),c(1,5)]
    trials<- 10000
    r<- foreach(icount(trials), .combine=cbind) %dopar% {
        ind<- sample(100,100,replace=T)
        result1<- glm(x[ind,2]~x[ind,1],family=binomial(logit))
        coefficients(result1)
    }
    

    and you can define how many cores you want to use in the parallel:

    options(cores=4)
    

提交回复
热议问题