[petsc-users] Filling a matrix by chunks of nonzero entries

Matthew Knepley knepley at gmail.com
Mon Jun 20 11:00:56 CDT 2016


On Mon, Jun 20, 2016 at 8:13 AM, marco restelli <mrestelli at gmail.com> wrote:

> Dear all,
>    while assembling a matrix in PETsc we have the following pattern:
>
>
> do i=1,number_of_chunks
>
>  ! generate a chunk of matrix entries
>  call compute_ith_chunk( i_idx , j_idx , values )
>
>  ! insert those entries
>  do j=1,size_of_the_ith_chunk
>    call MatSetValue( mat , i_idx(j),j_idx(j),value(j) , add_values )
>  enddo
>
> enddo
>
>
> The problem is that inserting the elements with MatSetValue seems to
> have a significant overhead due to memory allocations and
> deallocations.
>
> Is there a way to speed-up this process, preallocating memory?
>
> Notice that we know the number of elements that we have to insert for
> each chunk, but we don't know to which extent they overlap, i.e. we do
> not know how many nonzero entries will result in the final matrix.
>
> Also, the entries do not have a block pattern, so we can not use
> MatSetValues.
>

Run the whole process once to count the entries, and then insert. This
usually
has negligible overhead.

   Matt


> Thank you,
>    Marco
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160620/30e0b122/attachment.html>


More information about the petsc-users mailing list