I have sets of simulations that each uses MPI to run in parallel (they are CFD simulations). However, I would like to create a pool of tasks in Python and run that in parallel. I used the multiprocessing library as follows:
import itertools
import multiprocessing
def Run_Cases(params):
run_each_mpi_simulation
a = range(1,len(U)); b = range(len(R))
paramlist = list(itertools.product(a,b))
pool = multiprocessing.Pool()
pool.map(Run_Case,paramlist)
so basically, the code creates the pool of tasks (simulation instances) and assign them to each processors to run. However, it does not take into account that each simulation requires lets say 2 processors as each case is a parallel (MPI) simulation. This result in significant performance drop in the simulations.
Hereby, I was wondering if it is possible to somehow define the number of processors that get assigned to each task in Python multiprocessing package?
Any comments is highly appreciated.
Kind regards Ashkan
EDIT/UPDATE:
Thank you so much @AntiMatterDynamite for your answer.
I tried your approach and the performance and work load distribution on the processors improved a lot but it seems there are 2 issues:
1) I get the following message although everything continues
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 1073, in run
self.function(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Execution/FoamThread.py", line 86, in getLinuxMem
me=psutil.Process(thrd.threadPid)
File "/usr/local/lib/python2.7/dist-packages/psutil/__init__.py", line 341, in __init__
self._init(pid)
File "/usr/local/lib/python2.7/dist-packages/psutil/__init__.py", line 381, in _init
raise NoSuchProcess(pid, None, msg)
NoSuchProcess: psutil.NoSuchProcess no process found with pid 8880
I would highly appreciate your comments.
Many thanks again Ashkan
EDIT/UPDATE:
I believe the message was because the number of processes were less than the list of processors. As I had two cases/simulations with each using 2 processors, when I was using hyper-threading I had 8 processors so getting the message. It was resolved using 4 processors or having larger pool of simulations.