How to find the number of cores available for MPI (4PY)?
Motivation
My Python program runs MPI instances hierarchically.
The first appearance always occurs and creates 4 instances. It makes no sense to increase this number due to the structure of my calculations, so I hard-coded it.
Depending on the command line parameters of the main program, each of the 4 instances invokes external Python software that scales almost linearly.
I call this external software using
N=3
child=MPI.COMM_SELF.Spawn(sys.executable,args=[`external.py`],maxprocs=N)
At the moment I use N=3
, so that in 4 copies of the first caviar 3 copies of the external program appear each time, which gives a total of 12 copies, comparing the number of cores on my workstation.
However, for portability, I would like to do
N_avail = <MPI.N_CORES> #on my workstation: N_avail=12
N = N_avail/MPI.COMM_WORLD.Get_size() #on my workstation: N=12/4=3
.
, ?
, maxprocs , mpirun
out -np
, . , Spawn
maxprocs=1
.
, ( ) 4 N_avail
.
multiprocessing.cpu_count()
, node ( ). SLURM.