Actual source code: ex95.c

petsc-3.6.4 2016-04-12
Report Typos and Errors
  1: static char help[] = "Testing MatCreateMPIAIJSumSeqAIJ().\n\n";

  3: #include <petscmat.h>

  7: int main(int argc,char **argv)
  8: {
  9:   Mat            A,B;
 10:   MatScalar      a[1],alpha;
 11:   PetscMPIInt    size,rank;
 12:   PetscInt       m,n,i,col, prid;

 15:   PetscInitialize(&argc,&argv,(char*)0,help);
 16:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 17:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 18:   prid = size;
 19:   PetscOptionsGetInt(NULL,"-prid",&prid,NULL);

 21:   m    = n = 10*size;
 22:   MatCreate(PETSC_COMM_SELF,&A);
 23:   MatSetSizes(A,PETSC_DETERMINE,PETSC_DETERMINE,m,n);
 24:   MatSetType(A,MATSEQAIJ);
 25:   MatSetUp(A);

 27:   a[0] = rank+1;
 28:   for (i=0; i<m-rank; i++) {
 29:     col  = i+rank;
 30:     MatSetValues(A,1,&i,1,&col,a,INSERT_VALUES);
 31:   }
 32:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 33:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 35:   if (rank == prid) {
 36:     PetscPrintf(PETSC_COMM_SELF,"[%d] A: \n",rank);
 37:     MatView(A,PETSC_VIEWER_STDOUT_SELF);
 38:   }

 40:   /* Test MatCreateMPIAIJSumSeqAIJ */
 41:   MatCreateMPIAIJSumSeqAIJ(PETSC_COMM_WORLD,A,PETSC_DECIDE,PETSC_DECIDE,MAT_INITIAL_MATRIX,&B);

 43:   /* Test MAT_REUSE_MATRIX */
 44:   alpha = 0.1;
 45:   for (i=0; i<3; i++) {
 46:     MatScale(A,alpha);
 47:     MatCreateMPIAIJSumSeqAIJ(PETSC_COMM_WORLD,A,PETSC_DECIDE,PETSC_DECIDE,MAT_REUSE_MATRIX,&B);
 48:   }
 49:   MatView(B, PETSC_VIEWER_STDOUT_WORLD);
 50:   MatDestroy(&B);
 51:   MatDestroy(&A);

 53:   PetscFinalize();
 54:   return(0);
 55: }