Actual source code: ex207.c
petsc-3.14.6 2021-03-30
1: static char help[] = "Test MatCreateRedundantMatrix for a BAIJ matrix.\n\
2: Contributed by Lawrence Mitchell, Feb. 21, 2017\n\n";
4: #include <petscmat.h>
5: int main(int argc,char **args)
6: {
7: Mat A,B;
8: Vec diag;
9: PetscErrorCode ierr;
10: PetscMPIInt size,rank;
12: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
13: MPI_Comm_size(PETSC_COMM_WORLD, &size);
14: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
16: MatCreate(PETSC_COMM_WORLD, &A);
17: MatSetSizes(A, 2, 2, PETSC_DETERMINE, PETSC_DETERMINE);
18: MatSetBlockSize(A, 2);
19: MatSetType(A, MATBAIJ);
20: MatSetUp(A);
22: MatCreateVecs(A, &diag, NULL);
23: VecSet(diag, 1.0);
24: MatDiagonalSet(A, diag, INSERT_VALUES);
25: MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
26: MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
27: MatView(A,PETSC_VIEWER_STDOUT_WORLD);
29: MatCreateRedundantMatrix(A, size, MPI_COMM_NULL, MAT_INITIAL_MATRIX, &B);
30: if (!rank) {
31: MatView(B,PETSC_VIEWER_STDOUT_SELF);
32: }
34: MatDestroy(&A);
35: MatDestroy(&B);
36: VecDestroy(&diag);
37: PetscFinalize();
38: return ierr;
39: }
42: /*TEST
44: test:
46: test:
47: suffix: 2
48: nsize: 3
50: TEST*/