Actual source code: ex52.c
2: static char help[] = "Tests various routines in MatMPIBAIJ format.\n";
4: #include <petscmat.h>
6: int main(int argc, char **args)
7: {
8: Mat A;
9: PetscInt m = 2, bs = 1, M, row, col, start, end, i, j, k;
10: PetscMPIInt rank, size;
11: PetscScalar data = 100;
12: PetscBool flg;
15: PetscInitialize(&argc, &args, (char *)0, help);
16: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
17: MPI_Comm_size(PETSC_COMM_WORLD, &size);
19: /* Test MatSetValues() and MatGetValues() */
20: PetscOptionsGetInt(NULL, NULL, "-mat_block_size", &bs, NULL);
21: PetscOptionsGetInt(NULL, NULL, "-mat_size", &m, NULL);
23: M = m * bs * size;
24: MatCreateBAIJ(PETSC_COMM_WORLD, bs, PETSC_DECIDE, PETSC_DECIDE, M, M, PETSC_DECIDE, NULL, PETSC_DECIDE, NULL, &A);
26: MatGetOwnershipRange(A, &start, &end);
27: PetscOptionsHasName(NULL, NULL, "-column_oriented", &flg);
28: if (flg) MatSetOption(A, MAT_ROW_ORIENTED, PETSC_FALSE);
30: /* inproc assembly */
31: for (row = start; row < end; row++) {
32: for (col = start; col < end; col++, data += 1) MatSetValues(A, 1, &row, 1, &col, &data, INSERT_VALUES);
33: }
34: MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
35: MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
37: /* offproc assembly */
38: data = 5.0;
39: row = (M + start - 1) % M;
40: for (col = 0; col < M; col++) MatSetValues(A, 1, &row, 1, &col, &data, ADD_VALUES);
41: MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
42: MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
44: /* Test MatSetValuesBlocked() */
45: PetscOptionsHasName(NULL, NULL, "-test_setvaluesblocked", &flg);
46: if (flg) {
47: PetscScalar *bval;
48: row /= bs;
49: col = start / bs;
50: PetscMalloc1(bs * bs, &bval);
51: k = 1;
52: /* row oriented - default */
53: for (i = 0; i < bs; i++) {
54: for (j = 0; j < bs; j++) {
55: bval[i * bs + j] = (PetscScalar)k;
56: k++;
57: }
58: }
59: MatSetValuesBlocked(A, 1, &row, 1, &col, bval, INSERT_VALUES);
60: MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
61: MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
62: PetscFree(bval);
63: }
65: MatView(A, PETSC_VIEWER_STDOUT_WORLD);
66: MatDestroy(&A);
67: PetscFinalize();
68: return 0;
69: }
71: /*TEST
73: test:
74: suffix: 1
75: nsize: 3
76: args: -mat_block_size 2 -test_setvaluesblocked
78: test:
79: suffix: 2
80: nsize: 3
81: args: -mat_block_size 2 -test_setvaluesblocked -column_oriented
83: test:
84: suffix: 3
85: nsize: 3
86: args: -mat_block_size 1 -test_setvaluesblocked
88: test:
89: suffix: 4
90: nsize: 3
91: args: -mat_block_size 1 -test_setvaluesblocked -column_oriented
93: TEST*/