Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Was the python script launched by mpirun or mpiexec?

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?

like image 582
Jorge Avatar asked May 17 '13 15:05

Jorge


People also ask

What is the difference between Mpirun and Mpiexec?

Mpiexec is a replacement program for the script mpirun, which is part of the mpich package. It is used to initialize a parallel job from within a PBS batch or interactive environment. Mpiexec uses the task manager library of PBS to spawn copies of the executable on the nodes in a PBS allocation.

How do I run an MPI program in Python?

Interface options The use of -m mpi4py to execute Python code on the command line resembles that of the Python interpreter. mpiexec -n numprocs python -m mpi4py pyfile [arg] ... mpiexec -n numprocs python -m mpi4py -m mod [arg] ... mpiexec -n numprocs python -m mpi4py -c cmd [arg] ...

How does MPI Python work?

MPI for Python provides Python bindings for the Message Passing Interface (MPI) standard, allowing Python applications to exploit multiple processors on workstations, clusters and supercomputers. This package builds on the MPI specification and provides an object oriented interface resembling the MPI-2 C++ bindings.


2 Answers

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.

like image 93
Jeremiah Willcock Avatar answered Sep 25 '22 15:09

Jeremiah Willcock


If you are on Unix, you can analize the output of:

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 like psutil:

import psutil, os
p = psutil.Process(os.getppid())
print p.name
like image 38
elyase Avatar answered Sep 26 '22 15:09

elyase