Actual source code: ex165.c
2: static char help[] = "Tests C=A^T*B via MatTranspose() and MatMatMult(). \n\
3: Contributed by Alexander Grayver, Jan. 2012 \n\n";
4: /* Example:
5: mpiexec -n <np> ./ex165 -fA A.dat -fB B.dat -view_C
6: */
8: #include <petscmat.h>
9: int main(int argc, char **args)
10: {
11: Mat A, AT, B, C;
12: PetscViewer viewer;
13: PetscBool flg;
14: char file[PETSC_MAX_PATH_LEN];
17: PetscInitialize(&argc, &args, (char *)0, help);
18: PetscOptionsGetString(NULL, NULL, "-fA", file, sizeof(file), &flg);
20: PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &viewer);
21: MatCreate(PETSC_COMM_WORLD, &A);
22: MatSetType(A, MATAIJ);
23: MatLoad(A, viewer);
24: PetscViewerDestroy(&viewer);
26: PetscOptionsGetString(NULL, NULL, "-fB", file, sizeof(file), &flg);
28: PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &viewer);
29: MatCreate(PETSC_COMM_WORLD, &B);
30: MatSetType(B, MATDENSE);
31: MatLoad(B, viewer);
32: PetscViewerDestroy(&viewer);
34: MatTranspose(A, MAT_INITIAL_MATRIX, &AT);
35: MatMatMult(AT, B, MAT_INITIAL_MATRIX, PETSC_DEFAULT, &C);
37: PetscOptionsHasName(NULL, NULL, "-view_C", &flg);
38: if (flg) {
39: PetscViewerBinaryOpen(PETSC_COMM_WORLD, "C.dat", FILE_MODE_WRITE, &viewer);
40: PetscViewerPushFormat(viewer, PETSC_VIEWER_NATIVE);
41: MatView(C, viewer);
42: PetscViewerPopFormat(viewer);
43: PetscViewerDestroy(&viewer);
44: }
45: MatDestroy(&A);
46: MatDestroy(&B);
47: MatDestroy(&AT);
48: MatDestroy(&C);
49: PetscFinalize();
50: return 0;
51: }