Actual source code: ex113.c

  2: static char help[] = "Tests sequential and parallel MatMatMult() and MatAXPY(...,SUBSET_NONZERO_PATTERN) \n\
  3: Input arguments are:\n\
  4:   -f <input_file>  : file to load\n\n";
  5: /* e.g., mpiexec -n 3 ./ex113 -f <file> */

 7:  #include petscmat.h

 11: int main(int argc,char **args)
 12: {
 13:   Mat            A,A1,A2,Mtmp,dstMat;
 14:   PetscViewer    viewer;
 16:   PetscReal      fill=4.0;
 17:   char           file[128];
 18:   PetscTruth     flg;

 20:   PetscInitialize(&argc,&args,(char *)0,help);
 21: 
 22:   /*  Load the matrix A */
 23:   PetscOptionsGetString(PETSC_NULL,"-f",file,127,&flg);
 24:   if (!flg) SETERRQ(1,"Must indicate a file name for matrix A with the -f option.");

 26:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);
 27:   MatLoad(viewer,MATAIJ,&A);
 28:   PetscViewerDestroy(viewer);

 30:   MatDuplicate(A,MAT_COPY_VALUES,&A1);
 31:   MatDuplicate(A,MAT_COPY_VALUES,&A2);

 33:   /* dstMat = A*A1*A2 */
 34:   MatMatMult(A1,A2,MAT_INITIAL_MATRIX,fill,&Mtmp);
 35:   MatMatMult(A,Mtmp,MAT_INITIAL_MATRIX,fill,&dstMat);
 36:   MatDestroy(Mtmp);

 38:   /* dstMat += A1*A2 */
 39:   MatMatMult(A1,A2,MAT_INITIAL_MATRIX,fill,&Mtmp);
 40:   MatAXPY(dstMat,1.0,Mtmp,SUBSET_NONZERO_PATTERN);
 41:   MatDestroy(Mtmp);

 43:   /* dstMat += A*A1 */
 44:   MatMatMult(A,A1,MAT_INITIAL_MATRIX,fill,&Mtmp);
 45:   MatAXPY(dstMat, 1.0, Mtmp,SUBSET_NONZERO_PATTERN);
 46:   MatDestroy(Mtmp);

 48:   /* dstMat += A */
 49:   MatAXPY(dstMat, 1.0, A,SUBSET_NONZERO_PATTERN);

 51:   MatDestroy(A);
 52:   MatDestroy(A1);
 53:   MatDestroy(A2);
 54:   MatDestroy(dstMat);
 55:   PetscFinalize();
 56:   return 0;
 57: }