You are not allowed to call VecGetArray on the solution vector of an SNES object within a user callback, nor to modify its values in any other way. Put in C++ lingo, the solution vector is a "const" argument It would be great if you could provide an MWE to help us understand your problem
Il giorno mer 17 dic 2025 alle ore 20:51 David Knezevic via petsc-users < [email protected]> ha scritto: > Hi all, > > I have a question about this error: > >> Vector 'Vec_0x84000005_0' (argument #2) was locked for read-only access >> in unknown_function() at unknown file:0 (line numbers only accurate to >> function begin) > > > I'm encountering this error in an FE solve where there is an error > encountered during the residual/jacobian assembly, and what we normally do > in that situation is shrink the load step and continue, starting from the > "last converged solution". However, in this case I'm running on 32 > processes, and 5 of the processes report the error above about a "locked > vector". > > We clear the SNES object (via SNESDestroy) before we reset the solution to > the "last converged solution", and then we make a new SNES object > subsequently. But it seems to me that somehow the solution vector is still > marked as "locked" on 5 of the processes when we modify the solution > vector, which leads to the error above. > > I was wondering if someone could advise on what the best way to handle > this would be? I thought one option could be to add an MPI barrier call > prior to updating the solution vector to "last converged solution", to make > sure that the SNES object is destroyed on all procs (and hence the locks > cleared) before editing the solution vector, but I'm unsure if that would > make a difference. Any help would be most appreciated! > > Thanks, > David > -- Stefano
