Actual source code: test1.c
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7: SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: */
11: static char help[] = "Tests B-orthonormality of eigenvectors in a GHEP problem.\n\n";
13: #include <slepceps.h>
15: int main(int argc,char **argv)
16: {
17: Mat A,B; /* matrices */
18: EPS eps; /* eigenproblem solver context */
19: ST st;
20: Vec *X,v;
21: PetscReal lev=0.0,tol=PETSC_SMALL;
22: PetscInt N,n=45,m,Istart,Iend,II,i,j,nconv;
23: PetscBool flag,skiporth=PETSC_FALSE;
24: EPSPowerShiftType variant;
26: PetscFunctionBeginUser;
27: PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
28: PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
29: PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
30: if (!flag) m=n;
31: N = n*m;
32: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nGeneralized Symmetric Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
33: PetscCall(PetscOptionsGetBool(NULL,NULL,"-skiporth",&skiporth,NULL));
35: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36: Compute the matrices that define the eigensystem, Ax=kBx
37: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39: PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
40: PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
41: PetscCall(MatSetFromOptions(A));
43: PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
44: PetscCall(MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N));
45: PetscCall(MatSetFromOptions(B));
47: PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
48: for (II=Istart;II<Iend;II++) {
49: i = II/n; j = II-i*n;
50: if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
51: if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
52: if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
53: if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
54: PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
55: PetscCall(MatSetValue(B,II,II,2.0/PetscLogScalar(II+2),INSERT_VALUES));
56: }
58: PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
59: PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
60: PetscCall(MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY));
61: PetscCall(MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY));
62: PetscCall(MatCreateVecs(B,&v,NULL));
64: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65: Create the eigensolver and set various options
66: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
68: PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
69: PetscCall(EPSSetOperators(eps,A,B));
70: PetscCall(EPSSetProblemType(eps,EPS_GHEP));
71: PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
72: PetscCall(EPSSetConvergenceTest(eps,EPS_CONV_NORM));
73: PetscCall(EPSSetFromOptions(eps));
75: /* illustrate how to extract parameters from specific solver types */
76: PetscCall(PetscObjectTypeCompare((PetscObject)eps,EPSPOWER,&flag));
77: if (flag) {
78: PetscCall(EPSGetST(eps,&st));
79: PetscCall(PetscObjectTypeCompare((PetscObject)st,STSHIFT,&flag));
80: if (flag) {
81: PetscCall(EPSPowerGetShiftType(eps,&variant));
82: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Type of shifts used during power iteration: %s\n",EPSPowerShiftTypes[variant]));
83: }
84: }
86: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87: Solve the eigensystem
88: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
90: PetscCall(EPSSolve(eps));
92: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
93: Display solution and clean up
94: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
96: PetscCall(EPSGetTolerances(eps,&tol,NULL));
97: PetscCall(EPSErrorView(eps,EPS_ERROR_BACKWARD,NULL));
98: PetscCall(EPSGetConverged(eps,&nconv));
99: if (nconv>1) {
100: PetscCall(VecDuplicateVecs(v,nconv,&X));
101: for (i=0;i<nconv;i++) PetscCall(EPSGetEigenvector(eps,i,X[i],NULL));
102: if (!skiporth) PetscCall(VecCheckOrthonormality(X,nconv,NULL,nconv,B,NULL,&lev));
103: if (lev<10*tol) PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality below the tolerance\n"));
104: else PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality: %g\n",(double)lev));
105: PetscCall(VecDestroyVecs(nconv,&X));
106: }
108: PetscCall(EPSDestroy(&eps));
109: PetscCall(MatDestroy(&A));
110: PetscCall(MatDestroy(&B));
111: PetscCall(VecDestroy(&v));
112: PetscCall(SlepcFinalize());
113: return 0;
114: }
116: /*TEST
118: testset:
119: args: -n 18 -eps_nev 4 -eps_max_it 1500
120: requires: !single
121: output_file: output/test1_1.out
122: test:
123: suffix: 1
124: args: -eps_type {{krylovschur arnoldi gd jd lapack}}
125: test:
126: suffix: 1_subspace
127: args: -eps_type subspace -eps_conv_rel
128: test:
129: suffix: 1_ks_nopurify
130: args: -eps_purify 0
131: test:
132: suffix: 1_ks_trueres
133: args: -eps_true_residual
134: test:
135: suffix: 1_ks_sinvert
136: args: -st_type sinvert -eps_target 22
137: test:
138: suffix: 1_ks_cayley
139: args: -st_type cayley -eps_target 22
140: test:
141: suffix: 1_lanczos
142: args: -eps_type lanczos -eps_lanczos_reorthog full
143: test:
144: suffix: 1_gd2
145: args: -eps_type gd -eps_gd_double_expansion
146: test:
147: suffix: 1_gd_borth
148: args: -eps_type gd -eps_gd_borth
149: test:
150: suffix: 1_jd_borth
151: args: -eps_type jd -eps_jd_borth
152: test:
153: suffix: 1_lobpcg
154: args: -eps_type lobpcg -st_shift 22 -eps_largest_real
155: test:
156: suffix: 1_hpddm
157: requires: hpddm
158: args: -eps_type lobpcg -st_shift 22 -eps_largest_real -st_pc_type lu -st_ksp_type hpddm
159: test:
160: suffix: 1_cholesky
161: args: -mat_type sbaij
162: test:
163: suffix: 1_scalapack
164: nsize: {{1 2 3}}
165: requires: scalapack !__float128
166: args: -eps_type scalapack
167: test:
168: suffix: 1_elpa
169: nsize: {{1 2 3}}
170: requires: elpa
171: args: -eps_type elpa
172: filter: grep -v "Buffering level"
173: test:
174: suffix: 1_elemental
175: nsize: {{1 2}}
176: requires: elemental
177: args: -eps_type elemental
179: testset:
180: args: -n 18 -eps_type ciss -rg_interval_endpoints 20.8,22
181: requires: !single
182: output_file: output/test1_1_ciss.out
183: test:
184: suffix: 1_ciss
185: args: -eps_ciss_extraction {{ritz hankel}}
186: test:
187: suffix: 1_ciss_ksps
188: args: -eps_ciss_strategy split -eps_ciss_integration_points 12
189: requires: !__float128
190: test:
191: suffix: 1_ciss_gnhep
192: args: -eps_gen_non_hermitian -skiporth
193: test:
194: suffix: 1_ciss_trapezoidal
195: args: -eps_ciss_quadrule trapezoidal -eps_ciss_integration_points 24 -eps_ciss_extraction hankel -eps_ciss_delta 1e-10 -eps_tol 5e-11 -skiporth
196: test:
197: suffix: 1_ciss_cuda
198: args: -mat_type aijcusparse -st_pc_factor_mat_solver_type cusparse
199: requires: cuda
200: test:
201: suffix: 1_ciss_hip
202: args: -mat_type aijhipsparse -st_pc_factor_mat_solver_type hipsparse
203: requires: hip
204: test:
205: suffix: 1_ciss_kokkos
206: TODO: CISS crashes with kokkos
207: args: -mat_type aijkokkos -st_pc_factor_mat_solver_type kokkos
208: requires: hip kokkos_kernels
210: testset:
211: requires: !single
212: args: -eps_tol 1e-10 -st_type sinvert -st_ksp_type preonly -st_pc_type cholesky
213: test:
214: suffix: 2
215: args: -eps_interval .1,1.1
216: test:
217: suffix: 2_open
218: args: -eps_interval -inf,1.1
219: test:
220: suffix: 2_parallel
221: requires: mumps !complex
222: nsize: 3
223: args: -eps_interval .1,1.1 -eps_krylovschur_partitions 2 -st_pc_factor_mat_solver_type mumps -st_mat_mumps_icntl_13 1
224: output_file: output/test1_2.out
226: test:
227: suffix: 3
228: requires: !single
229: args: -n 18 -eps_type power -eps_conv_rel -eps_nev 3
231: test:
232: suffix: 4
233: requires: !single
234: args: -n 18 -eps_type power -eps_conv_rel -eps_nev 3 -st_type sinvert -eps_target 1.149 -eps_power_shift_type {{constant rayleigh wilkinson}}
236: testset:
237: args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type icc
238: output_file: output/test1_5.out
239: test:
240: suffix: 5_rqcg
241: args: -eps_type rqcg
242: test:
243: suffix: 5_lobpcg
244: args: -eps_type lobpcg -eps_lobpcg_blocksize 3
245: test:
246: suffix: 5_hpddm
247: args: -eps_type lobpcg -eps_lobpcg_blocksize 3 -st_pc_type lu -st_ksp_type hpddm
248: requires: hpddm
249: test:
250: suffix: 5_blopex
251: args: -eps_type blopex -eps_conv_abs -st_shift 0.1
252: requires: blopex
254: testset:
255: args: -n 18 -eps_nev 12 -eps_mpd 8 -eps_max_it 3000
256: requires: !single
257: output_file: output/test1_6.out
258: test:
259: suffix: 6
260: args: -eps_type {{krylovschur arnoldi gd}}
261: test:
262: suffix: 6_lanczos
263: args: -eps_type lanczos -eps_lanczos_reorthog full
264: test:
265: suffix: 6_subspace
266: args: -eps_type subspace -eps_conv_rel
268: testset:
269: args: -n 18 -eps_nev 4 -eps_max_it 1500 -mat_type aijcusparse
270: requires: cuda !single
271: output_file: output/test1_1.out
272: test:
273: suffix: 7
274: args: -eps_type {{krylovschur arnoldi gd jd}}
275: test:
276: suffix: 7_subspace
277: args: -eps_type subspace -eps_conv_rel
278: test:
279: suffix: 7_ks_sinvert
280: args: -st_type sinvert -eps_target 22
281: test:
282: suffix: 7_lanczos
283: args: -eps_type lanczos -eps_lanczos_reorthog full
284: test:
285: suffix: 7_ciss
286: args: -eps_type ciss -rg_interval_endpoints 20.8,22 -st_pc_factor_mat_solver_type cusparse
287: output_file: output/test1_1_ciss.out
289: testset:
290: args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type sor -mat_type aijcusparse
291: requires: cuda
292: output_file: output/test1_5.out
293: test:
294: suffix: 8_rqcg
295: args: -eps_type rqcg
296: test:
297: suffix: 8_lobpcg
298: args: -eps_type lobpcg -eps_lobpcg_blocksize 3
300: testset:
301: nsize: 2
302: args: -n 18 -eps_nev 7 -eps_ncv 32 -ds_parallel synchronized
303: filter: grep -v "orthogonality" | sed -e "s/[+-]0\.0*i//g" | sed -e "s/0.61338/0.61339/g"
304: output_file: output/test1_9.out
305: test:
306: suffix: 9_ks_ghep
307: args: -eps_gen_hermitian -st_pc_type redundant -st_type sinvert
308: test:
309: suffix: 9_ks_gnhep
310: args: -eps_gen_non_hermitian -st_pc_type redundant -st_type sinvert
311: test:
312: suffix: 9_ks_ghiep
313: args: -eps_gen_indefinite -st_pc_type redundant -st_type sinvert
314: requires: !single
315: test:
316: suffix: 9_lobpcg_ghep
317: args: -eps_gen_hermitian -eps_type lobpcg -eps_max_it 200 -eps_lobpcg_blocksize 6
318: requires: !single
319: timeoutfactor: 2
320: test:
321: suffix: 9_jd_gnhep
322: args: -eps_gen_non_hermitian -eps_type jd -eps_target 0 -eps_ncv 64
323: requires: !single
324: timeoutfactor: 2
326: test:
327: suffix: 10_feast
328: args: -n 25 -eps_type feast -eps_interval .95,1.1 -eps_conv_rel -eps_tol 1e-6
329: requires: feast
331: testset:
332: args: -n 18 -eps_nev 4 -eps_max_it 1500 -mat_type aijhipsparse
333: requires: hip !single
334: output_file: output/test1_1.out
335: test:
336: suffix: 11
337: args: -eps_type {{krylovschur arnoldi gd jd}}
338: test:
339: suffix: 11_subspace
340: args: -eps_type subspace -eps_conv_rel
341: test:
342: suffix: 11_ks_sinvert
343: args: -st_type sinvert -eps_target 22
344: test:
345: suffix: 11_lanczos
346: args: -eps_type lanczos -eps_lanczos_reorthog full
347: test:
348: suffix: 11_ciss
349: args: -eps_type ciss -rg_interval_endpoints 20.8,22 -st_pc_factor_mat_solver_type hipsparse
350: output_file: output/test1_1_ciss.out
352: testset:
353: args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type sor -mat_type aijhipsparse
354: requires: hip
355: output_file: output/test1_5.out
356: test:
357: suffix: 12_rqcg
358: args: -eps_type rqcg
359: test:
360: suffix: 12_lobpcg
361: args: -eps_type lobpcg -eps_lobpcg_blocksize 3
363: TEST*/