Actual source code: test1.c

slepc-3.17.2 2022-08-09
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;

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

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

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

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

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

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

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

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

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

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

 91:   EPSSolve(eps);

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

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

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

117: /*TEST

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

180:    testset:
181:       args: -n 18 -eps_type ciss -rg_interval_endpoints 20.8,22
182:       requires: !single
183:       output_file: output/test1_1_ciss.out
184:       test:
185:          suffix: 1_ciss
186:          args: -eps_ciss_extraction {{ritz hankel}}
187:       test:
188:          suffix: 1_ciss_ksps
189:          args: -eps_ciss_usest 0 -eps_ciss_integration_points 12
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

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

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

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

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

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

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

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

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

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

322: TEST*/