[Rd] How to use mpi.allreduce() in Rmpi?

From: Eduardo García <edugarpor_at_gmail.com>
Date: Mon, 12 Jul 2010 21:42:07 +0200

Hi everybody!

I have the next code which makes a reduction of the *a *variable in two slaves, using the Rmpi package.

library(Rmpi)

#get the slaves

mpi.spawn.Rslaves(nslaves=2)

#slaves will execute this function

reduc<-function(){
  a<-mpi.comm.rank()+2
  mpi.reduce(a,type=2, op="prod")
  return(paste("a=",a))
}

#send function

mpi.bcast.Robj2slave(reduc)

#execute function by slaves

mpi.remote.exec(reduc())

#get reduction

cat("Product: ")
mpi.reduce(1,op="prod")

mpi.close.Rslaves()

I want to use the function mpi.allreduce() instead of mpi.reduce(), so slaves should receive the value of the reduction. I don't know how to do it and the avaliable documentation is very small and i'm starting with Rmpi. I also tried with the next two changes but nothing:

library(Rmpi)

mpi.spawn.Rslaves(nslaves=2)

reduc<-function(){
  a<-mpi.comm.rank()+2
  mpi.reduce(a,type=2, op="prod")
  return(paste("a=",a))
}

mpi.bcast.Robj2slave(reduc)
mpi.remote.exec(reduc())

cat("Product: ")
mpi.allreduce(1,op="prod")

mpi.close.Rslaves()

and

library(Rmpi)

mpi.spawn.Rslaves(nslaves=2)

reduc<-function(){
  a<-mpi.comm.rank()+2
  mpi.allreduce(a,type=2, op="prod")
  return(paste("a=",a))
}

mpi.bcast.Robj2slave(reduc)
mpi.remote.exec(reduc())

cat("Product: ")
mpi.allreduce(1,op="prod")

mpi.close.Rslaves()

Could somebody help me?

Thanks a lot in advance for your help !* *

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 12 Jul 2010 - 19:44:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 12 Jul 2010 - 21:00:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive