简体   繁体   中英

How to run external program on multiple cpu cores using python?

I am trying to run multiple simulations on an external program, CalculiX, using python. I am aware that the python script can't run on multiple cpu cores but CalculiX is an external program which I am running through the os.system command. I need to run the simulations on multiple cores to save time.

    os.system("ccx WireBend")

This is what I am using to run the external program and it works, it just takes a lot of time as the calculations are done using only one cpu. So how can I run ccx on multiple cores? I am using python 3.6

With subprocess.Popen you can open a subprocess asynchronously (ie control will return to python before the subprocess has finished).

Use it many times to spawn multiple subprocesses and then check if each of the processes has terminated.

You can set the environment variable into the terminal from where you are running your program or set it in the script as Below:

import os
os.environ['OMP_NUM_THREADS']
OR
os.environ['OMP_NUM_THREADS'] = '10'

then run

os.system("ccx WireBend")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM