Large Mesh Error PETSc Error 76 - Adjoint Calculation

So what happens when you call:mpirun -n 3 python3` instead of python3?

Since your conversion from mat-file to Function runs in serial, I suggest saving it with XDMFFile:write_checkpoint, which can be reloaded in parallel by XDMFFile.read_checkpoint, see Access function in time dependent XDMFFile