[Rd] parApply vs parCapply

Ken Knoblauch ken.knoblauch at inserm.fr
Sat Mar 17 18:03:07 CET 2012


I've started to use the parallel package and it works very well speeding
things up.  Thank you for making this easy to do.

Should I have expected that parCapply would return a vector
when parApply returns a matrix?

library(parallel)

x <- matrix(rnorm(8), nc = 2)
apply(x, 2, function(y) y)

            [,1]       [,2]
[1,] -0.9649685 0.91339851
[2,] -1.4313140 0.13457671
[3,]  1.0499248 1.58967879
[4,] -1.8974411 0.03639876

cl <- makeCluster(getOption("cl.cores", detectCores()))
parApply(cl, x, 2, function(y) y)

            [,1]       [,2]
[1,] -0.9649685 0.91339851
[2,] -1.4313140 0.13457671
[3,]  1.0499248 1.58967879
[4,] -1.8974411 0.03639876

parCapply(cl, x, function(y) y)

[1] -0.96496852 -1.43131396  1.04992479 -1.89744113  0.91339851  0.13457671
[7]  1.58967879  0.03639876

stopCluster(cl)

> sessionInfo()
R version 2.15.0 beta (2012-03-15 r58760)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods
[8] base

Thank you.

-- 
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html



More information about the R-devel mailing list