Run TUFLOW From a Batch-file: Difference between revisions

Content deleted Content added
No edit summary
Line 380:
endlocal
</pre>
===Coordinating Asynchronous Simulations===
This batch file will set off asynchronous runs on separate threads, and then wait for all runs to finish before moving to the next process. This example kicks off 8 tuflow.exe processes and then waits before collating (in fortran) and processing the results (in python).
 
<pre>
@echo off
 
:: Set local
setlocal
:: User defined variables – will need to be changed
set "for_infile=inputs_fortran.inp"
set "run_exe=tuflow.exe"
set "file_prefix=C:\temp\test"
set "sum_exe=combine_thread_outputs.exe"
set "n_threads=8"
set "pyt_code=Post_process.py"
set "pyt_infile=inputs_python.inp"
 
:: Random lock file
set "lock=%temp%\wait%random%.lock"
 
:: Launch processes asynchronously, with stream 9 redirected to a lock file.
:: The lock file will remain locked until the individual exe instance ends.
:: %%a is sent to %run_exe% as an argument to set the thread to use
for /L %%a in (0,1,7) do (
start "" 9>"%lock%%%a" %run_exe% %for_infile% %%a
)
 
:: Wait for the processes to finish
:Waitrun
1>nul 2>nul ping /n %n_threads% ::1
for /L %%N in (0,1,7) do (
(call ) 9>"%lock%%%N" || goto :Waitrun
) 2>nul
 
:: Delete the lock files
del "%lock%*"
 
:: Collate thread outputs
%sum_exe% %file_prefix% %n_threads%
 
:: Make image
python %pyt_code% %pyt_infile%
 
:: Finish up
echo Done.
</pre>
===Shutdown on Completion===
Often we may have a number of TUFLOW simulations going when we leave work on a Friday afternoon, if these are not going to take all weekend to run, using some of the batch file logic above you can create a batch file that will shutdown the computer when no TUFLOW simulations are running. An example batch file for this purpose is below:<br>