Closed EduardoCristo closed 2 years ago
Why don't you just wrap your serial part of the code in an if statement
from mpi4py import MPI
mpi_comm = MPI.COMM_WORLD
mpi_rank = mpi_comm.Get_rank()
if mpi_rank == 0:
# part of the code that runs in serial
I usually write a data preparation script, a analysis script and a plotting script, but @arnauqb's suggestion solves the messing up. you can also ask sampler.mpi_rank
, I think.
To pass arguments, if the data structures are complicated, you could use a file (json/hdf5). Otherwise have a look at the argparse
library to make a robust script and input parsing.
Description
Hi Joahannes! Is there any efficient way to run UltraNest in parallel inside a Python script? I can't use mpirun to run the main since it messes the parallelization of other part of the code.
What I Did
I coded a script to call UltraNest outside the main code, running it with os.system("mpirun -np x ultranest_script.py ..."). However, I'm having problems passing the function arguments. I'm convinced it must exist a better way of doing it.
Cheers, Eduardo.