[petsc-users] KSP ex2.c and Parallelization

Zhang, Hong hzhang at mcs.anl.gov
Fri Feb 15 13:43:06 CST 2019


Maahi :
Hello All,

I have some questions regarding ex2.c in /petsc/src/ksp/ksp/examples/tutorials/ex2.c.

1.   The  local sizes of the matrix was decided by PETSc using ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n);CHKERRQ(ierr);
But without knowing the local sizes, how was the following function used which requires the knowledge of how the big matrix was split into smaller chunks within PETSc?
  ierr = MatMPIAIJSetPreallocation(A,5,NULL,5,NULL);CHKERRQ(ierr);
This example sets a matrix for 2D 5-point PDE stencil, for which the maximum non-zeros in each row is 5.

2.  When using  MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr),  the global index of  first and last row of which local chunk of the big matrix is it returning ? I mean if the big matrix was split into three processes, for example, fist and last global row of which process is it returning?
Adding a line
  ierr = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr);
+  printf("Istart %d Iend %d\n",Istart,Iend);

I get
$ mpiexec -n 3 ./ex2
Istart 0 Iend 19
Istart 19 Iend 38
Istart 38 Iend 56
Norm of error 0.000522061 iterations 9
The matrix global size = 56

Hong

Your replies are highly appreciated

Thanks,
Maahi Talukder
Clarkson University


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


More information about the petsc-users mailing list