[petsc-users] choosing MatSetValue or MatSetValues

Barry Smith bsmith at mcs.anl.gov
Thu Mar 11 11:35:57 CST 2010


John-Michael,

    For dense matrices the only extra overhead of calling  
MatSetValue() for each point versus for a set of points is the  
function call overhead, since there is no searching etc for dense  
matrices since the values are stored directly in a dense array.

    As Jed points out for dense matrices BOTH sequential and parallel  
you can call MatGetArray() which gives direct access to the array  
(column oriented) for that process then stick values directly into the  
array. This eliminates the function call overhead of MatSetValues()  
and so is the way to go.

    Barry

By column oriented I mean that

    PetscScalar *a;
    MatGetArray(A,&a);

    a[0] is the from the first column, first row of the on the  
processes part of the matrix, a[1] is the first column, SECOND row on  
the processes part of the matrix. a[2] third column, a[m] is first  
column, second row where m is the local number of rows. Etc


On Mar 11, 2010, at 10:34 AM, John-Michael Fischer wrote:

> I need some help in determining the extent of the benefit when doing  
> dense matrix insertions.
>
> Essentially, in our software we need every last byte of memory we  
> can get, and I wanted to get some feedback on how much slower it  
> would be when building a dense matrix to use different insertion  
> methods.
> Option A:
> Use MatSetValue for every datapoint.
> Option B:
> Store some amount of values locally in an array as they are  
> generated (which would take up extra memory), say 1024, then using  
> MatSetValues to insert them over several sweeps of local generation.
>
> If the speed tradeoff for building the matrix is say, a factor of 2,  
> in exchange for not having to allocate the extra local memory --  
> then its probably worth it for us.  I just wanted to get some  
> intelligent comment on what those tradeoffs might be and how they  
> would scale.
>
> Thanks
> John-Michael Fischer



More information about the petsc-users mailing list