I am working with a large chunk of serial code that I am trying to get part of to run under MPI. Currently my files (Parents with their child files) are as followed below. My main issue is that my file that imports MPI is causing N
processes to spawn from the start.
File1 (Imports->) File2 (Imports->) File3(Where MPI is imported)
What I am trying to do is that most of my serial code stays the same and then to have parts of my code run under MPI. I have something similar to the following
File1.py
import file2
def main():
print "Testing"
function1():
def function1():
function2():
File2.py
import file3
def function2():
answers = function3()
File3.py
def function3():
from mpi4py import MPI
if rank == 1:
...
elif rank == 0:
...
... # Do work with MPI and return stuff to file2.py
What is happening here is that Testing
gets output to the console for every process that File1.py
starts with. I.e. mpiexec -n 2 python file1.py
results in 2 outputs in Testing
when I only expect the print statement to run. However, running the same command without the MPI import just results in one print of Testing
. So is it possible that I isolate MPI to just file 3 and not all three files.