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;

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

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

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

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

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

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

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

 63: /*TEST

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

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

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

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

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

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

100: TEST*/