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> 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,(char*)0,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) { 31 PetscCall(MatView(B,PETSC_VIEWER_STDOUT_SELF)); 32 } 33 34 PetscCall(MatDestroy(&A)); 35 PetscCall(MatDestroy(&B)); 36 PetscCall(VecDestroy(&diag)); 37 PetscCall(PetscFinalize()); 38 return 0; 39 } 40 41 /*TEST 42 43 test: 44 45 test: 46 suffix: 2 47 nsize: 3 48 49 TEST*/ 50