views:

908

answers:

2

I know I must be making a simple syntax mistake, but I want to have a windows batch file that fires up 9 instances of R and runs a different routine in each one. I want these to run simultaneously (i.e. asynchronously). I can fire up 9 command prompt windows and type a command in each one, but it seems like with the START command I should be able to make them start from a single batch file.

Here's an example of how I start one of the instances of R:

"C:\Program Files (x86)\R\R-2.8.1\bin\R" CMD BATCH "C:\Users\jd\Documents\mexico\Estado\getdata1.r"

Reading this previous stackoverflow question along with this previous question makes me think I should be able to do this:

START "" "C:\Program Files (x86)\R\R-2.8.1\bin\R" CMD BATCH "C:\Users\jd\Documents\mexico\Estado\getdata1.r" /b

That does not return an error, it just returns a prompt and R never starts. What am I missing?

+2  A: 

I would do two things differently:

  1. Use R itself to dispatch nine different jobs; the snow package is very good at this even when do not use MPI / PVM / NWS for distributed work. Some examples for snow use are for example in my 'introduction to high performance computing with R' tutorials linked from this page. With snow, you get 'parallel' versions of the apply functions that you can run over multiple instances of R running on the local computer (or of course a network of computers if have one). The r-sig-hpc list is helpful for more detailed questions.

  2. Switch to using Rscript.exe instead of using 'R CMD BATCH'. On Linux / OS X you also get a choice of using littler

That said, I run almost all my jobs on Linux so there may be a Windows-specific answer here too that I just do not know. But the above is generic and stays in the platform-agnostic spirit of R.

Dirk Eddelbuettel
OK that makes really good sense. I need to break down and spend a day wrapping my feeble brain around snow and MPI. Parallel process is certainly the future, but I've been slow to get ramped up.
JD Long
And the nice thing is that you do can experiment with snow using just network sockets on the local machine before jumping to MPI.That said, nine jobs on a single machine may exhaust your memory anyway.
Dirk Eddelbuettel
A: 

Simple answer. On windows when running command use "Rcmd" not "R CMD". There is a separate exe for running the commands. Look in the bin folder of your R installation.

Andrew Redd
but snow is certainly the more sophisticated way to parallelize a job.
Andrew Redd
yes, snow is more sophisticated... and with that sophistication comes a lot of overhead
JD Long