Actual source code: ex2.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[] = "Standard symmetric eigenproblem corresponding to the Laplacian operator in 2 dimensions.\n\n"
12: "The command line options are:\n"
13: " -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
14: " -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";
16: #include <slepceps.h>
18: int main(int argc,char **argv)
19: {
20: Mat A; /* operator matrix */
21: EPS eps; /* eigenproblem solver context */
22: EPSType type;
23: EPSStop stop;
24: PetscReal thres;
25: PetscInt N,n=10,m,Istart,Iend,II,nev,i,j;
26: PetscBool flag,terse;
28: PetscFunctionBeginUser;
29: PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
31: PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
32: PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
33: if (!flag) m=n;
34: N = n*m;
35: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
37: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38: Compute the operator matrix that defines the eigensystem, Ax=kx
39: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41: PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
42: PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
43: PetscCall(MatSetFromOptions(A));
45: PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
46: for (II=Istart;II<Iend;II++) {
47: i = II/n; j = II-i*n;
48: if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
49: if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
50: if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
51: if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
52: PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
53: }
55: PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
56: PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
58: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59: Create the eigensolver and set various options
60: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
62: /*
63: Create eigensolver context
64: */
65: PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
67: /*
68: Set operators. In this case, it is a standard eigenvalue problem
69: */
70: PetscCall(EPSSetOperators(eps,A,NULL));
71: PetscCall(EPSSetProblemType(eps,EPS_HEP));
73: /*
74: Set solver parameters at runtime
75: */
76: PetscCall(EPSSetFromOptions(eps));
78: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79: Solve the eigensystem
80: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82: PetscCall(EPSSolve(eps));
84: /*
85: Optional: Get some information from the solver and display it
86: */
87: PetscCall(EPSGetType(eps,&type));
88: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type));
89: PetscCall(EPSGetStoppingTest(eps,&stop));
90: if (stop!=EPS_STOP_THRESHOLD) {
91: PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
92: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
93: } else {
94: PetscCall(EPSGetThreshold(eps,&thres,NULL));
95: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Using threshold: %.4g\n",(double)thres));
96: }
98: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99: Display solution and clean up
100: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
102: /* show detailed info unless -terse option is given by user */
103: PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
104: if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
105: else {
106: PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
107: PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
108: PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
109: PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
110: }
111: PetscCall(EPSDestroy(&eps));
112: PetscCall(MatDestroy(&A));
113: PetscCall(SlepcFinalize());
114: return 0;
115: }
117: /*TEST
119: testset:
120: args: -n 72 -eps_nev 4 -eps_ncv 20 -terse
121: output_file: output/ex2_1.out
122: requires: !single
123: test:
124: suffix: 1
125: test:
126: suffix: 2
127: requires: defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
128: args: -library_preload
130: testset:
131: args: -n 30 -eps_type ciss -eps_ciss_realmats -terse
132: requires: !single
133: output_file: output/ex2_ciss.out
134: filter: grep -v method
135: test:
136: suffix: ciss_1
137: nsize: 1
138: args: -rg_type interval -rg_interval_endpoints 1.1,1.25,-.1,.1
139: requires: complex
140: test:
141: suffix: ciss_1_hpddm
142: nsize: 1
143: args: -rg_type interval -rg_interval_endpoints 1.1,1.25 -st_ksp_type hpddm
144: requires: hpddm
145: test:
146: suffix: ciss_2
147: nsize: 2
148: args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2
149: test:
150: suffix: ciss_2_block
151: args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_blocksize 3 -eps_ciss_moments 2
152: requires: complex !__float128
153: test:
154: suffix: ciss_2_hpddm
155: nsize: 2
156: args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2 -eps_ciss_ksp_type hpddm
157: requires: hpddm
158: test:
159: suffix: ciss_2_kokkos
160: nsize: 2
161: args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -mat_type aijkokkos -st_pc_type redundant
162: requires: complex kokkos_kernels
163: test:
164: suffix: feast
165: args: -eps_type feast -eps_interval 1.1,1.25 -eps_ncv 64 -options_left 0
166: requires: feast
168: testset:
169: args: -n 30 -m 30 -eps_interval 3.9,4.15 -terse
170: output_file: output/ex2_3.out
171: filter: grep -v Solution
172: requires: !single
173: test:
174: suffix: 3
175: args: -st_type sinvert -st_pc_type cholesky
176: test:
177: suffix: 3_evsl
178: args: -eps_type evsl -eps_evsl_slices 6
179: requires: evsl
181: testset:
182: args: -n 45 -m 46 -eps_interval 4.54,4.57 -eps_ncv 24 -terse
183: output_file: output/ex2_4.out
184: filter: grep -v Solution | grep -v "Number of requested" | grep -v "Using threshold"
185: requires: !single
186: timeoutfactor: 2
187: test:
188: suffix: 4
189: args: -st_type sinvert -st_pc_type cholesky
190: test:
191: suffix: 4_filter
192: args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -st_filter_type {{filtlan chebyshev}}
193: requires: !__float128
194: test:
195: suffix: 4_filter_cuda
196: args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijcusparse -st_filter_type {{filtlan chebyshev}}
197: requires: cuda
198: test:
199: suffix: 4_filter_hip
200: args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijhipsparse -st_filter_type {{filtlan chebyshev}}
201: requires: hip
202: test:
203: suffix: 4_filter_kokkos
204: args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijkokkos -st_filter_type {{filtlan chebyshev}}
205: requires: hip kokkos_kernels
206: test:
207: suffix: 4_evsl
208: args: -eps_type evsl
209: requires: evsl
211: test:
212: args: -n 25 -m 24 -eps_threshold_absolute .25 -eps_smallest_magnitude -eps_ncv 10 -terse
213: suffix: 5
214: requires: !single
216: testset:
217: args: -n 25 -m 24 -st_type sinvert -terse
218: requires: double
219: test:
220: suffix: 6
221: args: -eps_threshold_absolute .2 -eps_target 0.01 -eps_type {{krylovschur subspace}}
222: filter: grep -v "Solution method"
223: test:
224: suffix: 6_rel_large
225: args: -eps_threshold_relative .98 -eps_target 8 -eps_ncv 12
226: test:
227: suffix: 6_rel_small
228: args: -eps_threshold_relative 3 -eps_ncv 8
229: requires: !complex
231: TEST*/