Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't the plyr package use my parallel backend?

I'm trying to use the parallel package in R for parallel operations rather than doSNOW since it's built-in and ostensibly the way the R Project wants things to go. I'm doing something wrong that I can't pin down though. Take for example this:

a <- rnorm(50)
b <- rnorm(50)

arr <- matrix(cbind(a,b),nrow=50)

aaply(arr,.margin=1,function(x){x[1]+x[2]},.parallel=F)

This works just fine, producing the sums of my two columns. But if I try to bring in the parallel package:

library(parallel)
nodes <- detectCores()
cl <- makeCluster(nodes)
setDefaultCluster(cl)

aaply(arr,.margin=1,function(x){x[1]+x[2]},.parallel=T)

It throws the error

2: In setup_parallel() : No parallel backend registered
3: executing %dopar% sequentially: no parallel backend registered 

Am I initializing the backend wrong?

like image 396
Patrick McCarthy Avatar asked Mar 26 '13 16:03

Patrick McCarthy


1 Answers

Try this setup:

library(doParallel)
library(plyr)

nodes <- detectCores()
cl <- makeCluster(nodes)
registerDoParallel(cl)

aaply(ozone, 1, mean,.parallel=TRUE)

stopCluster(cl)

Since I have never used plyr for parallel computing I have no idea why this issues warnings. The result is correct anyway.

like image 179
Roland Avatar answered Nov 05 '22 20:11

Roland