I’m trying to manipulate functions using assign()
inside of a for-loop, but I want my code to run in parallel, especially when using solve()
elsewhere inside of a time loop.
As a simple example, consider the following code code as run using mpirun -np 2
# Define submesh mesh and function spaces
mesh = BoxMesh(Point(0, 0), Point(box_length, box_length, 0.5),
64, 64, 32)
P1 = FiniteElement('CG', mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, P1)
#Initialize functions
Aexp = Expression('2', degree=1)
A = interpolate(Aexp, W)
Bexp = Expression('2', degree=1)
B = interpolate(Bexp, W)
Cexp = Expression('0', degree=1)
C = interpolate(C, W)
#time loop
for t in range(0,5):
C.assign(A + B)
B.assign(C)
print(C.vector().get_local())
This returns the following error message
-------------------------------------------------------------------------
*** Error: Unable to successfully call PETSc function 'VecCopy'.
*** Reason: PETSc error code is: 73 (Object is in wrong state).
*** Where: This error was encountered inside /home/conda/feedstock_root/build_artifacts/fenics-pkgs_1668433332839/work/dolfin/dolfin/la/PETScVector.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset: 3ea2183fbfe7277de9f16cbe1a9ffaab133ba1fa
*** -------------------------------------------------------------------------
This question seems similar to this question, but that question was never answered and my example is both slightly different in form and returns a different error.
Any help at all would be appreciated, even just an explanation of what is going on with the dofs in parallel, or pointing to the relevant documentation. Clearly, I know that assign itself does not probably need parallelization. Parallelizing other code that might be in the for-loop alongside assign()
is my real goal. For instance, when assign()
is used in a time loop to update a source field for some variational form to be solved.