Actual source code: ex100.c

  1: static char help[] = "Tests various routines in MatMAIJ format.\n";

  3: #include <petscmat.h>
  4: #define IMAX 15
  5: int main(int argc, char **args)
  6: {
  7:   Mat         A, B, MA;
  8:   PetscViewer fd;
  9:   char        file[PETSC_MAX_PATH_LEN];
 10:   PetscInt    m, n, M, N, dof = 1;
 11:   PetscMPIInt rank, size;
 12:   PetscBool   flg;

 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
 16:   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
 17:   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));

 19:   /* Load aij matrix A */
 20:   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", file, sizeof(file), &flg));
 21:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER, "Must indicate binary file with the -f option");
 22:   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd));
 23:   PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
 24:   PetscCall(MatLoad(A, fd));
 25:   PetscCall(PetscViewerDestroy(&fd));

 27:   /* Get dof, then create maij matrix MA */
 28:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-dof", &dof, NULL));
 29:   PetscCall(MatCreateMAIJ(A, dof, &MA));
 30:   PetscCall(MatGetLocalSize(MA, &m, &n));
 31:   PetscCall(MatGetSize(MA, &M, &N));

 33:   if (size == 1) {
 34:     PetscCall(MatConvert(MA, MATSEQAIJ, MAT_INITIAL_MATRIX, &B));
 35:   } else {
 36:     PetscCall(MatConvert(MA, MATMPIAIJ, MAT_INITIAL_MATRIX, &B));
 37:   }

 39:   /* Test MatMult() */
 40:   PetscCall(MatMultEqual(MA, B, 10, &flg));
 41:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_CONV_FAILED, "Error: MatMul() for MAIJ matrix");
 42:   /* Test MatMultAdd() */
 43:   PetscCall(MatMultAddEqual(MA, B, 10, &flg));
 44:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_CONV_FAILED, "Error: MatMulAdd() for MAIJ matrix");

 46:   /* Test MatMultTranspose() */
 47:   PetscCall(MatMultTransposeEqual(MA, B, 10, &flg));
 48:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_CONV_FAILED, "Error: MatMulAdd() for MAIJ matrix");

 50:   /* Test MatMultTransposeAdd() */
 51:   PetscCall(MatMultTransposeAddEqual(MA, B, 10, &flg));
 52:   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_CONV_FAILED, "Error: MatMulTransposeAdd() for MAIJ matrix");

 54:   PetscCall(MatDestroy(&MA));
 55:   PetscCall(MatDestroy(&A));
 56:   PetscCall(MatDestroy(&B));
 57:   PetscCall(PetscFinalize());
 58:   return 0;
 59: }

 61: /*TEST

 63:    build:
 64:       requires: !complex

 66:    test:
 67:       nsize: {{1 3}}
 68:       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
 69:       args: -f ${DATAFILESPATH}/matrices/arco1 -dof {{1 2 3 4 5 6 8 9 16}} -viewer_binary_skip_info

 71: TEST*/