Assembling in Parallel and Solving in Serial

I am working with a problem where it takes a long time to assemble the vector u in Ax==u. Running the assemble in parallel does a good job with decreasing the time it takes to assemble, but doing so increases the time it takes to solve the problem. Is it possible for me to assemble u vector in parallel but then solve it with one core or is there something else I should be trying?

Does the solution from this thread help?

That did help with the solver not increasing as much, although it still does increase by a little bit. This is very helpful but I still wonder if there is a way to assemble in parallel and solve in serial?

I have the same problem, only I want to assemble in serial and solve in parallel. I assume that for doing something in parallel you always have to run your script with mpirun, but is there any way to perform some of the commands in your script in serial?

For some commands you can do this, e.g., by using

rank = fenics.MPI.comm_world.Get_rank()

if rank == 0:
    % only processor 0 does this

% the other commands are executed in parallel

However, this will not help with your problem directly. What you can do is to use the multithreading ability of PETSc to solve your linear systems in parallel even though you assembled them in serial. For example, just running a script as

python scripty.py

will execute the assembly in serial, and PETSC will use openmp to parallelize the solve of the linear system, for example with mumps. Sadly, I don’t know which of PETSc’s solvers support openmp (except for mumps), so this might not work for iterative solvers.

For MPI I am not sure if what you want is possible, I suspect that it is not as you might need a domain decomposition for that kind of solver and I guess you only get this by also assembling in parallel.