Gather solution in parallel

Something like this?

# u: solution Function from PDE

mpi_comm = u.function_space().mesh().mpi_comm()
array = u.vector().get_local()

# gather solution from all processes on proc 0
array_gathered = mpi_comm.gather(array, root=0)

# compute coefficients on proc 0
if mpi_comm.Get_rank() == 0:
    coef = compute_coefficients_glob(array_gathered)
else:
    coef = None

# broadcast from proc 0 to other processes
mpi_comm.Bcast(coef, root=0)
2 Likes