Actual source code: ex52.c

  2: static char help[] = "Tests the vatious routines in MatMPIBAIJ format.\n";


 5:  #include petscmat.h

  9: int main(int argc,char **args)
 10: {
 11:   Mat            A;
 12:   PetscInt       m=2,bs=1,M,row,col,start,end;
 14:   PetscMPIInt    rank,size;
 15:   PetscScalar    data=100;

 17:   PetscInitialize(&argc,&args,(char *)0,help);
 18:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 19:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 20:   /* Test MatSetValues() and MatGetValues() */
 21:   PetscOptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);
 22:   PetscOptionsGetInt(PETSC_NULL,"-mat_size",&m,PETSC_NULL);

 24:   M    = m*bs*size;
 25:   MatCreateMPIBAIJ(PETSC_COMM_WORLD,bs,PETSC_DECIDE,PETSC_DECIDE,M,M,PETSC_DECIDE,PETSC_NULL,PETSC_DECIDE,PETSC_NULL,&A);

 27:   MatGetOwnershipRange(A,&start,&end);
 28: 
 29:   for (row=start; row<end; row++) {
 30:     for (col=start; col<end; col++,data+=1) {
 31:       MatSetValues(A,1,&row,1,&col,&data,INSERT_VALUES);
 32:     }
 33:   }
 34:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 35:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 37:   /* off proc assembly */
 38:   data = 5.0;
 39:   row = (M+start-1)%M;
 40:   for (col=0; col<M; col++) {
 41:     MatSetValues(A,1,&row,1,&col,&data,ADD_VALUES);
 42:   }
 43:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 44:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 46:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

 48:   MatDestroy(A);
 49: 
 50:   PetscFinalize();
 51:   return 0;
 52: }
 53: