I was reading through the threads on this forum, and found that the simplest way to use MPI is to execute
mpirun -n np python demo.py
where “np” is the number of processors. When I use this option, my code gets executed “np” times. My motivation for using MPI is to split the computational load across several processors so that they work in parallel and the overall execution time (in real time) is reduced.
Could you please guide me to some resources which would help me achieve this? A simple example code would also be helpful.
Thank you. Could the fact that I am using “python3” and not “python” be the reason for this behavior? Because I tried running the demo programs using (e.g):
mpirun -n 2 python3 demo_poisson.py
the contents of the folder, apart from the code, are: poisson.pvd poisson000000.pvtu poisson_p0_000000.vtu poisson_p1_000000.vtu
If you think that this is erroneous behavior, I will try to figure out if MPI is configured correctly at my end.
Are you sure the code is being executed np times? The reason you get multiple output files, e.g.
poisson_p0_000000.vtu
poisson_p1_000000.vtu
...
is because the pvd format doesn’t support parallel access, so the result for each distributed portion of the mesh is written to a separate file. If you replace
file = File("poisson.pvd")
file << u
with
file = XDMFFile("poisson.xdmf")
file.write(u)
you should see that only one file poisson.xdmf is generated (with the corresponding .h5 file, of course).
Yes, using the xdmf option in place of pvd avoids the creation of multiple output files.
Also, I have “print” commands in my FEniCS script which get executed when using MPI, and I supposed that the solver was also being called “n” times. Based on a simple timing run, I can see that using the mpirun command as shown in my question indeed distributes the computational load. I was thrown off a bit by the output from the multiple “print” statements.