Hello!<div><span style="white-space:pre"> </span>I am a beginner about petsc,and I'm studing the DMDA recently. I hava a exercise code below, i run it with 4 processes, why is the size of A matrix is 15×15? The user manual said A is the Jobian matix, is there any detailed material that explain the process? Another question is the setting values for A. I don't understand why a loop using the grid distribution information of each process can assign a value to A. The MatStencil mentioned in the user manual is a Data structure (C struct) for storing information about a single row or column of a matrix, why MatStencil contains i and j at the same time, and the row only needs i. Very much looking forward to reply,thanks.</div><div><br></div><div><div>  DM grid;</div><div>  ierr = DMDACreate2d            // IN:</div><div>    ( comm,                      // collective on this communicator</div><div>      DM_BOUNDARY_NONE,DM_BOUNDARY_NONE, // no periodicity and such</div><div>      DMDA_STENCIL_STAR,         // no cross connections</div><div>      4,4,                 // global size 100x100; can be changed with options</div><div>      PETSC_DECIDE,PETSC_DECIDE, // processors in each direction</div><div>      1,                         // degree of freedom per node</div><div>      1,                         // stencil width</div><div>      NULL,NULL,                 // arrays of local sizes in each direction</div><div>      &grid                      // OUT: resulting object</div><div>      ); CHKERRQ(ierr);</div><div>  ierr = DMSetUp(grid); CHKERRQ(ierr);</div><div><br></div><div>  Mat A;</div><div>  ierr = DMCreateMatrix(grid,&A); CHKERRQ(ierr);</div></div><div><div>  DMDALocalInfo  info;</div><div>  ierr = DMDAGetLocalInfo(grid,&info);CHKERRQ(ierr);</div></div><div><div>  for (int j=info.ys; j<info.ys+info.ym; j++) {</div><div>    for (int i=info.xs; i<info.xs+info.xm; i++) {</div><div>      MatStencil  row = {0},col[5] = {{0}};</div><div>      PetscScalar v[5];</div><div>      PetscInt    ncols = 0;</div><div>      row.j        = j; row.i = i;</div><div>      printf("procno: %d;j:%d; i:%d\n",procno,j,i);</div><div>      /**** local connection: diagonal element ****/</div><div>      col[ncols].j = j; col[ncols].i = i; v[ncols++] = 4.;</div><div>      printf("procno: %d, j:%d. col[%d].j = %d, col[%d].i = %d, v[%d]=4\n",procno,j,ncols-1,j,ncols-1,i,ncols);</div><div>      /* boundaries: top row */</div><div>      if (i>0)         {</div><div>        col[ncols].j = j;   col[ncols].i = i-1; v[ncols++] = -1.;</div><div>        printf("procno: %d, j:%d. col[%d].j = %d, col[%d].i = %d, v[%d]=4\n",procno,j,ncols-1,j,ncols-1,i-1,ncols);</div><div>        }</div><div>      if (j>0){</div><div>        col[ncols].j = j-1; col[ncols].i = i;   v[ncols++] = -1.;</div><div>        printf("procno: %d, j:%d. col[%d].j = %d, col[%d].i = %d, v[%d]=4\n",procno,j,ncols-1,j-1,ncols-1,i,ncols);</div><div>        }</div><div>      if (j<info.my-1) {</div><div>        col[ncols].j = j+1; col[ncols].i = i;   v[ncols++] = -1.;</div><div>        printf("procno: %d, j:%d. col[%d].j = %d, col[%d].i = %d, v[%d]=-1\n",procno,j,ncols-1,j+1,ncols-1,i+1,ncols);</div><div>        }</div><div><br></div><div>      /* boundary: bottom row */</div><div>      if (i<info.mx-1) {</div><div>        col[ncols].j = j;   col[ncols].i = i+1; v[ncols++] = -1.;</div><div>        printf("procno: %d, j:%d. col[%d].j = %d, col[%d].i = %d, v[%d]=-1\n",procno,j,ncols-1,j,ncols-1,i+1,ncols);</div><div>        }</div><div>      ierr = MatSetValuesStencil(A,1,&row,ncols,col,v,INSERT_VALUES);CHKERRQ(ierr);</div><div>    }</div><div>  }</div></div>