Actual source code: test2.c
slepc-3.17.1 2022-04-11
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 multiple calls to EPSSolve with the same matrix.\n\n";
13: #include <slepceps.h>
15: int main(int argc,char **argv)
16: {
17: Mat A; /* problem matrix */
18: EPS eps; /* eigenproblem solver context */
19: ST st;
20: PetscReal tol=PetscMax(1000*PETSC_MACHINE_EPSILON,1e-9);
21: PetscInt n=30,i,Istart,Iend;
22: PetscBool flg;
23: EPSLanczosReorthogType reorth;
25: SlepcInitialize(&argc,&argv,(char*)0,help);
27: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
28: PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%" PetscInt_FMT "\n\n",n);
30: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31: Compute the operator matrix that defines the eigensystem, Ax=kx
32: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
34: MatCreate(PETSC_COMM_WORLD,&A);
35: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
36: MatSetFromOptions(A);
37: MatSetUp(A);
39: MatGetOwnershipRange(A,&Istart,&Iend);
40: for (i=Istart;i<Iend;i++) {
41: if (i>0) MatSetValue(A,i,i-1,-1.0,INSERT_VALUES);
42: if (i<n-1) MatSetValue(A,i,i+1,-1.0,INSERT_VALUES);
43: MatSetValue(A,i,i,2.0,INSERT_VALUES);
44: }
45: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
46: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
48: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49: Create the eigensolver
50: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
51: EPSCreate(PETSC_COMM_WORLD,&eps);
52: EPSSetOperators(eps,A,NULL);
53: EPSSetProblemType(eps,EPS_HEP);
54: EPSSetTolerances(eps,tol,PETSC_DEFAULT);
55: EPSSetFromOptions(eps);
57: /* illustrate how to extract parameters from specific solver types */
58: PetscObjectTypeCompare((PetscObject)eps,EPSLANCZOS,&flg);
59: if (flg) {
60: EPSLanczosGetReorthog(eps,&reorth);
61: PetscPrintf(PETSC_COMM_WORLD,"Reorthogonalization type used in Lanczos: %s\n",EPSLanczosReorthogTypes[reorth]);
62: }
64: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65: Solve for largest eigenvalues
66: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
67: EPSSetWhichEigenpairs(eps,EPS_LARGEST_REAL);
68: EPSSolve(eps);
69: PetscPrintf(PETSC_COMM_WORLD," - - - Largest eigenvalues - - -\n");
70: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
72: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73: Solve for smallest eigenvalues
74: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
75: EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL);
76: EPSSolve(eps);
77: PetscPrintf(PETSC_COMM_WORLD," - - - Smallest eigenvalues - - -\n");
78: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
80: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81: Solve for interior eigenvalues (target=2.1)
82: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
83: EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE);
84: EPSSetTarget(eps,2.1);
85: PetscObjectTypeCompare((PetscObject)eps,EPSLANCZOS,&flg);
86: if (flg) {
87: EPSGetST(eps,&st);
88: STSetType(st,STSINVERT);
89: } else {
90: PetscObjectTypeCompare((PetscObject)eps,EPSKRYLOVSCHUR,&flg);
91: if (!flg) PetscObjectTypeCompare((PetscObject)eps,EPSARNOLDI,&flg);
92: if (flg) EPSSetExtraction(eps,EPS_HARMONIC);
93: }
94: EPSSolve(eps);
95: PetscPrintf(PETSC_COMM_WORLD," - - - Interior eigenvalues - - -\n");
96: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
98: EPSDestroy(&eps);
99: MatDestroy(&A);
100: SlepcFinalize();
101: return 0;
102: }
104: /*TEST
106: testset:
107: args: -eps_nev 4
108: requires: !single
109: output_file: output/test2_1.out
110: test:
111: suffix: 1
112: args: -eps_type {{arnoldi gd jd lapack}}
113: test:
114: suffix: 1_gd2
115: args: -eps_type gd -eps_gd_double_expansion
116: timeoutfactor: 2
117: test:
118: suffix: 1_krylovschur
119: args: -eps_type krylovschur -eps_krylovschur_locking {{0 1}}
120: test:
121: suffix: 1_scalapack
122: requires: scalapack
123: args: -eps_type scalapack
124: test:
125: suffix: 1_elpa
126: requires: elpa
127: args: -eps_type elpa
128: test:
129: suffix: 1_elemental
130: requires: elemental
131: args: -eps_type elemental
133: testset:
134: args: -eps_type lanczos -eps_nev 4
135: requires: !single
136: filter: grep -v "Lanczos"
137: output_file: output/test2_1.out
138: test:
139: suffix: 2
140: args: -eps_lanczos_reorthog {{local full periodic partial}}
141: test:
142: suffix: 2_selective
143: args: -eps_lanczos_reorthog selective
144: requires: !defined(PETSCTEST_VALGRIND)
146: testset:
147: args: -n 32 -eps_nev 4
148: requires: !single
149: output_file: output/test2_3.out
150: test:
151: nsize: 2
152: suffix: 3
153: args: -eps_type {{krylovschur lapack}}
154: test:
155: nsize: 2
156: suffix: 3_gd
157: args: -eps_type gd -eps_gd_krylov_start
158: timeoutfactor: 2
159: test:
160: suffix: 3_jd
161: args: -eps_type jd -eps_jd_krylov_start -eps_ncv 18
163: testset:
164: args: -eps_nev 4 -mat_type aijcusparse
165: requires: cuda !single
166: output_file: output/test2_1.out
167: test:
168: suffix: 4_cuda
169: args: -eps_type {{krylovschur arnoldi gd jd}}
171: TEST*/