mpi4py: Spawn processes as Python threads for easier debugging
<p>To use mpi4py, the standard approach is to use <code>mpiexec</code> to start a program using multiple MPI processes. For example <code>mpiexec -n 4 python3.5 myprog.py</code>.</p>

<p>Now, that makes debugging difficult, because one can not straight-forwardly use the Python interpreter plus maybe an IDE debugger using the Python interpreter. However, it is no problem to debug a multi-threaded application.</p>

<p>So my idea would be: <strong>Instead of using mpiexec to spwan the processes, I have a Python script that will spwan several threads, each of them will act as an MPI process, all happening within the Python interpreter.</strong> So the use of <code>mpiexec</code> woud not be necessary and I could debug my application like any other multi-threaded Python program. Would that be possible, and how?</p>

<p>(In general, I'd be very happy to find some good example collections or tutorials for mpi4py, there's not very much available.)</p>

<p>You do not need to implement any hardcore idea. <code>mpiexec</code> is already spawning process for you. Assuming your using the pudb Python debugger you could do the following:</p>

<p><code>mpiexec -np 4 xterm -e python2.7 -m pudb.run helloword.py</code></p>

<p>The <code>-e</code> option of <code>xterm</code> is specifying which program <code>xterm</code> is going to execute.</p>

<p>PS: I have not test it with Python 3.5 but a similar solution will work</p>

python multithreading mpi mpi4py