Actual source code: ex60.c

petsc-3.8.4 2018-03-24
Report Typos and Errors

  2: static char help[] = "Tests MatGetColumnVector().";

  4:  #include <petscmat.h>

  6: int main(int argc,char **args)
  7: {
  8:   Mat            C;
  9:   PetscInt       i,j,m = 3,n = 2,Ii,J,col = 0;
 10:   PetscMPIInt    size,rank;
 12:   PetscScalar    v;
 13:   Vec            yy;

 15:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 16:   PetscOptionsGetInt(NULL,NULL,"-col",&col,NULL);

 18:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 19:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 20:   n    = 2*size;

 22:   /* create the matrix for the five point stencil, YET AGAIN*/
 23:   MatCreateAIJ(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,
 24:                       m*n,m*n,5,NULL,5,NULL,&C);
 25:   for (i=0; i<m; i++) {
 26:     for (j=2*rank; j<2*rank+2; j++) {
 27:       v = -1.0;  Ii = j + n*i;
 28:       if (i>0)   {J = Ii - n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 29:       if (i<m-1) {J = Ii + n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 30:       if (j>0)   {J = Ii - 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 31:       if (j<n-1) {J = Ii + 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 32:       v = 4.0; MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);
 33:     }
 34:   }
 35:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 36:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
 37:   MatView(C,PETSC_VIEWER_STDOUT_WORLD);

 39:   VecCreate(PETSC_COMM_WORLD,&yy);
 40:   VecSetSizes(yy,PETSC_DECIDE,m*n);
 41:   VecSetFromOptions(yy);

 43:   MatGetColumnVector(C,yy,col);

 45:   VecView(yy,PETSC_VIEWER_STDOUT_WORLD);

 47:   VecDestroy(&yy);
 48:   MatDestroy(&C);
 49:   PetscFinalize();
 50:   return ierr;
 51: }