Hi all,

I have been working on parallelizing a bootstrap procedure using 'snow' R
package. The aim is to bootstrap a bayesian algorithm (e.g. grow-shrink
algorithm, available through 'bnlearn' R package). However, I could not get
parallelization to work the way it should.

Ideally I expected the time required by a regular (no parallelization) code
to be more than that of the code parallelized using the snow package
functions, but the results were vice versa.

Below is the parallelized code and the results observed. The data was a
protein expression data of 11 genes and 853 time points. Any help or
suggestions will be highly appreciated. I would be glad to provide any more
information required.

rm(list = ls(all = TRUE))
library(snow)
library(bnlearn)
library(rlecuyer)

#Create a cluster of 2 on the localhost using sockets
cl <- makeCluster(c("localhost","localhost"), type = "SOCK")

#Load bnlearn on the cluster
clusterEvalQ(cl, library(bnlearn))

Myfile <- "/home/shweta/r-snow/dat_schs1.txt"

clusterSetupRNG(cl)

y <<- read.table(Myfile, header=TRUE, as.is=FALSE)
nboot <<- 10000
confi <<- 0.9
#Function to send to the different cores/processes
#Run this first

d <<- dim(y)
bmat  <<- array(0,c(d[2],d[2]))
DoBootstrap<-function(y,nboot)
{
    for (i in 1:nboot)
    {
        r <- sample(d[1], replace = TRUE)
        xboot <- y[r,]
        net <<- gs(xboot, cluster = cl, whitelist = NULL, blacklist =
NULL,test = 'cor', alpha = 0.05, debug = FALSE, optimized = TRUE, strict =
FALSE, direction = FALSE)
        tmp <- amat(net)
        bmat <<- bmat + tmp
        rm(tmp)
        rm(r)
        rm(net)
    }
return(bmat)
}

timing_results <- system.time(bmat <- DoBootstrap(y,nboot))
print(bmat)
bmat <- (bmat/nboot)
bmat <<- floor(bmat/confi)
finalmat <- floor(bmat)
print (finalmat)
stopCluster(cl)
print(timing_results)

Results:

--
parallelized code - 1 cluster 100 runs
user  system elapsed
10.476   0.630  54.115

regular 100 runs
user  system elapsed
24.975   0.011  25.696

--
parallelized code - 1 cluster 500 runs
user  system elapsed
52.369   3.275 276.548

regular 500 runs
user  system elapsed
128.314   0.197 133.001

----
parallelized code - 1 cluster 1000 runs
user  system elapsed
103.782   6.427 547.730

regular 1000 runs
user  system elapsed
237.738   0.002 237.884

~Shweta

	[[alternative HTML version deleted]]

