Actual source code: ex52.c

  1: /*$Id: ex52.c,v 1.16 2001/08/07 03:03:07 balay Exp $*/

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


 6:  #include petscmat.h

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

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

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

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

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

 45:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

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