Actual source code: test1.c

slepc-3.18.2 2023-01-26
Report Typos and Errors
  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;

 27:   SlepcInitialize(&argc,&argv,(char*)0,help);
 28:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
 29:   PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);
 30:   if (!flag) m=n;
 31:   N = n*m;
 32:   PetscPrintf(PETSC_COMM_WORLD,"\nGeneralized Symmetric Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m);
 33:   PetscOptionsGetBool(NULL,NULL,"-skiporth",&skiporth,NULL);

 35:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 36:      Compute the matrices that define the eigensystem, Ax=kBx
 37:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 39:   MatCreate(PETSC_COMM_WORLD,&A);
 40:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
 41:   MatSetFromOptions(A);
 42:   MatSetUp(A);

 44:   MatCreate(PETSC_COMM_WORLD,&B);
 45:   MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N);
 46:   MatSetFromOptions(B);
 47:   MatSetUp(B);

 49:   MatGetOwnershipRange(A,&Istart,&Iend);
 50:   for (II=Istart;II<Iend;II++) {
 51:     i = II/n; j = II-i*n;
 52:     if (i>0) MatSetValue(A,II,II-n,-1.0,INSERT_VALUES);
 53:     if (i<m-1) MatSetValue(A,II,II+n,-1.0,INSERT_VALUES);
 54:     if (j>0) MatSetValue(A,II,II-1,-1.0,INSERT_VALUES);
 55:     if (j<n-1) MatSetValue(A,II,II+1,-1.0,INSERT_VALUES);
 56:     MatSetValue(A,II,II,4.0,INSERT_VALUES);
 57:     MatSetValue(B,II,II,2.0/PetscLogScalar(II+2),INSERT_VALUES);
 58:   }

 60:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 61:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
 62:   MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
 63:   MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);
 64:   MatCreateVecs(B,&v,NULL);

 66:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 67:                 Create the eigensolver and set various options
 68:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 70:   EPSCreate(PETSC_COMM_WORLD,&eps);
 71:   EPSSetOperators(eps,A,B);
 72:   EPSSetProblemType(eps,EPS_GHEP);
 73:   EPSSetTolerances(eps,tol,PETSC_DEFAULT);
 74:   EPSSetConvergenceTest(eps,EPS_CONV_NORM);
 75:   EPSSetFromOptions(eps);

 77:   /* illustrate how to extract parameters from specific solver types */
 78:   PetscObjectTypeCompare((PetscObject)eps,EPSPOWER,&flag);
 79:   if (flag) {
 80:     EPSGetST(eps,&st);
 81:     PetscObjectTypeCompare((PetscObject)st,STSHIFT,&flag);
 82:     if (flag) {
 83:       EPSPowerGetShiftType(eps,&variant);
 84:       PetscPrintf(PETSC_COMM_WORLD,"Type of shifts used during power iteration: %s\n",EPSPowerShiftTypes[variant]);
 85:     }
 86:   }

 88:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 89:                       Solve the eigensystem
 90:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 92:   EPSSolve(eps);

 94:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 95:                     Display solution and clean up
 96:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 98:   EPSGetTolerances(eps,&tol,NULL);
 99:   EPSErrorView(eps,EPS_ERROR_BACKWARD,NULL);
100:   EPSGetConverged(eps,&nconv);
101:   if (nconv>1) {
102:     VecDuplicateVecs(v,nconv,&X);
103:     for (i=0;i<nconv;i++) EPSGetEigenvector(eps,i,X[i],NULL);
104:     if (!skiporth) VecCheckOrthonormality(X,nconv,NULL,nconv,B,NULL,&lev);
105:     if (lev<10*tol) PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality below the tolerance\n");
106:     else PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality: %g\n",(double)lev);
107:     VecDestroyVecs(nconv,&X);
108:   }

110:   EPSDestroy(&eps);
111:   MatDestroy(&A);
112:   MatDestroy(&B);
113:   VecDestroy(&v);
114:   SlepcFinalize();
115:   return 0;
116: }

