Skip to content
Prev 86460 / 398513 Next

Turning control back over to the terminal

Hi Ross --

Not a direct answer to your question, but here's an idea.

I guess you've got some script in a file batch.sh

#! /bin/bash
R --no-save --no-restore --gui=none > `hostname`  2>&1 <<BYE
# some mpi commands
# other mpi commands
BYE

and you do something like

mpiexec -np 10 batch.sh

Instead, you might create a file script.R

script.R
--------

library("Rmpi")
mpi.spawn.Rslaves(nslaves=10)

variousCmds <- function() {
  ## some mpi commands
  if( mpi.comm.rank() == 0 && interactive()) {
    while( (res <- readline( prompt=" > ")) != "DONE" ) {
      try(cat(eval(parse(text=res)), "\n"))
      ## or other, e.g., browser()
    }
  }
  ## other mpi commands
}

mpi.bcast.Robj2slave( variousCmds )
mpi.bcast.cmd( variousCmds())
variousCmds()

mpi.close.Rslaves()

Then just run R and

source("script.R")

to debug, and

R --vanilla < script.R

to run. This assumes that the 'some' and 'other' mpi commands include
communication of results between nodes, so that you don't have to rely
on the the return value of variousCmds to harvest the results. This
could be great fun, because you can edit the script file (in emacs,
for e.g.) and rerun without exiting R.

http://ace.acadiau.ca/math/ACMMaC/Rmpi/index.html provided some
inspiration for this, thanks!

Martin

Ross Boylan <ross at biostat.ucsf.edu> writes: