Date: 2020-01-13T12:00:34+00:00

Actual source code: test1.c
slepc-3.12.2 2020-01-13
Report Typos and Errors

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

     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++) {
    103:       EPSGetEigenvector(eps,i,X[i],NULL);
    104:     }
    105:     VecCheckOrthogonality(X,nconv,NULL,nconv,B,NULL,&lev);
    106:     if (lev<10*tol) {
    107:       PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality below the tolerance\n");
    108:     } else {
    109:       PetscPrintf(PETSC_COMM_WORLD,"Level of orthogonality: %g\n",(double)lev);
    110:     }
    111:     VecDestroyVecs(nconv,&X);
    112:   }

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

    122: /*TEST

    124:    testset:
    125:       args: -n 18 -eps_nev 4 -eps_max_it 1500
    126:       requires: !single
    127:       output_file: output/test1_1.out
    128:       test:
    129:          suffix: 1
    130:          args: -eps_type {{krylovschur subspace arnoldi gd jd lapack}}
    131:       test:
    132:          suffix: 1_ks_nopurify
    133:          args: -eps_purify 0
    134:       test:
    135:          suffix: 1_ks_trueres
    136:          args: -eps_true_residual
    137:       test:
    138:          suffix: 1_ks_sinvert
    139:          args: -st_type sinvert -eps_target 22
    140:       test:
    141:          suffix: 1_ks_cayley
    142:          args: -st_type cayley -eps_target 22
    143:       test:
    144:          suffix: 1_lanczos
    145:          args: -eps_type lanczos -eps_lanczos_reorthog full
    146:       test:
    147:          suffix: 1_gd2
    148:          args: -eps_type gd -eps_gd_double_expansion
    149:       test:
    150:          suffix: 1_gd_borth
    151:          args: -eps_type gd -eps_gd_borth
    152:       test:
    153:          suffix: 1_jd_borth
    154:          args: -eps_type jd -eps_jd_borth
    155:       test:
    156:          suffix: 1_ciss
    157:          args: -eps_type ciss -rg_interval_endpoints 20.8,22 -eps_largest_real
    158:       test:
    159:          suffix: 1_ciss_trapezoidal
    160:          args: -eps_type ciss -rg_interval_endpoints 20.8,22 -eps_largest_real -eps_ciss_quadrule trapezoidal -eps_ciss_integration_points 24 -eps_ciss_extraction hankel -eps_ciss_delta 1e-10 -eps_tol 1e-11
    161:       test:
    162:          suffix: 1_lobpcg
    163:          args: -eps_type lobpcg -st_shift 22 -eps_largest_real
    164:       test:
    165:          suffix: 1_cholesky
    166:          args: -mat_type sbaij

    168:    testset:
    169:       requires: !single
    170:       args: -eps_tol 1e-10 -st_type sinvert -st_ksp_type preonly -st_pc_type cholesky
    171:       test:
    172:          suffix: 2
    173:          args: -eps_interval .1,1.1
    174:       test:
    175:          suffix: 2_open
    176:          args: -eps_interval -inf,1.1
    177:       test:
    178:          suffix: 2_parallel
    179:          requires: mumps
    180:          nsize: 3
    181:          args: -eps_interval .1,1.1 -eps_krylovschur_partitions 2 -st_pc_factor_mat_solver_type mumps -mat_mumps_icntl_13 1
    182:          output_file: output/test1_2.out

    184:    test:
    185:       suffix: 3
    186:       requires: !single
    187:       args: -n 18 -eps_type power -eps_nev 3

    189:    test:
    190:       suffix: 4
    191:       requires: !single
    192:       args: -n 18 -eps_type power -eps_nev 3 -st_type sinvert -eps_target 1.149 -eps_power_shift_type {{constant rayleigh wilkinson}}

    194:    testset:
    195:       args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type icc
    196:       output_file: output/test1_5.out
    197:       test:
    198:          suffix: 5_rqcg
    199:          args: -eps_type rqcg
    200:       test:
    201:          suffix: 5_lobpcg
    202:          args: -eps_type lobpcg -eps_lobpcg_blocksize 3
    203:          requires: !single
    204:       test:
    205:          suffix: 5_blopex
    206:          args: -eps_type blopex -eps_conv_abs -st_shift 0.1
    207:          requires: blopex

    209:    testset:
    210:       args: -n 18 -eps_nev 12 -eps_mpd 8 -eps_max_it 3000
    211:       requires: !single
    212:       output_file: output/test1_6.out
    213:       test:
    214:          suffix: 6
    215:          args: -eps_type {{krylovschur subspace arnoldi gd}}
    216:       test:
    217:          suffix: 6_lanczos
    218:          args: -eps_type lanczos -eps_lanczos_reorthog full

    220:    testset:
    221:       args: -n 18 -eps_nev 4 -eps_max_it 1500 -mat_type aijcusparse
    222:       requires: cuda !single
    223:       output_file: output/test1_1.out
    224:       test:
    225:          suffix: 7
    226:          args: -eps_type {{krylovschur subspace arnoldi gd jd}}
    227:       test:
    228:          suffix: 7_ks_sinvert
    229:          args: -st_type sinvert -eps_target 22
    230:       test:
    231:          suffix: 7_lanczos
    232:          args: -eps_type lanczos -eps_lanczos_reorthog full
    233:       test:
    234:          suffix: 7_ciss
    235:          args: -eps_type ciss -rg_interval_endpoints 20.8,22 -eps_largest_real

    237:    testset:
    238:       args: -n 18 -eps_nev 3 -eps_smallest_real -eps_max_it 500 -st_pc_type sor -mat_type aijcusparse
    239:       requires: cuda
    240:       output_file: output/test1_5.out
    241:       test:
    242:          suffix: 8_rqcg
    243:          args: -eps_type rqcg
    244:       test:
    245:          suffix: 8_lobpcg
    246:          args: -eps_type lobpcg -eps_lobpcg_blocksize 3

    248:    testset:
    249:       nsize: 2
    250:       args: -n 18 -eps_nev 7 -eps_ncv 32 -ds_parallel synchronized
    251:       requires: !single
    252:       filter: grep -v "orthogonality"
    253:       output_file: output/test1_9.out
    254:       test:
    255:          suffix: 9_ks_ghep
    256:          args: -eps_gen_hermitian -st_pc_type redundant -st_type sinvert
    257:       test:
    258:          suffix: 9_ks_gnhep
    259:          args: -eps_gen_non_hermitian -st_pc_type redundant -st_type sinvert
    260:       test:
    261:          suffix: 9_ks_ghiep
    262:          args: -eps_gen_indefinite -st_pc_type redundant -st_type sinvert
    263:       test:
    264:          suffix: 9_lobpcg_ghep
    265:          args: -eps_gen_hermitian -eps_type lobpcg -eps_max_it 200 -eps_lobpcg_blocksize 6
    266:          timeoutfactor: 2
    267:       test:
    268:          suffix: 9_jd_gnhep
    269:          args: -eps_gen_non_hermitian -eps_type jd -eps_target 0 -eps_ncv 64
    270:          timeoutfactor: 2

    272: TEST*/