Actual source code: test5.c

slepc-3.15.1 2021-05-28
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2021, 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;

 29:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

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

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

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

 76:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 77:                 Solve the eigensystem and display solution
 78:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 79:   EPSSolve(eps);
 80:   EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
 81:   EPSDestroy(&eps);
 82:   MatDestroy(&A);
 83:   SlepcFinalize();
 84:   return ierr;
 85: }

 87: /*TEST

 89:    build:
 90:       requires: !__float128

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

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

133:    testset:
134:       args: -symm -eps_nev 4 -eps_smallest_real
135:       requires: double !complex
136:       output_file: output/test5_2.out
137:       test:
138:         suffix: 2_arpack
139:         args: -eps_type arpack
140:         requires: arpack
141:       test:
142:         suffix: 2_blopex
143:         args: -eps_type blopex
144:         requires: blopex
145:       test:
146:         suffix: 2_blzpack
147:         args: -eps_type blzpack
148:         requires: blzpack
149:       test:
150:         suffix: 2_trlan
151:         args: -eps_type trlan
152:         requires: trlan

154:    testset:
155:       args: -symm -eps_nev 4 -eps_smallest_real
156:       requires: double complex
157:       output_file: output/test5_2_complex.out
158:       test:
159:         suffix: 2_blopex_complex
160:         args: -eps_type blopex
161:         requires: blopex

163: TEST*/