GCC Code Coverage Report


Directory: ./
File: src/eps/tests/test5.c
Date: 2025-10-04 04:19:13
Exec Total Coverage
Lines: 38 39 97.4%
Functions: 1 1 100.0%
Branches: 95 150 63.3%

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