118: /*TEST

120:    testset:
121:       args: -n 18 -eps_nev 4 -eps_max_it 1500
122:       requires: !single
123:       output_file: output/test1_1.out
124:       test:
125:          suffix: 1
126:          args: -eps_type {{krylovschur arnoldi gd jd lapack}}
127:       test:
128:          suffix: 1_subspace
129:          args: -eps_type subspace -eps_conv_rel
130:       test:
131:          suffix: 1_ks_nopurify
132:          args: -eps_purify 0
133:       test:
134:          suffix: 1_ks_trueres
135:          args: -eps_true_residual
136:       test:
137:          suffix: 1_ks_sinvert
138:          args: -st_type sinvert -eps_target 22
139:       test:
140:          suffix: 1_ks_cayley
141:          args: -st_type cayley -eps_target 22
142:       test:
143:          suffix: 1_lanczos
144:          args: -eps_type lanczos -eps_lanczos_reorthog full
145:       test:
146:          suffix: 1_gd2
147:          args: -eps_type gd -eps_gd_double_expansion
148:       test:
149:          suffix: 1_gd_borth
150:          args: -eps_type gd -eps_gd_borth
151:       test:
152:          suffix: 1_jd_borth
153:          args: -eps_type jd -eps_jd_borth
154:       test:
155:          suffix: 1_lobpcg
156:          args: -eps_type lobpcg -st_shift 22 -eps_largest_real
157:       test:
158:          suffix: 1_hpddm
159:          requires: hpddm
160:          args: -eps_type lobpcg -st_shift 22 -eps_largest_real -st_pc_type lu -st_ksp_type hpddm
161:       test:
162:          suffix: 1_cholesky
163:          args: -mat_type sbaij
164:       test:
165:          suffix: 1_scalapack
166:          nsize: {{1 2 3}}
167:          requires: scalapack
168:          args: -eps_type scalapack
169:       test:
170:          suffix: 1_elpa
171:          nsize: {{1 2 3}}
172:          requires: elpa
173:          args: -eps_type elpa
174:          filter: grep -v "Buffering level"
175:       test:
176:          suffix: 1_elemental
177:          nsize: {{1 2}}
178:          requires: elemental
179:          args: -eps_type elemental

181:    testset:
182:       args: -n 18 -eps_type ciss -rg_interval_endpoints 20.8,22
183:       requires: !single
184:       output_file: output/test1_1_ciss.out
185:       test:
186:          suffix: 1_ciss
187:          args: -eps_ciss_extraction {{ritz hankel}}
188:       test:
189:          suffix: 1_ciss_ksps
190:          args: -eps_ciss_usest 0 -eps_ciss_integration_points 12
191:       test:
192:          suffix: 1_ciss_gnhep
193:          args: -eps_gen_non_hermitian -skiporth
194:       test:
195:          suffix: 1_ciss_trapezoidal
196:          args: -eps_ciss_quadrule trapezoidal -eps_ciss_integration_points 24 -eps_ciss_extraction hankel -eps_ciss_delta 1e-10 -eps_tol 5e-11 -skiporth
197:       test:
198:          suffix: 1_ciss_cuda
199:          args: -mat_type aijcusparse -st_pc_factor_mat_solver_type cusparse
200:          requires: cuda

202:    testset:
203:       requires: !single
204:       args: -eps_tol 1e-10 -st_type sinvert -st_ksp_type preonly -st_pc_type cholesky
205:       test:
206:          suffix: 2
207:          args: -eps_interval .1,1.1
208:       test:
209:          suffix: 2_open
210:          args: -eps_interval -inf,1.1
211:       test:
212:          suffix: 2_parallel
213:          requires: mumps !complex
214:          nsize: 3
215:          args: -eps_interval .1,1.1 -eps_krylovschur_partitions 2 -st_pc_factor_mat_solver_type mumps -st_mat_mumps_icntl_13 1
216:          output_file: output/test1_2.out

218:    test:
219:       suffix: 3
220:       requires: !single
221:       args: -n 18 -eps_type power -eps_conv_rel -eps_nev 3

223:    test:
224:       suffix: 4
225:       requires: !single
226:       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}}

228:    testset:
229:       args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type icc
230:       output_file: output/test1_5.out
231:       test:
232:          suffix: 5_rqcg
233:          args: -eps_type rqcg
234:       test:
235:          suffix: 5_lobpcg
236:          args: -eps_type lobpcg -eps_lobpcg_blocksize 3
237:       test:
238:          suffix: 5_hpddm
239:          args: -eps_type lobpcg -eps_lobpcg_blocksize 3 -st_pc_type lu -st_ksp_type hpddm
240:          requires: hpddm
241:       test:
242:          suffix: 5_blopex
243:          args: -eps_type blopex -eps_conv_abs -st_shift 0.1
244:          requires: blopex

246:    testset:
247:       args: -n 18 -eps_nev 12 -eps_mpd 8 -eps_max_it 3000
248:       requires: !single
249:       output_file: output/test1_6.out
250:       test:
251:          suffix: 6
252:          args: -eps_type {{krylovschur arnoldi gd}}
253:       test:
254:          suffix: 6_lanczos
255:          args: -eps_type lanczos -eps_lanczos_reorthog full
256:       test:
257:          suffix: 6_subspace
258:          args: -eps_type subspace -eps_conv_rel

260:    testset:
261:       args: -n 18 -eps_nev 4 -eps_max_it 1500 -mat_type aijcusparse
262:       requires: cuda !single
263:       output_file: output/test1_1.out
264:       test:
265:          suffix: 7
266:          args: -eps_type {{krylovschur arnoldi gd jd}}
267:       test:
268:          suffix: 7_subspace
269:          args: -eps_type subspace -eps_conv_rel
270:       test:
271:          suffix: 7_ks_sinvert
272:          args: -st_type sinvert -eps_target 22
273:       test:
274:          suffix: 7_lanczos
275:          args: -eps_type lanczos -eps_lanczos_reorthog full
276:       test:
277:          suffix: 7_ciss
278:          args: -eps_type ciss -rg_interval_endpoints 20.8,22 -st_pc_factor_mat_solver_type cusparse
279:          output_file: output/test1_1_ciss.out

281:    testset:
282:       args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type sor -mat_type aijcusparse
283:       requires: cuda
284:       output_file: output/test1_5.out
285:       test:
286:          suffix: 8_rqcg
287:          args: -eps_type rqcg
288:       test:
289:          suffix: 8_lobpcg
290:          args: -eps_type lobpcg -eps_lobpcg_blocksize 3

292:    testset:
293:       nsize: 2
294:       args: -n 18 -eps_nev 7 -eps_ncv 32 -ds_parallel synchronized
295:       filter: grep -v "orthogonality"
296:       output_file: output/test1_9.out
297:       test:
298:          suffix: 9_ks_ghep
299:          args: -eps_gen_hermitian -st_pc_type redundant -st_type sinvert
300:       test:
301:          suffix: 9_ks_gnhep
302:          args: -eps_gen_non_hermitian -st_pc_type redundant -st_type sinvert
303:       test:
304:          suffix: 9_ks_ghiep
305:          args: -eps_gen_indefinite -st_pc_type redundant -st_type sinvert
306:          requires: !single
307:       test:
308:          suffix: 9_lobpcg_ghep
309:          args: -eps_gen_hermitian -eps_type lobpcg -eps_max_it 200 -eps_lobpcg_blocksize 6
310:          requires: !single
311:          timeoutfactor: 2
312:       test:
313:          suffix: 9_jd_gnhep
314:          args: -eps_gen_non_hermitian -eps_type jd -eps_target 0 -eps_ncv 64
315:          requires: !single
316:          timeoutfactor: 2

318:    test:
319:       suffix: 10_feast
320:       args: -n 25 -eps_type feast -eps_interval .95,1.1 -eps_conv_rel -eps_tol 1e-6
321:       requires: feast

323: TEST*/