[petsc-users] Speed of matrix assembly

Mark Adams mfadams at lbl.gov
Thu Dec 1 07:23:46 CST 2022


This is the recommended call sequence to create a matrix:

 PetscCall(MatCreate(comm, &A));  PetscCall(MatSetSizes(A,
PETSC_DECIDE, PETSC_DECIDE, N, N));  PetscCall(MatSetFromOptions(A));
PetscCall(MatSeqAIJSetPreallocation(A, 3, NULL));
PetscCall(MatMPIAIJSetPreallocation(A, 3, NULL, 2, NULL));

You need to look at
https://petsc.org/main/docs/manualpages/Mat/MatMPIAIJSetPreallocation
And set the preallocation correctly.
Note, you can run with -info (very noisy so filter with grep or something)
and look for messages about the number of mallocs in the matrix assembly.
You want to preallocate enough to have zero mallocs.

Mark

On Thu, Dec 1, 2022 at 2:32 AM 김성익 <ksi2443 at gmail.com> wrote:

> Hello,
>
>
> I set a large-sized global matrix through matsetsize and proceed with the
> process of assembling multiple local-sized matrices into a global matrix
> (By using MatSetValue).
>
> However, only using matsetsize much less than expected performance.
> In this case, what can be done to speed up assembly?
>
> Thanks,
> Hyung Kim
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221201/270bad91/attachment.html>


More information about the petsc-users mailing list