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>

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

 17:   PetscInitialize(&argc,&args,(char*)0,help);
 18:   /*  Load the matrix A */
 19:   PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);

 22:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);
 23:   MatCreate(PETSC_COMM_WORLD,&A);
 24:   MatLoad(A,viewer);
 25:   PetscViewerDestroy(&viewer);

 27:   MatDuplicate(A,MAT_COPY_VALUES,&A1);
 28:   MatDuplicate(A,MAT_COPY_VALUES,&A2);

 30:   /* dstMat = A*A1*A2 */
 31:   MatMatMult(A1,A2,MAT_INITIAL_MATRIX,fill,&Mtmp);
 32:   MatMatMult(A,Mtmp,MAT_INITIAL_MATRIX,fill,&dstMat);
 33:   MatDestroy(&Mtmp);

 35:   /* dstMat += A1*A2 */
 36:   MatMatMult(A1,A2,MAT_INITIAL_MATRIX,fill,&Mtmp);
 37:   MatAXPY(dstMat,1.0,Mtmp,SUBSET_NONZERO_PATTERN);
 38:   MatDestroy(&Mtmp);

 40:   /* dstMat += A*A1 */
 41:   MatMatMult(A,A1,MAT_INITIAL_MATRIX,fill,&Mtmp);
 42:   MatAXPY(dstMat, 1.0, Mtmp,SUBSET_NONZERO_PATTERN);
 43:   MatDestroy(&Mtmp);

 45:   /* dstMat += A */
 46:   MatAXPY(dstMat, 1.0, A,SUBSET_NONZERO_PATTERN);

 48:   MatDestroy(&A);
 49:   MatDestroy(&A1);
 50:   MatDestroy(&A2);
 51:   MatDestroy(&dstMat);
 52:   PetscFinalize();
 53:   return 0;
 54: }