[R-SIG-Mac] Snow package on bi-proc G5
Simon Urbanek
simon.urbanek at r-project.org
Wed Jun 15 20:36:23 CEST 2005
Naji,
On Jun 15, 2005, at 12:36 PM, Naji wrote:
> I'm running complex simulations and I'd like to distribute half the
> simulation on each processor (one G5 machine)
> The R code looks like
>
> For (rep in 1:replications) # 300 replications
> {
> # the simulations results are stored in an array
> Is it possible to distribute the simulations on both proc..?
Yes.
I use pvm as back-end for snow, but I guess others should work, too.
Example (very simple and stupid but should illustrate the idea):
> library(snow)
Loading required package: rpvm
> cl<-makeCluster(2) # use 2 CPUs
> clusterApplyLB(cl,1:6,function(x) mean(x+rnorm(10)))
[[1]]
[1] 0.836866
[[2]]
[1] 1.755120
[[3]]
[1] 3.385007
[[4]]
[1] 3.751311
[[5]]
[1] 4.805047
[[6]]
[1] 5.89379
When running simulations you may want to set the seed differently for
each process [something like clusterApply(cl, 1:2, set.seed)] or use
one of the RNG libraries, otherwise both CPUs will give you the same
results - probably not what you want ;).
Cheers,
Simon
More information about the R-SIG-Mac
mailing list