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

Tabrez Ali stali at geology.wisc.edu
Mon Jun 20 12:02:56 CDT 2016


Just overestimate it. You'll only waste some local memory.

T

On 06/20/2016 11:09 AM, marco restelli wrote:
> 2016-06-20 18:00 GMT+0200, Matthew Knepley <knepley at gmail.com>:
>> 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.
> Matt, when you say "insert" do you mean using MatSetValue? That is
> what we are currently doing, and it seems to have a significant
> overhead due to memory allocations and deallocations.
>
> I know already the number of entries that I am going to insert, what I
> don't know is the number of nonzeros in the resulting matrix, since my
> entries might or might not overlap. Counting the number of nonzeros
> seems to me a nontrivial task, which I would be happy to leave to
> PETsc.
>
> Marco



More information about the petsc-users mailing list