Actual source code: ex107.c
2: static char help[] = "Test MatCreate() with MAT_STRUCTURE_ONLY .\n\n";
4: #include <petscmat.h>
6: int main(int argc, char **argv)
7: {
8: Mat mat;
9: PetscInt m = 7, n, i, j, rstart, rend;
10: PetscMPIInt size;
11: PetscScalar v;
12: PetscBool struct_only = PETSC_TRUE;
15: PetscInitialize(&argc, &argv, (char *)0, help);
16: MPI_Comm_size(PETSC_COMM_WORLD, &size);
19: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_COMMON);
20: PetscOptionsGetInt(NULL, NULL, "-m", &m, NULL);
21: PetscOptionsGetBool(NULL, NULL, "-struct_only", &struct_only, NULL);
22: n = m;
24: /* ------- Assemble matrix, test MatValid() --------- */
25: MatCreate(PETSC_COMM_WORLD, &mat);
26: MatSetSizes(mat, PETSC_DECIDE, PETSC_DECIDE, m, n);
27: MatSetFromOptions(mat);
28: if (struct_only) MatSetOption(mat, MAT_STRUCTURE_ONLY, PETSC_TRUE);
29: MatSetUp(mat);
30: MatGetOwnershipRange(mat, &rstart, &rend);
31: for (i = rstart; i < rend; i++) {
32: for (j = 0; j < n; j++) {
33: v = 10.0 * i + j;
34: MatSetValues(mat, 1, &i, 1, &j, &v, INSERT_VALUES);
35: }
36: }
37: MatAssemblyBegin(mat, MAT_FINAL_ASSEMBLY);
38: MatAssemblyEnd(mat, MAT_FINAL_ASSEMBLY);
39: MatView(mat, PETSC_VIEWER_STDOUT_WORLD);
41: /* Free data structures */
42: MatDestroy(&mat);
43: PetscFinalize();
44: return 0;
45: }
47: /*TEST
49: test:
50: output_file: output/ex107.out
52: test:
53: suffix: 2
54: args: -mat_type baij -mat_block_size 2 -m 10
56: TEST*/