This repository contains MPI examples using mpi4py.
gather.pyuses each core to update a different piece of information in a list and passes that information to all cores using the.gatherand.bcastmethods. Theallgather.pyexample is similar, but uses the.allgathermethod instead; it then parses the resulting information to keep only the updated values.
-
spawn_multiple_worker.pyis a program designed to be run as a worker/child process.spawn_multiple_worker_fortran.f90is the corresponding FORTRAN example. These programs will be called in the spawning programs below. They distribute a calculation of pi over the cores that were allocated to them and return the reduced-sum value to their parent process. -
spawn.pyis the most basic example of spawning, and performs a single spawn.spawn_loop.pyhas similar functionality, but spawns workers iteratively, waiting for each child process to finish before starting a new one. -
spawn_multiple.pyspawns multiple copies of an executable with different data.spawn_multiple_loop.pyspawns multiple executables during each iteration of a loop. -
spawn_fortran_multiple.pyandspawn_fortran_multiple_loop.pyare the analogous programs that call the FORTRAN worker rather than the Python worker.
-
split_multiple.pyis an analogous program tospawn_multiple.py, only rather than using spawn_multiple, it splits the world communicator within the parent process and then spawns processes on the newly created communicators. The worker process can be found insplit_multiple_worker.py. -
split_multiple_loop.pysplits and spawns multiple executables within a loop.
This code has only been tested with Open MPI 1.10.2 and mpi4py 2.0.0.
Open MPI sets the environment variable OMPI_MCA_orte_app_num, which is crucial for the spawn_multiple commands. This necessity can be avoided in other MPI implementations by passing the color in to the worker program. This is illustrated in the examples.
The processes of spawning multiple individuals using Spawn_multiple vs. Split -> Spawn both take about the same amount of time (within the margin of error for the simple tests I ran).
The Spawn Multiple programs can take advantage of the OpenMPI environment variable OMPI_MCA_orte_app_num directly, while the splitting examples inherently cannot. The Spawn Multiple examples can therefore be made to run naturally using MPMD with OpenMPI.
If more MPI APIs were to specify an argument analogous to OMPI_MCA_orte_app_num, the MPI_COMM_Spawn_multiple function would become signficantly more useful.