xref: /petsc/src/mat/tests/ex182.c (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
1 static char help[] = "Tests using MatShift() to create a constant diagonal matrix\n\n";
2 
3 #include <petscmat.h>
4 
5 int main(int argc, char **argv) {
6   Mat           A, F;
7   MatFactorInfo info;
8   PetscInt      m = 10;
9   IS            perm;
10   PetscMPIInt   size;
11   PetscBool     issbaij;
12 
13   PetscFunctionBeginUser;
14   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
15   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
16 
17   PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
18   PetscCall(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, m, m));
19   PetscCall(MatSetFromOptions(A));
20   PetscCall(MatSetUp(A));
21   PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
22   PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
23 
24   PetscCall(MatShift(A, 1.0));
25 
26   PetscCall(PetscObjectTypeCompare((PetscObject)A, MATSEQSBAIJ, &issbaij));
27   if (size == 1 && !issbaij) {
28     PetscCall(MatGetFactor(A, MATSOLVERPETSC, MAT_FACTOR_LU, &F));
29     PetscCall(MatFactorInfoInitialize(&info));
30     PetscCall(ISCreateStride(PETSC_COMM_SELF, m, 0, 1, &perm));
31     PetscCall(MatLUFactorSymbolic(F, A, perm, perm, &info));
32     PetscCall(MatLUFactorNumeric(F, A, &info));
33     PetscCall(MatDestroy(&F));
34     PetscCall(ISDestroy(&perm));
35   }
36   PetscCall(MatDestroy(&A));
37   PetscCall(PetscFinalize());
38   return 0;
39 }
40 
41 /*TEST
42 
43    test:
44       requires: defined(PETSC_USE_INFO)
45       args: -info
46       filter: grep malloc | sort -b
47 
48    test:
49       suffix: 2
50       nsize: 2
51       requires: defined(PETSC_USE_INFO)
52       args: -info ex182info
53       filter: grep -h malloc "ex182info.0" | sort -b
54 
55    test:
56       suffix: 3
57       requires: defined(PETSC_USE_INFO)
58       args: -info -mat_type baij
59       filter: grep malloc | sort -b
60 
61    test:
62       suffix: 4
63       nsize: 2
64       requires: defined(PETSC_USE_INFO)
65       args: -info ex182info -mat_type baij
66       filter: grep -h malloc "ex182info.1" | sort -b
67 
68    test:
69       suffix: 5
70       requires: defined(PETSC_USE_INFO)
71       args: -info -mat_type sbaij
72       filter: grep malloc | sort  -b
73 
74    test:
75       suffix: 6
76       nsize: 2
77       requires: defined(PETSC_USE_INFO)
78       args: -info ex182info -mat_type sbaij
79       filter: grep -h malloc "ex182info.0" | sort -b
80 
81    test:
82      suffix: 7
83      nsize: 1
84      requires: defined(PETSC_USE_INFO)
85      args: -info ex182info
86      filter: grep -h malloc "ex182info.0" | grep -v Running | sort -b
87 
88    test:
89      suffix: 8
90      nsize: 2
91      requires: defined(PETSC_USE_INFO)
92      args: -info ex182info:mat
93      filter: grep -h malloc "ex182info.1" | sort -b
94 
95    test:
96      suffix: 9
97      nsize: 1
98      requires: defined(PETSC_USE_INFO)
99      args: -info ex182info:sys
100      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscDetermineInitialFPTrap -ve libpetscbamg "ex182info.0" | sort -b
101 
102    test:
103      suffix: 10
104      nsize: 1
105      requires: defined(PETSC_USE_INFO)
106      args: -info :~sys
107      filter: grep -h malloc | sort -b
108 
109    test:
110      suffix: 11
111      nsize: 2
112      requires: defined(PETSC_USE_INFO)
113      args: -info :~sys,mat
114      filter: sort -b
115 
116    test:
117      suffix: 12
118      nsize: 2
119      requires: defined(PETSC_USE_INFO)
120      args: -info ex182info:sys,mat
121      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscDetermineInitialFPTrap -ve libpetscbamg "ex182info.1" | sort -b
122 
123    test:
124      suffix: 13
125      nsize: 2
126      requires: defined(PETSC_USE_INFO)
127      args: -info ex182info:mat:~self
128      filter: grep -h "ex182info.1" | sort -b
129 
130    test:
131      suffix: 14
132      nsize: 2
133      requires: defined(PETSC_USE_INFO)
134      args: -info ex182info::~self
135      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscDetermineInitialFPTrap "ex182info.1" | sort -b
136 
137    test:
138      suffix: 15
139      nsize: 2
140      requires: defined(PETSC_USE_INFO)
141      args: -info ex182info::self
142      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscDetermineInitialFPTrap -ve libpetscbamg "ex182info.1" | sort -b
143 
144 TEST*/
145