xref: /petsc/src/mat/tests/ex179.c (revision df4cd43f92eaa320656440c40edb1046daee8f75)
1 
2 static char help[] = "Tests MatTranspose() with MAT_REUSE_MATRIX and different nonzero pattern\n\n";
3 
4 #include <petscmat.h>
5 
6 int main(int argc, char **argv)
7 {
8   Mat         A, B;
9   PetscMPIInt size;
10 
11   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
12   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
13   PetscCheck(size == 1, PETSC_COMM_WORLD, PETSC_ERR_WRONG_MPI_SIZE, "This is a uniprocessor example only!");
14   PetscCall(MatCreateSeqAIJ(PETSC_COMM_SELF, 2, 2, 2, NULL, &A));
15   PetscCall(MatSetValue(A, 0, 0, 1.0, INSERT_VALUES));
16   PetscCall(MatSetValue(A, 0, 1, 2.0, INSERT_VALUES));
17   PetscCall(MatSetValue(A, 1, 1, 4.0, INSERT_VALUES));
18   PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
19   PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
20   PetscCall(MatView(A, PETSC_VIEWER_STDOUT_SELF));
21   PetscCall(MatTranspose(A, MAT_INITIAL_MATRIX, &B));
22   PetscCall(MatView(B, PETSC_VIEWER_STDOUT_SELF));
23   PetscCall(MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
24   PetscCall(MatSetValue(A, 1, 0, 3.0, INSERT_VALUES));
25   PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
26   PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
27   PetscCall(MatView(A, PETSC_VIEWER_STDOUT_SELF));
28   PetscCall(MatTranspose(A, MAT_REUSE_MATRIX, &B));
29   PetscCall(MatView(B, PETSC_VIEWER_STDOUT_SELF));
30   PetscCall(MatDestroy(&A));
31   PetscCall(MatDestroy(&B));
32   PetscCall(PetscFinalize());
33   return 0;
34 }
35 
36 /*TEST
37 
38    test:
39 
40 TEST*/
41