@echo off
rem Calculate the number of nodes from the list of nodes required in the diagnostic.
rem The list is available as an environment variable DIAG_NODELIST.
set /A NumNodes = 0
for %%a in (%DIAG_NODELIST%) do (set /A NumNodes += 1)
rem Parse the switch parameter sent by the diagnostic.
rem This is the SwitchName parameter defined in diag.bat.xml: sn01.
rem Each piece of real parameter data starts at string index 6 of the parameter passed to us here.
rem e.g. from -sn01:1000000 we want 1000000.
set sp01=%1
set NumIntervals=%sp01:~6%
rem By default a diagnostic job is set up to run on only one core.
rem We want to execute an MPI cluster run on at least as many cores as there are nodes in the diagnostic run.
rem Modify the job. The job id is available as an environment variable DIAG_RUNSTEP_JOBID.
job modify %DIAG_RUNSTEP_JOBID% /numnodes:%NumNodes%
rem Add the MPI task to the job.
job add %DIAG_RUNSTEP_JOBID% /numnodes:%NumNodes% /requirednodes:%DIAG_NODELIST% /workdir:"\\%CCP_SCHEDULER%\C$\Diag\MPIPiCalculation" "mpiexec.exe" "picalc-cs-mpi.exe" %NumIntervals%
rem The daignostic run will submit the job in the RunStep.
exit /b 0
