[petsc-users] How to create symmetric matrix?

Barry Smith bsmith at mcs.anl.gov
Mon Jun 6 14:27:07 CDT 2016


> On Jun 6, 2016, at 1:02 PM, Faraz Hussain <faraz_hussain at yahoo.com> wrote:
> 
> I am learning petsc and using the following code to insert values into my matrix:
> 
> ierr = MatSetValue(A, row, col, value,INSERT_VALUES);
> ierr = MatSetValue(A, col, row, value,INSERT_VALUES);
> 
> Since my matrix is symmetric, I want to speed things up only calling MatSetValue once. I tried setting: 
> 
>  ierr = MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
> 
> However, whenver I solve Ax=b, I get a wrong solution for x ( almost all zeroes ).  I am guessing MAT_SYMMETRIC is not automatically creating the lower triangular matrix from the upper triangular matrix?

    Correct. 

   You can use the SBAIJ format which stores only the diagonal and upper triangular portion of the matrix. Then you do not need to set the other values.

   Barry

> 
> 



More information about the petsc-users mailing list