LCOV - code coverage report
Current view: top level - eps/tests - test6.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 38 38 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[] = "Diagonal eigenproblem.\n\n"
      12             :   "The command line options are:\n"
      13             :   "  -n <n>, where <n> = matrix dimension.\n"
      14             :   "  -seed <s>, where <s> = seed for random number generation.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18           7 : int main(int argc,char **argv)
      19             : {
      20           7 :   Mat            A;           /* problem matrix */
      21           7 :   EPS            eps;         /* eigenproblem solver context */
      22           7 :   Vec            v0;          /* initial vector */
      23           7 :   PetscRandom    rand;
      24           7 :   PetscReal      tol=PETSC_SMALL;
      25           7 :   PetscInt       n=30,i,Istart,Iend,seed=0x12345678;
      26             : 
      27           7 :   PetscFunctionBeginUser;
      28           7 :   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
      29             : 
      30           7 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      31           7 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%" PetscInt_FMT "\n\n",n));
      32             : 
      33           7 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      34           7 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
      35           7 :   PetscCall(MatSetFromOptions(A));
      36           7 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      37         217 :   for (i=Istart;i<Iend;i++) PetscCall(MatSetValue(A,i,i,i+1,INSERT_VALUES));
      38           7 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      39           7 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      40             : 
      41             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      42             :                       Solve the eigensystem
      43             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      44           7 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      45           7 :   PetscCall(EPSSetOperators(eps,A,NULL));
      46           7 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      47           7 :   PetscCall(EPSSetTolerances(eps,tol,PETSC_DEFAULT));
      48           7 :   PetscCall(EPSSetFromOptions(eps));
      49             :   /* set random initial vector */
      50           7 :   PetscCall(MatCreateVecs(A,&v0,NULL));
      51           7 :   PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&rand));
      52           7 :   PetscCall(PetscRandomSetFromOptions(rand));
      53           7 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-seed",&seed,NULL));
      54           7 :   PetscCall(PetscRandomSetSeed(rand,seed));
      55           7 :   PetscCall(PetscRandomSeed(rand));
      56           7 :   PetscCall(VecSetRandom(v0,rand));
      57           7 :   PetscCall(EPSSetInitialSpace(eps,1,&v0));
      58             :   /* call the solver */
      59           7 :   PetscCall(EPSSolve(eps));
      60             : 
      61             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      62             :                     Display solution and clean up
      63             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      64           7 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      65           7 :   PetscCall(EPSDestroy(&eps));
      66           7 :   PetscCall(MatDestroy(&A));
      67           7 :   PetscCall(VecDestroy(&v0));
      68           7 :   PetscCall(PetscRandomDestroy(&rand));
      69           7 :   PetscCall(SlepcFinalize());
      70             :   return 0;
      71             : }
      72             : 
      73             : /*TEST
      74             : 
      75             :    testset:
      76             :       args: -eps_nev 4
      77             :       requires: !single
      78             :       output_file: output/test6_1.out
      79             :       test:
      80             :          suffix: 1
      81             :          args: -eps_type {{krylovschur subspace arnoldi gd}}
      82             :       test:
      83             :          suffix: 1_power
      84             :          args: -eps_type power -eps_max_it 20000
      85             :       test:
      86             :          suffix: 1_gd2
      87             :          args: -eps_type gd -eps_gd_double_expansion
      88             :       test:
      89             :          suffix: 1_arpack
      90             :          args: -eps_type arpack
      91             :          requires: arpack
      92             :       test:
      93             :          suffix: 1_trlan
      94             :          args: -eps_type trlan
      95             :          requires: trlan
      96             : 
      97             : TEST*/

Generated by: LCOV version 1.14