[petsc-users] a question about MatSetValue

Dave May dave.mayhem23 at gmail.com
Thu May 21 03:08:27 CDT 2020


On Thu, 21 May 2020 at 08:55, Yang Bo (Asst Prof) <yang.bo at ntu.edu.sg>
wrote:

> Hi Everyone,
>
> I have a question about adding values to the matrix. The code I have is
>
>
> for (int i=0;i<row.size();i++) {
> MatSetValue(A,row[i],column[i],h[i],INSERT_VALUES);
> }
>
> where row.size() is a large number. It seems the running time of this
> procedure does not scale linearly with row.size(). As row.size() gets
> bigger, the time it takes increases exponentially.


It sounds like your matrix is not properly preallocated. Could this be the
case?

You can confirm / deny this by running with the command line options (shown
in bold)

./your-exec <your-options>* -info | grep malloc*

If all is good you will see something like this

[0] MatAssemblyEnd_SeqAIJ(): Number of mallocs during MatSetValues() is 0
    *total number of mallocs used during MatSetValues calls=0*

If the reported number of mallocs in your code is not 0, please read these
pages:

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSeqAIJSetPreallocation.html

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html


You may like to use the generic preallocator (depending on the type of you
Mat).

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html


Thanks
Dave




> Am I doing something wrong and can I do better than that?
>
> Thanks and stay healthy!
>
> Cheers,
>
> Yang Bo
> ________________________________
>
> CONFIDENTIALITY: This email is intended solely for the person(s) named and
> may be confidential and/or privileged. If you are not the intended
> recipient, please delete it, notify us and do not copy, use, or disclose
> its contents.
> Towards a sustainable earth: Print only when necessary. Thank you.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200521/97adbe0e/attachment.html>


More information about the petsc-users mailing list