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