[petsc-users] MatSetValues() can't work right

Barry Smith bsmith at petsc.dev
Mon Mar 18 08:28:36 CDT 2024


   The output is correct (only confusing). For PETSc DMDA by default viewing a parallel matrix converts it to the "natural" ordering instead of the PETSc parallel ordering.

   See the Notes in https://urldefense.us/v3/__https://petsc.org/release/manualpages/DM/DMCreateMatrix/__;!!G_uCfscf7eWS!dHznAiOiU4NDCipIaS1et2IIGx1u779XYQmMGk4EeeLQf41tAhbciI4ne1JKfOR0jG5WCsFm7dRWuEy6KdNhM5w$ 

  Barry


> On Mar 18, 2024, at 8:06 AM, Waltz Jan <jl2862237661 at gmail.com> wrote:
> 
> This Message Is From an External Sender
> This message came from outside your organization.
> PETSc version: 3.20.4
> Program:
> #include <petscdmda.h>
> #include <petscsys.h>
> #include <petscdm.h>
> #include <petscdmda.h>
> #include <petscsys.h>
> #include <petscdm.h>
> #include <petsc/private/snesimpl.h>
> 
> int main()
> {
>     PetscInitialize(NULL, NULL, NULL, NULL);
>     DM da;
>     DMDACreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DMDA_STENCIL_STAR,
>                  10, 1, 10, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, 3, 1, NULL, NULL, NULL, &da);
>     DMSetFromOptions(da);
>     DMSetUp(da);
>     Mat Jac;
>     DMCreateMatrix(da, &Jac);
>     int row = 100, col = 100;
>     double val = 1.;
>     MatSetValues(Jac, 1, &row, 1, &col, &val, INSERT_VALUES);
>     MatAssemblyBegin(Jac, MAT_FINAL_ASSEMBLY);
>     MatAssemblyEnd(Jac, MAT_FINAL_ASSEMBLY);
> 
>     PetscViewer viewer;
>     PetscViewerASCIIOpen(PETSC_COMM_WORLD, "./jacobianmatrix.m", &viewer);
>     PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);
>     MatView(Jac, viewer);
>     PetscViewerDestroy(&viewer);
> 
>     PetscFinalize();
> }
> 
> When I ran the program with np = 6, I got the result as the below
> <image.png>
> It's obviously wrong.
> When I ran the program with np = 1 or 8, I got the right result as
> <image.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240318/d684b717/attachment-0001.html>


More information about the petsc-users mailing list