Short version of the question here,
I run an exceutable (which in turn runs a simulation) from a batch file. I can run up to four of these at once. Is there any method for checking (from the batch file) how many of these executables are running at a time?
Long version,
I have a batch file which allows me to run multiple models but dues to licencing I cannot run more than 4 models simultaneously. I can however queue them up to be run, however i am struggling to write a batch file which ensures that there are always four models running at all times. My best effort (cobbled together from searching the internet) is below
FOR %%a in (%A%) do (
FOR %%b in (%B%) DO (
FOR %%c in (%C%) DO (
FOR %%d in (%D%) DO (
SET /A COUNT+=1
SET /A Result =!COUNT!%%4
:: set Result to the remainder of the Count divided by 4
if !Result! == 0 (
start "TUFLOW" /wait C:\Tuflow\TuflowExe\Build_2011_09_AF_64\TUFLOW_iSP_w64.exe -e1 %%a -s1 %%b -s2 %%c -s3 %%d C:\Tuflow\Model\Ohoka\runs\OH.tcf
) else (
start "TUFLOW" C:\Tuflow\TuflowExe\Build_2011_09_AF_64\TUFLOW_iSP_w64.exe -e1 %%a -s1 %%b -s2 %%c -s3 %%d C:\Tuflow\Model\Ohoka\runs\OH.tcf
)
)
)
)
)
Where A, B, C and D are arrays containing variable combinations that are passed to the executable. I then have a count which records the iterations, on every fourth iteration the "True" condition for the if statement is triggered and the batch waits until the model run is completed before continuing.
This is ok, but my other three models may finish earlier, freeing up valuable cpu time that is not utilised because the batch is waiting for the fourth iteration to complete. Or worse, the fourth iteration completes prior to the other three and ends up trying to run more than four models which causes a licensing pop up which requires a user to dismiss.
Any suggestions or other solutions that I am bound to have missed?