Date: 2022-08-09T09:05:37+00:00

Actual source code: test5.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[] = "Test EPS with different builds with a matrix loaded from a file.\n"
     12:   "This test is based on ex4.c in tutorials.\n"
     13:   "It loads test matrices available in PETSc's distribution.\n"
     14:   "Add -symm or -herm to select the symmetric/Hermitian matrix.\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:   char           filename[PETSC_MAX_PATH_LEN];
     23:   const char     *prefix,*scalar,*ints,*floats;
     24:   PetscReal      tol=PETSC_SMALL;
     25:   PetscViewer    viewer;
     26:   PetscBool      flg,symm;

     28:   SlepcInitialize(&argc,&argv,(char*)0,help);

     30:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     31:         Load the operator matrix that defines the eigensystem, Ax=kx
     32:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     33:   PetscOptionsHasName(NULL,NULL,"-symm",&symm);
     34:   PetscOptionsHasName(NULL,NULL,"-herm",&flg);
     35:   if (flg) symm=PETSC_TRUE;
     36: #if defined(PETSC_USE_COMPLEX)
     37:   prefix = symm? "hpd": "nh";
     38:   scalar = "complex";
     39: #else
     40:   prefix = symm? "spd": "ns";
     41:   scalar = "real";
     42: #endif
     43: #if defined(PETSC_USE_64BIT_INDICES)
     44:   ints   = "int64";
     45: #else
     46:   ints   = "int32";
     47: #endif
     48: #if defined(PETSC_USE_REAL_DOUBLE)
     49:   floats = "float64";
     50: #elif defined(PETSC_USE_REAL_SINGLE)
     51:   floats = "float32";
     52: #endif

     54:   PetscSNPrintf(filename,sizeof(filename),"%s/share/petsc/datafiles/matrices/%s-%s-%s-%s",PETSC_DIR,prefix,scalar,ints,floats);
     55:   PetscPrintf(PETSC_COMM_WORLD,"\nReading matrix from binary file...\n\n");
     56:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);
     57:   MatCreate(PETSC_COMM_WORLD,&A);
     58:   MatSetFromOptions(A);
     59:   MatLoad(A,viewer);
     60:   PetscViewerDestroy(&viewer);

     62:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     63:                      Create the eigensolver
     64:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     65:   EPSCreate(PETSC_COMM_WORLD,&eps);
     66:   EPSSetOperators(eps,A,NULL);
     67:   if (symm) EPSSetProblemType(eps,EPS_HEP);
     68:   else EPSSetProblemType(eps,EPS_NHEP);
     69:   EPSSetTolerances(eps,tol,PETSC_DEFAULT);
     70:   EPSSetFromOptions(eps);

     72:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     73:                 Solve the eigensystem and display solution
     74:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     75:   EPSSolve(eps);
     76:   EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
     77:   EPSDestroy(&eps);
     78:   MatDestroy(&A);
     79:   SlepcFinalize();
     80:   return 0;
     81: }

     83: /*TEST

     85:    build:
     86:       requires: !__float128

     88:    testset:
     89:       args: -eps_nev 3
     90:       requires: !complex
     91:       filter: sed -e "s/92073/92072/" | sed -e "s/80649/80648/" | sed -e "s/80647/80648/" | sed -e "s/45755/45756/"
     92:       output_file: output/test5_1.out
     93:       test:
     94:          suffix: 1
     95:          args: -eps_type {{krylovschur subspace arnoldi gd}}
     96:       test:
     97:          suffix: 1_power
     98:          args: -eps_type power -st_type sinvert -eps_target 7
     99:       test:
    100:          suffix: 1_jd
    101:          args: -eps_type jd -eps_jd_minv 3 -eps_jd_plusk 1
    102:       test:
    103:          suffix: 1_gd
    104:          args: -eps_type gd -eps_gd_minv 3 -eps_gd_plusk 1
    105:       test:
    106:          suffix: 1_gd2
    107:          args: -eps_type gd -eps_gd_double_expansion

    109:    testset:
    110:       args: -eps_nev 3
    111:       requires: double complex
    112:       output_file: output/test5_1_complex.out
    113:       test:
    114:          suffix: 1_complex
    115:          args: -eps_type {{krylovschur subspace arnoldi gd}}
    116:       test:
    117:          suffix: 1_power_complex
    118:          args: -eps_type power -st_type sinvert -eps_target 7
    119:       test:
    120:          suffix: 1_jd_complex
    121:          args: -eps_type jd -eps_jd_minv 3 -eps_jd_plusk 1
    122:       test:
    123:          suffix: 1_gd_complex
    124:          args: -eps_type gd -eps_gd_minv 3 -eps_gd_plusk 1
    125:       test:
    126:          suffix: 1_gd2_complex
    127:          args: -eps_type gd -eps_gd_double_expansion

    129:    testset:
    130:       args: -symm -eps_nev 4 -eps_smallest_real
    131:       requires: double !complex
    132:       output_file: output/test5_2.out
    133:       test:
    134:         suffix: 2_arpack
    135:         args: -eps_type arpack
    136:         requires: arpack
    137:       test:
    138:         suffix: 2_blopex
    139:         args: -eps_type blopex
    140:         requires: blopex
    141:       test:
    142:         suffix: 2_trlan
    143:         args: -eps_type trlan
    144:         requires: trlan

    146:    testset:
    147:       args: -symm -eps_nev 4 -eps_smallest_real
    148:       requires: double complex
    149:       output_file: output/test5_2_complex.out
    150:       test:
    151:         suffix: 2_blopex_complex
    152:         args: -eps_type blopex
    153:         requires: blopex

    155: TEST*/