Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parallelize local simulation run #481

Open
ManuelaRunge opened this issue Sep 12, 2020 · 0 comments
Open

parallelize local simulation run #481

ManuelaRunge opened this issue Sep 12, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@ManuelaRunge
Copy link
Collaborator

The code below runs a batch file that loop through simulation in batches of 5 (separate batch files) but breaks if single simulation returns error, also the combine trajectories should only start after all trajectories were generated.
Running the code outside runScenarios works well (except those that break) and is faster as sequential run.

            file = open(os.path.join(trajectories_dir, 'runSimulations_loop.bat'), 'w')
            file.write('ECHO Run simulation number %x% to  %y%' + '\n' +
                       '\nFOR /L %%j IN (%x%,1,%y%) DO ( "{}" -c "{}" -m "{}") >> "{}/log/log_%x%_to_%y%.txt"'.format(
                get_cms_cmd(exe_dir, temp_exp_dir),
                os.path.join(temp_dir, "model_%%j" + ".cfg"),
                os.path.join(temp_dir, "simulation_%%j" + ".emodl"),
                os.path.join(trajectories_dir)
            ) + "\n ECHO end")

            file = open(os.path.join(trajectories_dir, 'runSimulations_parallel.bat'), 'w')
            file.write('@echo off' \
                        '\ncd {dir}\nfor /l %%i in (1,5,{nscen}]) do call :loop %%i' \
                        '\ngoto :eof' \
                        '\n\n:loop \ncall :checkinstances \nif %INSTANCES% LSS 5 (' \
                        '\n    echo Starting processing instance for %1' \
                        '\n    @set x=%1' \
                        '\n    @set step=%1+5' \
                        '\n    @set /a y=%x%+%step%' \
                        '\n    copy runSimulations_loop.bat runSimulations_loop%1.bat' \
                        '\n    start /min runSimulations_loop%1.bat 2 sec' \
                        '\n    goto :eof' \
                        '\n) \necho Waiting for instances to close ...\nping -n 2 ::1 >nul 2>&1\ngoto loop\ngoto :eof' \
                        '\n:checkinstances\nfor /f "usebackq" %%t in (`tasklist /fo csv /fi "imagename eq wait.bat"^|find /c /v ""`) do set INSTANCES=%%t' \
                        '\ngoto :eof' \
                        '\npause'.format(nscen=str(scen_num), dir=trajectories_dir))

(code modified from template on stackoverflow - example code)

@ManuelaRunge ManuelaRunge added the enhancement New feature or request label Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant