[petsc-users] Filling a matrix by chunks of nonzero entries
Barry Smith
bsmith at mcs.anl.gov
Mon Jun 20 12:01:15 CDT 2016
> On Jun 20, 2016, at 10: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 )
This just generates a "random" bunch of nonzero entries with no structure? What discretization method are you using?
>
> ! 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.
Take a look at MatPreallocateInitialize() and its other routines it is designed to make it easy to get a good preallocation.
Barry
>
> Also, the entries do not have a block pattern, so we can not use
> MatSetValues.
>
> Thank you,
> Marco
More information about the petsc-users
mailing list