I have a Python script that generates a system matrix. This happens serially, on one processor, in one process, nothing parallelized. I also have a solver code. The code runs on many processors using MPI.
Currently, the Python script creates the matrix, writes it to a file, calls the solver via subprocess.call(["mpirun ....."]), the solver reads the matrix from file, solves, writes back to a file and finally the Python script reads the result back from the file.
Now I'm looking for something more efficient, avoiding the file read/writes. One idea is to start the MPI process and run it in background, and then transfer data and commands with some sort of interprocess communication between Python and the solver.
How can I do interprocess communication in Python? Or are there better alternatives?
What I want to avoid is using the Python script within MPI (MPI4Py), because of debuggability and because parallelization there makes no sense.
mpiexectypically redirects its standard input to the standard input of rank 0 and does the opposite for the standard output of all ranks. Simply open a pipe to thempiexeccommand, send the matrix, then read the result. Just make sure that no rank other than 0 outputs to the standard output. Or useos.mkfifo()to create a separate FIFO.