Actual source code: ex136.c


  2: static char help[] = "Tests MatLoad() MatView() for MPIBAIJ.\n\n";

  4: #include <petscmat.h>

  6: int main(int argc,char **args)
  7: {
  8:   Mat            A,B;
  9:   char           file[PETSC_MAX_PATH_LEN];
 10:   PetscBool      flg;
 11:   PetscViewer    fd;

 13:   PetscInitialize(&argc,&args,(char*)0,help);
 14:   PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);

 17:   /*
 18:      Open binary file.  Note that we use FILE_MODE_READ to indicate
 19:      reading from this file.
 20:   */
 21:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);

 23:   /*
 24:      Load the matrix; then destroy the viewer.
 25:   */
 26:   MatCreate(PETSC_COMM_WORLD,&A);
 27:   MatSetFromOptions(A);
 28:   MatLoad(A,fd);
 29:   PetscViewerDestroy(&fd);

 31:   /*
 32:      Open another binary file.  Note that we use FILE_MODE_WRITE to indicate writing to the file
 33:   */
 34:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_WRITE,&fd);
 35:   PetscViewerBinarySetFlowControl(fd,3);
 36:   /*
 37:      Save the matrix and vector; then destroy the viewer.
 38:   */
 39:   MatView(A,fd);
 40:   PetscViewerDestroy(&fd);

 42:   /* load the new matrix */
 43:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_READ,&fd);
 44:   MatCreate(PETSC_COMM_WORLD,&B);
 45:   MatSetFromOptions(B);
 46:   MatLoad(B,fd);
 47:   PetscViewerDestroy(&fd);

 49:   MatEqual(A,B,&flg);
 50:   if (flg) {
 51:     PetscPrintf(PETSC_COMM_WORLD,"Matrices are equal\n");
 52:   } else {
 53:     PetscPrintf(PETSC_COMM_WORLD,"Matrices are not equal\n");
 54:   }

 56:   MatDestroy(&A);
 57:   MatDestroy(&B);
 58:   PetscFinalize();
 59:   return 0;
 60: }

 62: /*TEST

 64:    test:
 65:       nsize: 3
 66:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 67:       args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info

 69:    test:
 70:       suffix: 2
 71:       nsize: 5
 72:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 73:       args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info

 75:    test:
 76:       suffix: 3
 77:       nsize: 7
 78:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 79:       args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info

 81:    test:
 82:       suffix: 4
 83:       nsize: 3
 84:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 85:       args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij

 87:    test:
 88:       suffix: 5
 89:       nsize: 5
 90:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 91:       args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij

 93:    test:
 94:       suffix: 6
 95:       nsize: 7
 96:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 97:       args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij

 99: TEST*/