[petsc-users] confusion about MatSetValues(A, ,ADD_VALUES);

Satish Balay balay at mcs.anl.gov
Fri May 31 11:59:01 CDT 2013


On Fri, 31 May 2013, Jed Brown wrote:

> 丁老师 <ztdepyahoo at 163.com> writes:
> 
> > I write a simple c procedure to test the MatSetValues.  the main body of procedure is like this
> >         
> >      int row=1;
> >      int col=10;
> >      double v=1.0;
> >    
> >      MatSetValues(A,1,&row,1,&col,&v,INSERT_VALUES);
> >       MatSetValues(A,1,&row,1,&row,&v,ADD_VALUES);
> >       MatSetValues(A,1,&col,1,&col,&v,ADD_VALUES);
> 
> You can't mix INSERT_VALUES and ADD_VALUES.  Please use debugging PETSc
> for development.  It warns about this.

i.e use:

      MatSetValues(A,1,&row,1,&col,&v,INSERT_VALUES);
      
   MatAssemblyBegin(A,MAT_FLUSH_ASSEMBLY);
   MatAssemblyEnd(A,MAT_FLUSH_ASSEMBLY);

      MatSetValues(A,1,&row,1,&row,&v,ADD_VALUES);
      MatSetValues(A,1,&col,1,&col,&v,ADD_VALUES);

   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

Satish


More information about the petsc-users mailing list