[R-SIG-Mac] Re : Snow package on bi-proc G5

Naji nassar at noos.fr
Thu Jun 16 01:39:39 CEST 2005


Simon,


Thanks for your quick reply.
Is the following efficient? Comments are welcome

Replicate.vect=1:replications
Results=assay(0,dim=c(replications,design.fact1,dsign.fact2..))
For (ifact1 in 1:design.fact1){
    for (ifact2 in 1:design.fact2){
        # Put the experiment conditions as global parameter
        clusterApplyLB(cl,replicate.vect,SimulateIt)
    }
}

SimulateIt=function(irepl){
Set.seed(1000+irep,kind="Super-Duper")
# simulations given the global variables
results[irepl,ifact1,ifact2,..]=....
}

By the way, thanks for your kiwi pages

Best regards
Naji

Le 15/06/05 20:36, « Simon Urbanek » <simon.urbanek at r-project.org> a écrit :

> 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