LCOV - code coverage report
Current view: top level - eps/tests - test18.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 44 48 91.7 %
Date: 2024-12-18 00:51:33 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[] = "Symmetric-indefinite eigenproblem.\n\n"
      12             :   "The command line options are:\n"
      13             :   "  -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
      14             :   "  -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18           4 : int main(int argc,char **argv)
      19             : {
      20           4 :   Mat            A,B;             /* problem matrices */
      21           4 :   EPS            eps;             /* eigenproblem solver context */
      22           4 :   PetscInt       N,n=10,m,Istart,Iend,II,nev,i,j;
      23           4 :   PetscBool      flag,terse;
      24             : 
      25           4 :   PetscFunctionBeginUser;
      26           4 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      27           4 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      28           4 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
      29           4 :   if (!flag) m=n;
      30           4 :   N = n*m;
      31           4 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nSymmetric-indefinite eigenproblem, N=%" PetscInt_FMT "\n\n",N));
      32             : 
      33             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      34             :           Compute the matrices that define the eigensystem, Ax=kBx
      35             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      36             : 
      37           4 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      38           4 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
      39           4 :   PetscCall(MatSetFromOptions(A));
      40             : 
      41           4 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
      42           4 :   PetscCall(MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N));
      43           4 :   PetscCall(MatSetFromOptions(B));
      44             : 
      45           4 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      46         424 :   for (II=Istart;II<Iend;II++) {
      47         420 :     i = II/n; j = II-i*n;
      48         420 :     if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
      49         420 :     if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
      50         420 :     if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
      51         420 :     if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
      52         420 :     PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
      53         420 :     PetscCall(MatSetValue(B,II,N-II-1,1.0,INSERT_VALUES));
      54             :   }
      55             : 
      56           4 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      57           4 :   PetscCall(MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY));
      58           4 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      59           4 :   PetscCall(MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY));
      60             : 
      61             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      62             :                 Create the eigensolver and set various options
      63             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      64             : 
      65           4 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      66           4 :   PetscCall(EPSSetOperators(eps,A,B));
      67           4 :   PetscCall(EPSSetProblemType(eps,EPS_GHIEP));
      68           4 :   PetscCall(EPSSetFromOptions(eps));
      69             : 
      70             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      71             :                       Solve the eigensystem
      72             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      73             : 
      74           4 :   PetscCall(EPSSolve(eps));
      75           4 :   PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
      76           4 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
      77             : 
      78             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      79             :                     Display solution and clean up
      80             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      81             : 
      82             :   /* show detailed info unless -terse option is given by user */
      83           4 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
      84           4 :   if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      85             :   else {
      86           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
      87           0 :     PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
      88           0 :     PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
      89           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
      90             :   }
      91             : 
      92           4 :   PetscCall(EPSDestroy(&eps));
      93           4 :   PetscCall(MatDestroy(&A));
      94           4 :   PetscCall(MatDestroy(&B));
      95           4 :   PetscCall(SlepcFinalize());
      96             :   return 0;
      97             : }
      98             : 
      99             : /*TEST
     100             : 
     101             :    testset:
     102             :       args: -eps_nev 4 -eps_ncv 12 -terse -st_type sinvert -eps_krylovschur_restart .3
     103             :       requires: !single
     104             :       output_file: output/test18_1.out
     105             :       test:
     106             :          suffix: 1_ks
     107             :       test:
     108             :          suffix: 1_ks_gnhep
     109             :          args: -eps_gen_non_hermitian
     110             :          requires: !__float128
     111             :       test:
     112             :          suffix: 2_cuda_ks
     113             :          args: -mat_type aijcusparse
     114             :          requires: cuda
     115             :       test:
     116             :          suffix: 2_cuda_ks_gnhep
     117             :          args: -eps_gen_non_hermitian -mat_type aijcusparse
     118             :          requires: cuda
     119             :       test:
     120             :          suffix: 2_hip_ks
     121             :          args: -mat_type aijhipsparse
     122             :          requires: hip
     123             :       test:
     124             :          suffix: 2_hip_ks_gnhep
     125             :          args: -eps_gen_non_hermitian -mat_type aijhipsparse
     126             :          requires: hip
     127             : 
     128             :    testset:
     129             :       args: -n 10 -m 11 -eps_target 0.2 -eps_harmonic -eps_nev 2 -terse
     130             :       filter: sed -e "s/[+-]0\.0*i//g"
     131             :       output_file: output/test18_2.out
     132             :       test:
     133             :          suffix: 2_gd
     134             :          args: -eps_type gd -eps_ncv 8
     135             :          requires: !single
     136             :       test:
     137             :          suffix: 2_jd
     138             :          args: -eps_type jd -st_ksp_type bcgs -eps_ncv 10
     139             :          requires: double
     140             : 
     141             : TEST*/

Generated by: LCOV version 1.14