[R-sig-hpc] getting multiple results back from foreach using MPI
Maas James Dr (MED)
J.Maas at uea.ac.uk
Mon Jan 17 15:29:06 CET 2011
I'm relatively new to this. I have a toy script (listed below) that runs on a SGE cluster using doMPI. When I ask for the results ("stuff"), all I'm getting is the final variable calculated ("bsiaicORSD") as shown here. I need the function to return both "bsiaicOR" and "bsiaic". What do I need to do to get foreach to give me both back? I've tried using a "return" statement within the foreach loop but got a "multi argument returns are not permitted" error message.
Thanks
J
> stuff
[[1]]
[,1] [,2] [,3]
[1,] 0.00000000 0.05813405 0.03851296
[2,] 0.09045419 0.00000000 0.06218322
[3,] 0.11871065 0.12007783 0.00000000
[[2]]
[,1] [,2] [,3]
[1,] 0.00000000 0.05813405 0.03851296
[2,] 0.09045419 0.00000000 0.06218322
[3,] 0.11871065 0.12007783 0.00000000
[[3]]
[,1] [,2] [,3]
[1,] 0.00000000 0.05813405 0.03851296
[2,] 0.09045419 0.00000000 0.06218322
[3,] 0.11871065 0.12007783 0.00000000
======================================================
library(doMPI)
cl <- startMPIcluster()
registerDoMPI(cl)
results.overall <- array (dim = c(0,6))
bsiaic <- read.table(file="extern.bsiaic.dat",header=TRUE)
bsiaictritot <- nrow(bsiaic)
bsiaictreatnum=max(bsiaic[,4])
bsiaic.data <- list(Ntrials =bsiaictritot,ntreat=bsiaictreatnum,
treat0=bsiaic[,3],treat1=bsiaic[,4],
total.patientnums.trt1=bsiaic[ ,2],
total.patientnums.trt2=bsiaic[ ,2],
num.countstrt1=bsiaic[ ,5],
num.countstrt2=bsiaic[ ,6])
bsiaic.inits <- list( list (tau.eta=1, tau.theta=1,
thetamean0=0, eta.mean=c(rep(0,bsiaictreatnum))))
stuff <- foreach (i=1:3, .packages="rjags") %dopar% {
bsiaicjags <- jags.model("aicmodel.txt", data=bsiaic.data, inits=bsiaic.inits,
n.chain=1, n.adapt=1000 )
results <- jags.samples(bsiaicjags, variable.names =c("logOR", "OR",
"eta.mean", "tau.eta","tau.theta"), n.iter=1000)
bsiaicOR <- apply(results$OR, c(1,2), mean)
bsiaicORSD <- apply(results$OR, c(1,2), sd)
}
stuff
closeCluster(cl)
mpi.quit()
rm(list=ls())
===============================
Dr. Jim Maas
University of East Anglia
More information about the R-sig-hpc
mailing list