LCOV - code coverage report
Current view: top level - eps/tests - test2.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 54 54 100.0 %
Date: 2024-05-04 00:30:31 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[] = "Tests multiple calls to EPSSolve with the same matrix.\n\n";
      12             : 
      13             : #include <slepceps.h>
      14             : 
      15          19 : int main(int argc,char **argv)
      16             : {
      17          19 :   Mat            A;           /* problem matrix */
      18          19 :   EPS            eps;         /* eigenproblem solver context */
      19          19 :   ST             st;
      20          19 :   PetscReal      tol=PetscMax(1000*PETSC_MACHINE_EPSILON,1e-9);
      21          19 :   PetscInt       n=30,i,Istart,Iend;
      22          19 :   PetscBool      flg;
      23          19 :   EPSLanczosReorthogType reorth;
      24             : 
      25          19 :   PetscFunctionBeginUser;
      26          19 :   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
      27             : 
      28          19 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      29          19 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%" PetscInt_FMT "\n\n",n));
      30             : 
      31             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      32             :      Compute the operator matrix that defines the eigensystem, Ax=kx
      33             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      34             : 
      35          19 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      36          19 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
      37          19 :   PetscCall(MatSetFromOptions(A));
      38             : 
      39          19 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      40         507 :   for (i=Istart;i<Iend;i++) {
      41         488 :     if (i>0) PetscCall(MatSetValue(A,i,i-1,-1.0,INSERT_VALUES));
      42         488 :     if (i<n-1) PetscCall(MatSetValue(A,i,i+1,-1.0,INSERT_VALUES));
      43         488 :     PetscCall(MatSetValue(A,i,i,2.0,INSERT_VALUES));
      44             :   }
      45          19 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      46          19 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      47             : 
      48             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      49             :                         Create the eigensolver
      50             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      51          19 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      52          19 :   PetscCall(EPSSetOperators(eps,A,NULL));
      53          19 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      54          19 :   PetscCall(EPSSetTolerances(eps,tol,PETSC_DEFAULT));
      55          19 :   PetscCall(EPSSetFromOptions(eps));
      56             : 
      57             :   /* illustrate how to extract parameters from specific solver types */
      58          19 :   PetscCall(PetscObjectTypeCompare((PetscObject)eps,EPSLANCZOS,&flg));
      59          19 :   if (flg) {
      60           5 :     PetscCall(EPSLanczosGetReorthog(eps,&reorth));
      61           5 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Reorthogonalization type used in Lanczos: %s\n",EPSLanczosReorthogTypes[reorth]));
      62             :   }
      63             : 
      64             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      65             :                     Solve for largest eigenvalues
      66             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      67          19 :   PetscCall(EPSSetWhichEigenpairs(eps,EPS_LARGEST_REAL));
      68          19 :   PetscCall(EPSSolve(eps));
      69          19 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - Largest eigenvalues - - -\n"));
      70          19 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      71             : 
      72             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      73             :                     Solve for smallest eigenvalues
      74             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      75          19 :   PetscCall(EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL));
      76          19 :   PetscCall(EPSSolve(eps));
      77          19 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - Smallest eigenvalues - - -\n"));
      78          19 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      79             : 
      80             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      81             :                     Solve for interior eigenvalues (target=2.1)
      82             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      83          19 :   PetscCall(EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE));
      84          19 :   PetscCall(EPSSetTarget(eps,2.1));
      85          19 :   PetscCall(PetscObjectTypeCompare((PetscObject)eps,EPSLANCZOS,&flg));
      86          19 :   if (flg) {
      87           5 :     PetscCall(EPSGetST(eps,&st));
      88           5 :     PetscCall(STSetType(st,STSINVERT));
      89             :   } else {
      90          14 :     PetscCall(PetscObjectTypeCompare((PetscObject)eps,EPSKRYLOVSCHUR,&flg));
      91          14 :     if (!flg) PetscCall(PetscObjectTypeCompare((PetscObject)eps,EPSARNOLDI,&flg));
      92          14 :     if (flg) PetscCall(EPSSetExtraction(eps,EPS_HARMONIC));
      93             :   }
      94          19 :   PetscCall(EPSSolve(eps));
      95          19 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - Interior eigenvalues - - -\n"));
      96          19 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      97             : 
      98          19 :   PetscCall(EPSDestroy(&eps));
      99          19 :   PetscCall(MatDestroy(&A));
     100          19 :   PetscCall(SlepcFinalize());
     101             :   return 0;
     102             : }
     103             : 
     104             : /*TEST
     105             : 
     106             :    testset:
     107             :       args: -eps_nev 4
     108             :       requires: !single
     109             :       output_file: output/test2_1.out
     110             :       test:
     111             :          suffix: 1
     112             :          args: -eps_type {{arnoldi gd jd lapack}}
     113             :       test:
     114             :          suffix: 1_gd2
     115             :          args: -eps_type gd -eps_gd_double_expansion
     116             :          timeoutfactor: 2
     117             :       test:
     118             :          suffix: 1_krylovschur
     119             :          args: -eps_type krylovschur -eps_krylovschur_locking {{0 1}}
     120             :       test:
     121             :          suffix: 1_scalapack
     122             :          requires: scalapack
     123             :          args: -eps_type scalapack
     124             :       test:
     125             :          suffix: 1_elpa
     126             :          requires: elpa
     127             :          args: -eps_type elpa
     128             :       test:
     129             :          suffix: 1_elemental
     130             :          requires: elemental
     131             :          args: -eps_type elemental
     132             : 
     133             :    testset:
     134             :       args: -eps_type lanczos -eps_nev 4
     135             :       requires: !single
     136             :       filter: grep -v "Lanczos"
     137             :       output_file: output/test2_1.out
     138             :       test:
     139             :          suffix: 2
     140             :          args: -eps_lanczos_reorthog {{local full periodic partial}}
     141             :       test:
     142             :          suffix: 2_selective
     143             :          args: -eps_lanczos_reorthog selective
     144             :          requires: !defined(PETSCTEST_VALGRIND)
     145             : 
     146             :    testset:
     147             :       args: -n 32 -eps_nev 4
     148             :       requires: !single
     149             :       output_file: output/test2_3.out
     150             :       test:
     151             :          nsize: 2
     152             :          suffix: 3
     153             :          args: -eps_type {{krylovschur lapack}}
     154             :       test:
     155             :          nsize: 2
     156             :          suffix: 3_gd
     157             :          args: -eps_type gd -eps_gd_krylov_start
     158             :          timeoutfactor: 2
     159             :       test:
     160             :          suffix: 3_jd
     161             :          args: -eps_type jd -eps_jd_krylov_start -eps_ncv 18
     162             : 
     163             :    testset:
     164             :       args: -eps_nev 4 -mat_type aijcusparse
     165             :       requires: cuda !single
     166             :       output_file: output/test2_1.out
     167             :       test:
     168             :          suffix: 4_cuda
     169             :          args: -eps_type {{krylovschur arnoldi gd jd}}
     170             : 
     171             : TEST*/

Generated by: LCOV version 1.14