-
When PetscOptionsGetViewer() returns, for example, PETSC_VIEWER_STDOUT_SELF the same object is shared by all threads that call PetscOptionsGetViewer(). In the previous code PetscObjectReference() and dereference (via PetscViewerDestroy() where called on the viewer by multiple threads after the viewer was accessed thus corrupting the object. This branch introduces a PetscOptionsRestoreViewer() that allows not doing the referencing and dereferencing on persistant viewers, thus removing the specific race condition above. Other possible solutions include Use a lock on each PetscObjectReference/Dereference() just in case they are shared. Could be time consuming so one could mark each object as either threadshared or independent and only do the locks on threadshared objects. This lowers the cost but would require more extensive changes to PETSc infrastructure. And I do not know if this shared/not shared model is what we need in the long run, though it might be.
cd791dc2