[Rd] parApply vs parCapply

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Mar 17 19:51:41 CET 2012


On 17/03/2012 17:03, Ken Knoblauch wrote:
> 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?

Maybe: I would have expected so, and AFAICS ?parCapply does not say what 
the value is so it is unspecified.  We probably should document it.

> 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.
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list