[petsc-users] MatSetValues for nonzeros of a sparse matrix

Umut Tabak u.tabak at tudelft.nl
Wed Jan 13 09:53:20 CST 2010


Jed Brown wrote:
>   MatSetValues(A, 1, &idxm[r], 1, &idxn[r], &valuesMat[r*4+r], INSERT_VALUES);
>
> or
>
>   MatSetValue(A, idxm[r], idxn[r], valuesMat[r*4+r], INSERT_VALUES);
>
>   
Thanks for the quick replies, the above, I guess, still means to keep 
the zeros but below explanation is more practical from an efficiency 
point of view.
>> Also I keep the row and column indices of the non-zero values and as
>> well the non-zeros values in arrays of proper type.
>>     
>
> you should loop over rows and insert all entries of that row at once.
>   
This was where I was confused :), I should keep the non-zeros of the row 
and set them with the loop.

Thanks Jed.

Umut


More information about the petsc-users mailing list