A user recently brought to my attention a case where he was using python scripts to invoke C++ codes in an MPI job using SWIG an mpi4py. If you know all those terms, then you're halfway there!
He hadn't been able to get TotalView to work on his code, and it turned out to be a bit tricky, but not too hard.
My first try was to do:
mpirun -tv -np 4 python test2.py
where test2.py was:
========================
from example import *
from mpi4py import MPI
print "rank = ", MPI.COMM_WORLD.Get_rank()
print cube(3)
print cube(42)
print cube(8)
==============================
cube itself was found in example.c:
==============================
#include <stdlib.h>
int cube (int n)
{
return n * n * n;
}
================================
which has a wrapper in example.i:
===========================
%module example
%{
extern int cube( int n );
%}
%include example.c
===========================
which then uses swig to build more python related stuff:
swig -python example.i
and then gets built into stuff you can call from python:
gcc -g -fPIC -c example.c example_wrap.c -I/usr/include/pythonX.X -I/usr/lib/pythonX.x
gcc -g -shared -o _example.so example.o example_wrap.o
Then you can run (one hopes) python test2.py and have it all work correctly. The problem when trying TotalView as above with
mpirun -tv -np 4 python test2.py
was that it seemed to pick up the wrong version of python and thus, to make thing work, I changed this to
mpirun -tv -np 4 /usr/bin/python ./test2.py
which then seemed to pick up something. It wasn't clear where the example.c code was coming in, so I set a breakpoint on 'cube' and that took. Hitting 'Go' and answering the basic questions did get me eventually to break on 'cube'.
Another method is to use
totalview
by itself, and then enter
/usr/bin/python in the New Program window as the target to debug. With this method, you would then go to Arguments, and enter the script test2.py as a command line argument. Finally click on Parallel, and chose
OpenMPI (or your preferred MPI system) and the number of tasks you want to run.
Again, after you start, you want to set a breakpoint in 'cube' unless you have run things before and saved the breakpoint.
Cheers,