Hola Jesús You were lucky you got 20x. See
https://petsc.org/release/docs/manualpages/Mat/MatSeqAIJSetPreallocation.html https://petsc.org/release/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html Quote: "For large problems you MUST preallocate memory or you will get TERRIBLE performance, see the users' manual chapter on matrices. " -- jeremy On Wed, 2021-12-29 at 22:12 +0000, Ferrand, Jesus A. wrote: > Dear PETSc Team: > > I have a question about DM andPetscSection. Say I import a mesh (for > FEM purposes) and create aDMPlex for it. I then usePetscSections to > set degrees of freedom per "point" (by point I mean vertices, lines, > faces, and cells). I then usePetscSectionGetStorageSize() to get the > size of the global stiffness matrix (K) needed for my FEM problem. > One last detail, this K I populate inside a rather large loop using > an element stiffness matrix function of my own. Instead of > usingDMCreateMatrix(), I manually created aMat using MatCreate(), > MatSetType(),MatSetSizes(), and MatSetUp(). I come to find that said > loop is painfully slow when I use the manually created matrix, but > 20x faster when I use the Mat coming out ofDMCreateMatrix(). > > My question is then: Is the manual Mat a noob mistake and is it > somehow creating a memory leak with K? Just in case it's something > else I'm attaching the code. The loop that populates K is between > lines 221 and 278. Anything related to DM, DMPlex, and PetscSection > is between lines 117 and 180. > > Machine Type: HP Laptop > C-compiler: Gnu C > OS: Ubuntu 20.04 > PETSc version: 3.16.0 > MPI Implementation: MPICH > > Hope you all had a Merry Christmas and that you will have a happy and > productive New Year. :D > > Sincerely: > J.A. Ferrand > Embry-Riddle Aeronautical University - Daytona Beach FL > M.Sc. Aerospace Engineering | May 2022 > B.Sc. Aerospace Engineering > B.Sc. Computational Mathematics > > Sigma Gamma Tau > Tau Beta Pi > Honors Program > > Phone: (386)-843-1829 > Email(s): ferra...@my.erau.edu > jesus.ferr...@gmail.com