Actual source code: ex58.c

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

  3: static char help[] = "Tests MatTranspose() and MatEqual() for MPIAIJ matrices.nn";

 5:  #include petscmat.h


  8: int main(int argc,char **argv)
  9: {
 10:   Mat          A,B;
 11:   int          m = 7,n,i,ierr,rstart,rend,cols[3];
 12:   PetscScalar  v[3];
 13:   PetscTruth   equal;
 14:   char         *eq[2];

 16:   PetscInitialize(&argc,&argv,(char*)0,help);
 17:   PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_COMMON);
 18:   PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
 19:   n = m;

 21:   /* ------- Assemble matrix, test MatValid() --------- */

 23:   MatCreateMPIAIJ(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,m,n,0,0,0,0,&A);
 24:   MatGetOwnershipRange(A,&rstart,&rend);
 25:   if (rstart == 0) {
 26:     cols[0] = 0;
 27:     cols[1] = 1;
 28:     v[0]    = 2.0; v[1] = -1.0;
 29:     MatSetValues(A,1,&rstart,2,cols,v,INSERT_VALUES);
 30:     rstart++;
 31:   }
 32:   if (rend == m) {
 33:     rend--;
 34:     cols[0] = rend-1;
 35:     cols[1] = rend;
 36:     v[0]    = -1.0; v[1] = 2.0;
 37:     MatSetValues(A,1,&rend,2,cols,v,INSERT_VALUES);
 38:   }
 39:   v[0] = -1.0; v[1] = 2.0; v[2] = -1.0;
 40:   for (i=rstart; i<rend; i++) {
 41:     cols[0] = i-1;
 42:     cols[1] = i;
 43:     cols[2] = i+1;
 44:     MatSetValues(A,1,&i,3,cols,v,INSERT_VALUES);
 45:   }
 46:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 47:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 49:   MatTranspose(A,&B);

 51:   MatEqual(A,B,&equal);

 53:   eq[0] = "not equal";
 54:   eq[1] = "equal";
 55:   PetscPrintf(PETSC_COMM_WORLD,"Matrices are %sn",eq[equal]);

 57:   /* Free data structures */
 58:   MatDestroy(A);
 59:   MatDestroy(B);


 62:   PetscFinalize();
 63:   return 0;
 64: }
 65: