Date: 2021-02-01T14:41:59+00:00

Actual source code: test1.c
slepc-3.14.2 2021-02-01
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2020, 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=1000*PETSC_MACHINE_EPSILON;
     22:   PetscInt          N,n=45,m,Istart,Iend,II,i,j,nconv;
     23:   PetscBool         flag,skiporth=PETSC_FALSE;
     24:   EPSPowerShiftType variant;
     25:   PetscErrorCode    ierr;

     27:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     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=%D (%Dx%D 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++) {
    104:       EPSGetEigenvector(eps,i,X[i],NULL);
    105:     }
    106:     if (!skiporth) { VecCheckOrthonormality(X,nconv,NULL,nconv,B,NULL,&lev); }
    107:     if (lev<10*tol) {
    108:       PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality below the tolerance\n");
    109:     } else {
    110:       PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality: %g\n",(double)lev);
    111:     }
    112:     VecDestroyVecs(nconv,&X);
    113:   }

    115:   EPSDestroy(&eps);
    116:   MatDestroy(&A);
    117:   MatDestroy(&B);
    118:   VecDestroy(&v);
    119:   SlepcFinalize();
    120:   return ierr;
    121: }

    123: /*TEST

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

    186:    testset:
    187:       args: -n 18 -eps_type ciss -rg_interval_endpoints 20.8,22
    188:       requires: double
    189:       output_file: output/test1_1_ciss.out
    190:       test:
    191:          suffix: 1_ciss
    192:       test:
    193:          suffix: 1_ciss_trapezoidal
    194:          args: -eps_ciss_quadrule trapezoidal -eps_ciss_integration_points 24 -eps_ciss_extraction hankel -eps_ciss_delta 1e-10 -eps_tol 5e-11 -skiporth
    195:       test:
    196:          suffix: 1_ciss_cuda
    197:          args: -mat_type aijcusparse -st_pc_factor_mat_solver_type cusparse
    198:          requires: cuda

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

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

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

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

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

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

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

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

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

    320: TEST*/