'
'   Copyright Platform Computing Inc., an IBM company, 1997-2008, 2012
'                          All Rights Reserved.
'
Option Explicit
Dim sh, oJob, JobNewOut, appfile, Rsrc
Dim I, fs, appfilename, rankexe, mpioptions, rankopts

' Location of appfile
appfilename = "<path to appfile>"
' Location of executable
rankexe = "<path to executable>"
' Arguments to executable
rankopts = ""
' Arguments to mpirun (ex. -prot -TCP)
mpioptions = ""

Set sh = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set oJob = sh.exec("%MPI_ROOT%\bin\mpi_nodes.exe")
JobNewOut = oJob.StdOut.Readall

Set appfile = fs.CreateTextFile(appfilename, True)

Rsrc = Split(JobNewOut, " ")

For I = LBound(Rsrc) + 1 to UBound(Rsrc) Step 2
    appfile.WriteLine("-h " + Rsrc(I) + " -np " + Rsrc(I + 1) + _
            " """ + rankexe + """ " + rankopts)
 Next

appfile.Close

Set oJob = sh.exec("""%MPI_ROOT%\bin\mpirun.exe"" " + mpioptions + _
            " -f """ + appfilename + """ ")

while Not oJob.StdOut.AtEndOfStream
   WScript.Echo oJob.StdOut.ReadLine
WEnd
 
' No real good way to get stderr out, so just doing this afterwards.  May
' not be accurate, but it will at least give you an indication of
' the problem.
WScript.Echo oJob.StdErr.ReadAll

WScript.Echo "-------------------------------------------------------"
WScript.Echo "                   DONE - ExitCode=" + CStr(oJob.ExitCode)

' unfortunately exit code of mpirun doesn't get put here very
' accurately.
WScript.Quit(oJob.ExitCode)

