[R-sig-hpc] suggestion in parallelisation, please.

Rohmatul Fajriyah rfajriyah at yahoo.com
Fri Oct 3 20:24:02 CEST 2014


Dear All,
I am doing simulation in R and using parallel package in it.As some inputs (M1, M2, and M3) get larger then the simulation getting slow.
I really appreciate if anyone wants to give me  suggestion how to make the paralellization better in my program (as below),since I still learn how to do it.
Apologise if this is not an appropriate place to ask some question/suggestion.
Thank you very much in advance.
With kind regards,Rohmatul
===========================================sdata<-function(M3,k,me,sx,sy){    a<-matrix(0,ncol=M3,nrow=2*k)    for (i in 1: M3)    {      a[,i]<-rbind(rnorm(k,mean=me,sd=sx),rnorm(k,mean=me,sd=sy))    }    return(a)  }Xt<-sdata(10000,25,0,1)X<-as.list(data.frame(Xt))f1<-function(x,M1,M2,n){  X2<-x[1:n]  Y2<-x[(n+1):(2*n)]  Mx<-mean(X2)  Vx<-var(X2)  My<-mean(Y2)  Vy<-var(Y2)   Rac0=seq(0,0,length=M1)  for (i in 1:M1)  {     Z10=seq(0,0,length=M2)    Z20=seq(0,0,length=M2)    for (j in 1:M2)    {      x0=rnorm(n,mean=Mx,sd=Sx)      y0=rnorm(n,mean=My,sd=Sy)      mx0=mean(x0)      Vx0=var(x0)      my0=mean(y0)      Vy0=var(y0)      Z10[j]= (Vx0/Vx)+(my0-mx0)      Z20[j]= (Vy0/Vy)+(my0-mx0)     }    Z10<-rank(Z10)/M1    Z20<-rank(Z20)/M1    Rmc0<-summary(lm(Z10~Z20))    Rac0[i]<-Rmc0[[8]]  }   cat(Rac0,"\n")}
library(parallel)co<-detectCores()
sink("~/Documents/try0.R",append=TRUE)out<-mclapply(X,FUN=f1,M1=10000,M2=1000,n=25,mc.cores=(co-1))sink()


	[[alternative HTML version deleted]]



More information about the R-sig-hpc mailing list