[petsc-users] Question on matrix assembly
Matthew Knepley
knepley at gmail.com
Thu Aug 13 13:16:51 CDT 2020
On Thu, Aug 13, 2020 at 1:54 PM Sajid Ali <sajidsyed2021 at u.northwestern.edu>
wrote:
> Hi PETSc-developers,
>
> When assembling a matrix, what would the relative performance of the
> following be :
> [a] loop over the rows owned by the mpi-rank twice, first to compute the
> values and set preallocation for this mpi-rank and then again to fill in
> the values (as recommended in the manual)
> [b] loop over the rows once, preallocate and set the values for each row.
>
> I'm refactoring an application that follows approach [a] but computes the
> elements of the matrix twice (once to fill in the nnz arrays and once to
> set the values) and I want to know if computing, preallocating and setting
> the elements by row instead would be better (so as to not compute the
> matrix entries twice which involves calls to boost-geometry).
>
I am not sure what you mean by [b]. I do not believe the obvious
interpretation is possible in PETSc. We allocate the
matrix once, not row-by-row, so you could not preallocate just a few rows.
However, why not have a flag so that on the first pass you do not compute
entries, just the indices?
Thanks,
Matt
> I'm attaching a plot that shows (Left) the number of non-zeros per row for
> a typical matrix used in this application and (Right) the histogram of the
> number of non zeros per row, should this be useful. Note that this matrix
> has global dimensions [12800 rows, 65586 columns].
>
> PS : This matrix is used for a TAO optimization problem and generating the
> matrix takes between ~10 and ~25% of the time (longer on a smaller number
> of nodes).
>
> [image: image.png]
>
> Thank You,
> Sajid Ali | PhD Candidate
> Applied Physics
> Northwestern University
> s-sajid-ali.github.io
>
--
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
https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200813/ef01b2b4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 247517 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200813/ef01b2b4/attachment-0001.png>
More information about the petsc-users
mailing list