LCOV - code coverage report
Current view: top level - eps/tests - test5.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 35 35 100.0 %
Date: 2024-12-18 00:42:09 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : 
      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";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18          11 : int main(int argc,char **argv)
      19             : {
      20          11 :   Mat            A;               /* operator matrix */
      21          11 :   EPS            eps;             /* eigenproblem solver context */
      22          11 :   char           filename[PETSC_MAX_PATH_LEN];
      23          11 :   const char     *prefix,*scalar,*ints,*floats;
      24          11 :   PetscReal      tol=PETSC_SMALL;
      25          11 :   PetscViewer    viewer;
      26          11 :   PetscBool      flg,symm;
      27             : 
      28          11 :   PetscFunctionBeginUser;
      29          11 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      30             : 
      31             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      32             :         Load the operator matrix that defines the eigensystem, Ax=kx
      33             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      34          11 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-symm",&symm));
      35          11 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-herm",&flg));
      36          11 :   if (flg) symm=PETSC_TRUE;
      37             : #if defined(PETSC_USE_COMPLEX)
      38             :   prefix = symm? "hpd": "nh";
      39             :   scalar = "complex";
      40             : #else
      41          11 :   prefix = symm? "spd": "ns";
      42          11 :   scalar = "real";
      43             : #endif
      44             : #if defined(PETSC_USE_64BIT_INDICES)
      45             :   ints   = "int64";
      46             : #else
      47          11 :   ints   = "int32";
      48             : #endif
      49             : #if defined(PETSC_USE_REAL_DOUBLE)
      50          11 :   floats = "float64";
      51             : #elif defined(PETSC_USE_REAL_SINGLE)
      52             :   floats = "float32";
      53             : #endif
      54             : 
      55          11 :   PetscCall(PetscSNPrintf(filename,sizeof(filename),"%s/share/petsc/datafiles/matrices/%s-%s-%s-%s",PETSC_DIR,prefix,scalar,ints,floats));
      56          11 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nReading matrix from binary file...\n\n"));
      57          11 :   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
      58          11 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      59          11 :   PetscCall(MatSetFromOptions(A));
      60          11 :   PetscCall(MatLoad(A,viewer));
      61          11 :   PetscCall(PetscViewerDestroy(&viewer));
      62             : 
      63             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      64             :                      Create the eigensolver
      65             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      66          11 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      67          11 :   PetscCall(EPSSetOperators(eps,A,NULL));
      68          11 :   if (symm) PetscCall(EPSSetProblemType(eps,EPS_HEP));
      69           8 :   else PetscCall(EPSSetProblemType(eps,EPS_NHEP));
      70          11 :   PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
      71          11 :   PetscCall(EPSSetFromOptions(eps));
      72             : 
      73             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      74             :                 Solve the eigensystem and display solution
      75             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      76          11 :   PetscCall(EPSSolve(eps));
      77          11 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      78          11 :   PetscCall(EPSDestroy(&eps));
      79          11 :   PetscCall(MatDestroy(&A));
      80          11 :   PetscCall(SlepcFinalize());
      81             :   return 0;
      82             : }
      83             : 
      84             : /*TEST
      85             : 
      86             :    build:
      87             :       requires: !__float128
      88             : 
      89             :    testset:
      90             :       args: -eps_nev 3
      91             :       requires: !complex
      92             :       filter: sed -e "s/92073/92072/" | sed -e "s/80649/80648/" | sed -e "s/80647/80648/" | sed -e "s/45755/45756/"
      93             :       output_file: output/test5_1.out
      94             :       test:
      95             :          suffix: 1
      96             :          args: -eps_type {{krylovschur subspace arnoldi gd}}
      97             :       test:
      98             :          suffix: 1_power
      99             :          args: -eps_type power -st_type sinvert -eps_target 7
     100             :       test:
     101             :          suffix: 1_jd
     102             :          args: -eps_type jd -eps_jd_minv 3 -eps_jd_plusk 1
     103             :       test:
     104             :          suffix: 1_gd
     105             :          args: -eps_type gd -eps_gd_minv 3 -eps_gd_plusk 1
     106             :       test:
     107             :          suffix: 1_gd2
     108             :          args: -eps_type gd -eps_gd_double_expansion
     109             : 
     110             :    testset:
     111             :       args: -eps_nev 3
     112             :       requires: double complex
     113             :       output_file: output/test5_1_complex.out
     114             :       test:
     115             :          suffix: 1_complex
     116             :          args: -eps_type {{krylovschur subspace arnoldi gd}}
     117             :       test:
     118             :          suffix: 1_power_complex
     119             :          args: -eps_type power -st_type sinvert -eps_target 7
     120             :       test:
     121             :          suffix: 1_jd_complex
     122             :          args: -eps_type jd -eps_jd_minv 3 -eps_jd_plusk 1 -eps_max_it 2000
     123             :       test:
     124             :          suffix: 1_gd_complex
     125             :          args: -eps_type gd -eps_gd_minv 3 -eps_gd_plusk 1
     126             :       test:
     127             :          suffix: 1_gd2_complex
     128             :          args: -eps_type gd -eps_gd_double_expansion
     129             : 
     130             :    testset:
     131             :       args: -symm -eps_nev 4 -eps_smallest_real
     132             :       requires: double !complex
     133             :       output_file: output/test5_2.out
     134             :       test:
     135             :         suffix: 2_arpack
     136             :         args: -eps_type arpack
     137             :         requires: arpack
     138             :       test:
     139             :         suffix: 2_blopex
     140             :         args: -eps_type blopex
     141             :         requires: blopex
     142             :       test:
     143             :         suffix: 2_trlan
     144             :         args: -eps_type trlan
     145             :         requires: trlan
     146             : 
     147             :    testset:
     148             :       args: -symm -eps_nev 4 -eps_smallest_real
     149             :       requires: double complex
     150             :       output_file: output/test5_2_complex.out
     151             :       test:
     152             :         suffix: 2_blopex_complex
     153             :         args: -eps_type blopex
     154             :         requires: blopex
     155             : 
     156             : TEST*/

Generated by: LCOV version 1.14