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. Thank you, Marco
