Actual source code: ex220.c


  2: #include <petscmat.h>

  4: static char help[PETSC_MAX_PATH_LEN] = "Tests MatLoad() with MatCreateDense() for memory leak ";

  6: int main(int argc, char **argv)
  7: {
  8:   PetscViewer viewer;
  9:   Mat         A;
 10:   char        filename[PETSC_MAX_PATH_LEN];
 11:   PetscBool   flg;

 13:   PetscFunctionBeginUser;
 14:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
 15:   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg));
 16:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT, "Must indicate a filename for input with the -f option");

 18:   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, filename, FILE_MODE_READ, &viewer));
 19:   PetscCall(MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, 36, 36, NULL, &A));
 20:   PetscCall(MatLoad(A, viewer));
 21:   PetscCall(PetscViewerDestroy(&viewer));
 22:   PetscCall(MatDestroy(&A));
 23:   PetscCall(PetscFinalize());
 24:   return 0;
 25: }

 27: /*TEST

 29:      test:
 30:        requires: double !complex !defined(PETSC_USE_64BIT_INDICES) datafilespath
 31:        args: -f ${DATAFILESPATH}/matrices/small

 33: TEST*/