[petsc-users] MatSetValue

Barry Smith bsmith at mcs.anl.gov
Tue Jan 21 15:44:36 CST 2014


On Jan 21, 2014, at 3:26 PM, Que Cat <quecat001 at gmail.com> wrote:

> Hi Barry,
> 
> Thanks for your correction. This mean I have to set up values to be a 3x3 values matrix and set values[0]=1, values[4]=10, values[8]=20 and all other elements of values[i]=0 for i=1,2,3,5,6,7. But, by doing this way, it will also assembly 0 to other 6 location of the global matrix at (0,2) (3,1) (3,2) ..... and it may break the sparse matrix format of A. To prevent this, we must assembly one by one element (do the MatSetValues three times for this case) or is there any other way to set three elements of A at one time?

  Just set the three values with three calls. You should set blocks WHEN you can set blocks but not set blocks when you cannot set blocks.


> 
> 
> On Tue, Jan 21, 2014 at 2:25 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> 
> On Jan 21, 2014, at 1:22 PM, Que Cat <quecat001 at gmail.com> wrote:
> 
> > Hi Petsc-users,
> > I confused about the MatSetValue from the manual.
> > For example, I need to assembly three values A[0,1]=1 , A[3,2]=10 , A[5,2]=20 to the parallel matrix A. I can create a dense subblock matrix values that has dimension of m=1, n=3: values=[1 10 20], idxm=[0 3 5], idxn=[1 2 2].
> 
>    No this does not do that. the above idxm, idxn does not mean you are setting entries (0,1) (3,2) (5,2) it means you are setting the 1, 2 and 2 columns of the 0th, 3rd and 5th rows so 9 = 3x3 values. (which doesn’t make sense since you won’t set the 2 columns twice).
> > But the manual says that "the value to be put in row idxm[i] and column idxn[j] is located in values[i*n+j]". So, for example i=1,j=1 will add values[1*3+1] to the matrix, which does not exist in values. What do I misunderstand the manual? We can set separate value to the parallel matrix, but it says that it is better to set a subblock matrix.
> > Thank you.
> >
> > Que.
> 
> 



More information about the petsc-users mailing list