Home:ALL Converter>Was the python script launched by mpirun or mpiexec?

Was the python script launched by mpirun or mpiexec?

Ask Time:2013-05-17T23:07:50         Author:Jorge

Json Formatter

I've coded a python script that can be either launched in stand alone way or with mpi support.

python myscript.py

vs

mpirun -np 2 python myscript.py

How can I know inside the script in which way the script was launched to do some conditional operations?

Author:Jorge,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/16612389/was-the-python-script-launched-by-mpirun-or-mpiexec
Jeremiah Willcock :

Do you care whether it was run using MPI or whether it is run on one MPI rank? For compiled MPI code, running just the program will still start it under MPI, but with only one rank; and so you would probably just initialize MPI and check the size of MPI_COMM_WORLD. It could be that you trying to avoid initializing MPI (or even needing to have an MPI implementation available) if you are running without MPI, though. If so, you will probably need to check for particular environment variables, which appear to be implementation-specific. For Open MPI, the list is at http://www.open-mpi.org/faq/?category=running#mpi-environmental-variables. For MPICH, various sources mention PMI_RANK and PMI_SIZE as commonly being set; Microsoft MPI documents that it sets those. They may be specific to particular MPICH versions or configurations. There is a list of variables to check at http://www.roguewave.com/portals/0/products/threadspotter/docs/2012.1/linux/manual_html/apas03.html that might be useful as well.",
2013-05-17T15:38:01
yy