Regression tests fail with Petsc-3.9
friedenhe opened this issue · 3 comments
Type of issue
- Bugfix (non-breaking change which fixes an issue)
Description
Regression tests work up to Petsc-3.8, and they all fail when upgrading to Petsc-3.9
Serial reg tests pass, the issue only happens for parallel runs.
We found that it's related to the changes in the parallel behavior of the INSERT_VALUES option in MatSetValues function. As an example, if we do:
MatSetValue(myMat,0,0,1.0,INSERT_VALUES);
MatSetValue(myMat,0,0,2.0,INSERT_VALUES);
MatAssemblyBegin(myMat,MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(myMat,MAT_FINAL_ASSEMBLY);
In Petsc version <= 3.8, the [0,0] element in myMat will always be 2.0.
However, in Petsc version > 3.8, the [0,0] element in myMat can be 1.0 or 2.0.
So to avoid this we should always flush the matrix before different values are inserted.
That being said, we should do this if we want to make sure the [0,0] element in myMat is always 2.0
MatSetValue(myMat,0,0,1.0,INSERT_VALUES);
MatAssemblyBegin(myMat,MAT_FLUSH_ASSEMBLY);
MatAssemblyEnd(myMat,MAT_FLUSH_ASSEMBLY);
MatSetValue(myMat,0,0,2.0,INSERT_VALUES);
MatAssemblyBegin(myMat,MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(myMat,MAT_FINAL_ASSEMBLY);