question on MatSetValues

Barry Smith bsmith at mcs.anl.gov
Thu Sep 24 13:25:55 CDT 2009


On Sep 24, 2009, at 1:22 PM, Matt Funk wrote:

> Hi,
>
> i had a question concerning MatSetValues with respect to which  
> values are ignored.
>
> I believe that PETSC ignores column indices of -1?
> My question then is, are the corresponding entries in the values  
> array ignored as well?
>
>
> For example:
>
> int sizeOfNonZeroColumnEntries = 9
> int a_numRowsToInsert = 1
> int a_numRowsToInsert = 1
> int rowNumber 0
>
> //col. index vector for a given row (length 9)
> a_GlobalColNumber = {1 2 -1 4 5 6 -1 8 9}
>
> //corresponsing values vector for given row (length 9)
> a_Values = {x1 x2 x3 x4 x5 x6 x7 x8 x9}
>
> Now calling MatSetValues to insert this:
>
> m_ierr =
> MatSetValues(m_globalMatrix,
> a_numRowsToInsert,
> rowNumber,
> sizeOfNonZeroColumnEntries,
> &a_GlobalColNumber,
> &a_Values,
> INSERT_VALUES);
>
> question 1:
> will petsc insert 7 column/value pairs into the matrix, or will  
> insert 9

7

>
> question 2:
> assuming it only inserts 7, am assume it is ok that i only  
> preallocated 7 memory slots for this entry?

   Yes, you only need allocate 7.

   BTW: column (and row) indices always start at 0.

   Barry

>
>
> thanks
> matt
>
>
>



More information about the petsc-users mailing list