[R] Turning control back over to the terminal
Martin Morgan
mtmorgan at fhcrc.org
Tue Feb 14 18:23:58 CET 2006
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:
> I'm invoking R from withing a shell script like this
> R --no-save --no-restore --gui=none > `hostname` 2>&1 <<BYE
> # various commands here
> BYE
>
> I would like to regain control from the invoking terminal at some point.
> I tried source(stdin()) but got a syntax error, presumably stdin is the
> little shell here snippet (the part between <<BYE
> and BYE).
>
> Is there some way to accomplish this? I am trying to regain control
> inside an R session that has been launched inside an MPI environment
> (and I'm usually running inside emacs). This is on a Mac OS X cluster.
>
> I suppose there might be a way to do this with expect, but I'm hoping
> for something simpler. Potentially, I could make the script itself act
> differently on the head node (the only one I want to debug right now),
> including changing the redirection there.
>
>
> --
> Ross Boylan wk: (415) 514-8146
> 185 Berry St #5700 ross at biostat.ucsf.edu
> Dept of Epidemiology and Biostatistics fax: (415) 514-8150
> University of California, San Francisco
> San Francisco, CA 94107-1739 hm: (415) 550-1062
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list