Was python script mpirun or mpiexec running?

I have encoded a python script that can be run either standalone or with mpi support.

python myscript.py 

vs

 mpirun -np 2 python myscript.py 

How to find out inside the script how the script was run to perform some conditional operations?

+4
source share
2 answers

Do you care if it is launched using MPI or is it running on the same MPI rating? For compiled MPI code, starting only the program will still run in MPI, but with only one rank; and therefore you are probably just initializing MPI and checking the size of MPI_COMM_WORLD . Perhaps you are trying to avoid initializing MPI (or even having to have an MPI implementation) if you are working without MPI. If so, you will probably need to check for specific environment variables that are apparently implementation dependent. For an open MPI list, see http://www.open-mpi.org/faq/?category=running#mpi-environmental-variables . For MPICH, various sources mention PMI_RANK and PMI_SIZE as commonly installed; Microsoft MPI documents that it installs them. They may be specific to specific versions or configurations of MPICH. There is a list of variables that can be checked at http://www.roguewave.com/portals/0/products/threadspotter/docs/2012.1/linux/manual_html/apas03.html , which can also be useful.

+2
source

If you are working on Unix, you can analyze the output:

 import os print os.popen("ps -p %d -oargs=" % os.getpid()).read().strip() 

play with getpid() and getppid() (for the parent). For a portable solution, you need external libraries such as psutil :

 import psutil, os p = psutil.Process(os.getppid()) print p.name 
+2
source

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


All Articles