Last active
August 13, 2020 09:37
-
-
Save pmu2022/89c680ff44561591ef9433ba1702c295 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import multiprocessing as mp | |
| import subprocess | |
| def some_python_calc(*args) | |
| # Do some calculation in python | |
| return 0 | |
| def run_subprogram(): | |
| some_python_calc() | |
| outputfile = "stdout.out" | |
| stderr = "stderr.out" | |
| infile = "input.in" | |
| with open(outputfile, 'w', buffering=1) as f_std, \ | |
| open(stderr, 'w', buffering=1) as f_err, \ | |
| open(infile, 'r') as f_in: | |
| cmd = ['mpirun','-np 2', './anykindorprogram'] | |
| cwd = 'simulationpath' | |
| p = subprocess.Popen(cmd, | |
| cwd=cwd, | |
| stdin=f_in, | |
| stderr=f_err, | |
| stdout=f_std, | |
| ) | |
| p.wait() | |
| if __name__ == '__main__': | |
| number_pool_processes = 8 | |
| jobs = [run_subprogram for i in range(20)] | |
| with mp.Pool(processes=number_pool_processes) as pool: | |
| for job in jobs: | |
| pool.apply_async(job, ()) | |
| pool.close() | |
| pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment