Running Python MPI Applications¶
In this tutorial we show how a Python MPI model can be executed with Korali.
Do not forget to init MPI inside the Korali application:
from mpi4py import MPI
Run with the Distributed conduit to benefit from parallelized model evaluations. Note that we need to provide it with the MPI communicator we want to use for this instance of Korali. Next, we set Ranks Per Worker to determine how many MPI ranks will be assigned to each Korali worker. This particular example uses 4 MPI ranks per worker.
k.setMPIComm(MPI_COMM_WORLD); k["Conduit"]["Type"] = "Distributed"; k["Conduit"]["Ranks Per Worker"] = 4;
In some cases it might be useful to activate Korali’s internal profiler to analyze how efficiently workers executed. To enable it, add the following option:
k["Profiling"]["Detail"] = "Full"; k["Profiling"]["Frequency"] = 0.5;
If the computational model requires communication between the MPI ranks, you need to obtain the worker-specific sub-communicator
import korali ... comm = korali.getWorkerMPIComm() rank = comm.Get_rank() size = comm.Get_size()
To launch korali, use the corresponding MPI launcher, with a number of MPI ranks that equals k*n+1, where k is the number of Korali workers to use, n is the number of MPI Ranks per worker, and 1 MPI rank is assigned to the Korali engine. In this example, we launch two workers with 4 ranks each, hence we need 9 MPI ranks.
mpirun -n 9 ./run-cmaes