Closed vittoriodx7 closed 8 months ago
Hi @vittoriodx7 - that's a very interesting question.
I've tested and it's possible to do exactly what you're doing above in the setup
function of a module. It won't interfere with the MPI use later in the sampling because the pipeline setup is done before the MPI pool is created.
So yes, give it a go.
Incidentally, you can use:
if mpi_rank == 0:
heavy_stuff = calc()
mpi_comm.bcast(heavy_stuff, root=0)
else:
heavy_stuff = mpi_comm.bcast(None, root=0)
to replace your loop of send
s and recv
s - it should be more efficient.
Hello, I am currently adopting some code to cosmosis and I love it. However, I am not sure to understand a few things correctly regarding MPI and memory usage of setup functions.
In practice, imagine a likelihood that uses a lot of memory during
setup
and then uses much less memory duringexecute
phase because e.g. a complicated N-dimensional calculation in the former. In previous version of my code, usingmpi4py
, I was doing the memory intensive calculation only on one CPU and then share the much lighter results to the others in such a way that the overall memory usage of my code was remaining contained. In cosmosis I was wondering if such a possibility was available, if so what to setup in the pipeline to make that happen.e.g. in my old version it was something like::