How to find the number of cores available for MPI (4PY)?

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.

+4
1

, : MPI_UNIVERSE_SIZE. . MPI, http://mpi-forum.org/docs/mpi-3.1/mpi31-report/node253.htm#Node253

MPI MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, . .... MPI_COMM_WORLD MPI_UNIVERSE_SIZE, , ....

mpi4py :

from mpi4py import MPI

version= MPI.Get_version()
print "mpi version is ",version

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
print "size is ",size

universe_size=comm.Get_attr(MPI.UNIVERSE_SIZE)
print "universe size is ",universe_size

mpirun OpenMPI, , :

mpirun -np 1 -H localhost,localhost,localhost python main.py

MPI 3, MPI_Info MPI_INFO_ENV . , :

maxprocs MPI .

soft .

mpi4py, :

soft=MPI.INFO_ENV.get("soft")
print soft
maxprocs=MPI.INFO_ENV.get("maxprocs")
print maxprocs
+1

Source: https://habr.com/ru/post/1689189/


All Articles