Actual source code: ex255.c

  1: static char help[] = "Tests MatConvert from AIJ to MATIS with a block size greater than 1.\n";

  3: #include <petscmat.h>
  4: int main(int argc, char **args)
  5: {
  6:   Mat         A, B;
  7:   char        file[PETSC_MAX_PATH_LEN];
  8:   PetscViewer fd;
  9:   PetscBool   flg, equal;

 11:   PetscFunctionBeginUser;
 12:   PetscCall(PetscInitialize(&argc, &args, NULL, help));

 14:   /* Load an AIJ matrix */
 15:   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", file, sizeof(file), &flg));
 16:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER, "Must indicate binary file with the -f option");
 17:   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd));
 18:   PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
 19:   PetscCall(MatSetFromOptions(A));
 20:   PetscCall(MatLoad(A, fd));

 22:   /* Convert it to MATIS */
 23:   PetscCall(MatConvert(A, MATIS, MAT_INITIAL_MATRIX, &B));

 25:   /* Check they are equal */
 26:   PetscCall(MatEqual(A, B, &equal));
 27:   PetscCheck(equal, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "A and B are not equal");

 29:   PetscCall(MatDestroy(&A));
 30:   PetscCall(MatDestroy(&B));
 31:   PetscCall(PetscViewerDestroy(&fd));
 32:   PetscCall(PetscFinalize());
 33: }

 35: /*TEST
 36:    test:
 37:      requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 38:      args: -mat_type aij -matload_block_size {{1 2}} -f ${DATAFILESPATH}/matrices/smallbs2
 39:      output_file: output/empty.out

 41: TEST*/