Actual source code: ex222.c
1: static char help[] = "Tests MatComputeOperator() and MatComputeOperatorTranspose()\n\n";
3: #include <petscmat.h>
5: int main(int argc, char **argv)
6: {
7: Mat A, Ae, Aet;
8: char filename[PETSC_MAX_PATH_LEN];
9: char expltype[128], *etype = NULL;
10: PetscInt bs = 1;
11: PetscBool flg, check = PETSC_TRUE;
14: PetscInitialize(&argc, &argv, (char *)0, help);
16: PetscOptionsGetString(NULL, NULL, "-expl_type", expltype, sizeof(expltype), &flg);
17: if (flg) PetscStrallocpy(expltype, &etype);
18: PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg);
19: PetscOptionsGetInt(NULL, NULL, "-bs", &bs, NULL);
20: if (!flg) {
21: PetscInt M = 13, N = 6;
23: PetscOptionsGetInt(NULL, NULL, "-M", &M, NULL);
24: PetscOptionsGetInt(NULL, NULL, "-N", &N, NULL);
25: MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, M, N, NULL, &A);
26: MatSetBlockSize(A, bs);
27: MatSetRandom(A, NULL);
28: } else {
29: PetscViewer viewer;
31: PetscViewerBinaryOpen(PETSC_COMM_WORLD, filename, FILE_MODE_READ, &viewer);
32: MatCreate(PETSC_COMM_WORLD, &A);
33: MatSetBlockSize(A, bs);
34: MatSetFromOptions(A);
35: MatLoad(A, viewer);
36: PetscViewerDestroy(&viewer);
37: }
38: PetscObjectSetName((PetscObject)A, "Matrix");
39: MatViewFromOptions(A, NULL, "-view_expl");
41: MatComputeOperator(A, etype, &Ae);
42: PetscObjectSetName((PetscObject)Ae, "Explicit matrix");
43: MatViewFromOptions(Ae, NULL, "-view_expl");
45: PetscOptionsGetBool(NULL, NULL, "-check", &check, NULL);
46: if (check) {
47: Mat A2;
48: PetscReal err, tol = PETSC_SMALL;
50: PetscOptionsGetReal(NULL, NULL, "-tol", &tol, NULL);
51: MatConvert(A, etype, MAT_INITIAL_MATRIX, &A2);
52: MatAXPY(A2, -1.0, Ae, DIFFERENT_NONZERO_PATTERN);
53: MatNorm(A2, NORM_FROBENIUS, &err);
54: if (err > tol) PetscPrintf(PETSC_COMM_WORLD, "Error %g > %g (type %s)\n", (double)err, (double)tol, etype);
55: MatDestroy(&A2);
56: }
58: MatComputeOperatorTranspose(A, etype, &Aet);
59: PetscObjectSetName((PetscObject)Aet, "Explicit matrix transpose");
60: MatViewFromOptions(Aet, NULL, "-view_expl");
62: PetscFree(etype);
63: MatDestroy(&Ae);
64: MatDestroy(&Aet);
65: MatDestroy(&A);
66: PetscFinalize();
67: return 0;
68: }
70: /*TEST
72: test:
73: output_file: output/ex222_null.out
75: testset:
76: suffix: matexpl_rect
77: output_file: output/ex222_null.out
78: nsize: {{1 3}}
79: args: -expl_type {{dense aij baij}}
81: testset:
82: suffix: matexpl_square
83: output_file: output/ex222_null.out
84: nsize: {{1 3}}
85: args: -bs {{1 2 3}} -M 36 -N 36 -expl_type {{dense aij baij sbaij}}
87: TEST*/