| 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[] = "Standard symmetric eigenproblem corresponding to the Laplacian operator in 2 dimensions.\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 | 178 | int main(int argc,char **argv) | |
| 19 | { | ||
| 20 | 178 | Mat A; /* operator matrix */ | |
| 21 | 178 | EPS eps; /* eigenproblem solver context */ | |
| 22 | 178 | EPSType type; | |
| 23 | 178 | EPSStop stop; | |
| 24 | 178 | PetscReal thres; | |
| 25 | 178 | PetscInt N,n=10,m,Istart,Iend,II,nev,i,j; | |
| 26 | 178 | PetscBool flag,terse; | |
| 27 | |||
| 28 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
178 | PetscFunctionBeginUser; |
| 29 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(SlepcInitialize(&argc,&argv,NULL,help)); |
| 30 | |||
| 31 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL)); |
| 32 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag)); |
| 33 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
178 | if (!flag) m=n; |
| 34 | 178 | N = n*m; | |
| 35 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m)); |
| 36 | |||
| 37 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 38 | Compute the operator matrix that defines the eigensystem, Ax=kx | ||
| 39 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ | ||
| 40 | |||
| 41 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatCreate(PETSC_COMM_WORLD,&A)); |
| 42 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N)); |
| 43 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatSetFromOptions(A)); |
| 44 | |||
| 45 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatGetOwnershipRange(A,&Istart,&Iend)); |
| 46 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
303988 | for (II=Istart;II<Iend;II++) { |
| 47 | 303810 | i = II/n; j = II-i*n; | |
| 48 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
303810 | if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES)); |
| 49 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
303810 | if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES)); |
| 50 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
303810 | if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES)); |
| 51 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
303810 | if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES)); |
| 52 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
303810 | PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES)); |
| 53 | } | ||
| 54 | |||
| 55 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY)); |
| 56 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY)); |
| 57 | |||
| 58 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 59 | Create the eigensolver and set various options | ||
| 60 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ | ||
| 61 | |||
| 62 | /* | ||
| 63 | Create eigensolver context | ||
| 64 | */ | ||
| 65 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps)); |
| 66 | |||
| 67 | /* | ||
| 68 | Set operators. In this case, it is a standard eigenvalue problem | ||
| 69 | */ | ||
| 70 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSSetOperators(eps,A,NULL)); |
| 71 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSSetProblemType(eps,EPS_HEP)); |
| 72 | |||
| 73 | /* | ||
| 74 | Set solver parameters at runtime | ||
| 75 | */ | ||
| 76 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSSetFromOptions(eps)); |
| 77 | |||
| 78 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 79 | Solve the eigensystem | ||
| 80 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ | ||
| 81 | |||
| 82 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSSolve(eps)); |
| 83 | |||
| 84 | /* | ||
| 85 | Optional: Get some information from the solver and display it | ||
| 86 | */ | ||
| 87 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSGetType(eps,&type)); |
| 88 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type)); |
| 89 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSGetStoppingTest(eps,&stop)); |
| 90 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
178 | if (stop!=EPS_STOP_THRESHOLD) { |
| 91 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
138 | PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL)); |
| 92 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
138 | PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev)); |
| 93 | } else { | ||
| 94 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
40 | PetscCall(EPSGetThreshold(eps,&thres,NULL)); |
| 95 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
40 | PetscCall(PetscPrintf(PETSC_COMM_WORLD," Using threshold: %.4g\n",(double)thres)); |
| 96 | } | ||
| 97 | |||
| 98 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 99 | Display solution and clean up | ||
| 100 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ | ||
| 101 | |||
| 102 | /* show detailed info unless -terse option is given by user */ | ||
| 103 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse)); |
| 104 |
5/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
178 | if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL)); |
| 105 | else { | ||
| 106 | ✗ | PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL)); | |
| 107 | ✗ | PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD)); | |
| 108 | ✗ | PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD)); | |
| 109 | ✗ | PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD)); | |
| 110 | } | ||
| 111 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(EPSDestroy(&eps)); |
| 112 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
178 | PetscCall(MatDestroy(&A)); |
| 113 |
3/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
178 | PetscCall(SlepcFinalize()); |
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | /*TEST | ||
| 118 | |||
| 119 | testset: | ||
| 120 | args: -n 72 -eps_nev 4 -eps_ncv 20 -terse | ||
| 121 | output_file: output/ex2_1.out | ||
| 122 | requires: !single | ||
| 123 | test: | ||
| 124 | suffix: 1 | ||
| 125 | test: | ||
| 126 | suffix: 2 | ||
| 127 | requires: defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES) | ||
| 128 | args: -library_preload | ||
| 129 | |||
| 130 | testset: | ||
| 131 | args: -n 30 -eps_type ciss -eps_ciss_realmats -terse | ||
| 132 | requires: !single | ||
| 133 | output_file: output/ex2_ciss.out | ||
| 134 | filter: grep -v method | ||
| 135 | test: | ||
| 136 | suffix: ciss_1 | ||
| 137 | nsize: 1 | ||
| 138 | args: -rg_type interval -rg_interval_endpoints 1.1,1.25,-.1,.1 | ||
| 139 | requires: complex | ||
| 140 | test: | ||
| 141 | suffix: ciss_1_hpddm | ||
| 142 | nsize: 1 | ||
| 143 | args: -rg_type interval -rg_interval_endpoints 1.1,1.25 -st_ksp_type hpddm | ||
| 144 | requires: hpddm | ||
| 145 | test: | ||
| 146 | suffix: ciss_2 | ||
| 147 | nsize: 2 | ||
| 148 | args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2 | ||
| 149 | test: | ||
| 150 | suffix: ciss_2_block | ||
| 151 | args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_blocksize 3 -eps_ciss_moments 2 | ||
| 152 | requires: complex !__float128 | ||
| 153 | test: | ||
| 154 | suffix: ciss_2_hpddm | ||
| 155 | nsize: 2 | ||
| 156 | args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2 -eps_ciss_ksp_type hpddm | ||
| 157 | requires: hpddm | ||
| 158 | test: | ||
| 159 | suffix: feast | ||
| 160 | args: -eps_type feast -eps_interval 1.1,1.25 -eps_ncv 64 -options_left 0 | ||
| 161 | requires: feast | ||
| 162 | |||
| 163 | testset: | ||
| 164 | args: -n 30 -m 30 -eps_interval 3.9,4.15 -terse | ||
| 165 | output_file: output/ex2_3.out | ||
| 166 | filter: grep -v Solution | ||
| 167 | requires: !single | ||
| 168 | test: | ||
| 169 | suffix: 3 | ||
| 170 | args: -st_type sinvert -st_pc_type cholesky | ||
| 171 | test: | ||
| 172 | suffix: 3_evsl | ||
| 173 | args: -eps_type evsl -eps_evsl_slices 6 | ||
| 174 | requires: evsl | ||
| 175 | |||
| 176 | testset: | ||
| 177 | args: -n 45 -m 46 -eps_interval 4.54,4.57 -eps_ncv 24 -terse | ||
| 178 | output_file: output/ex2_4.out | ||
| 179 | filter: grep -v Solution | ||
| 180 | requires: !single | ||
| 181 | timeoutfactor: 2 | ||
| 182 | test: | ||
| 183 | suffix: 4 | ||
| 184 | args: -st_type sinvert -st_pc_type cholesky | ||
| 185 | test: | ||
| 186 | suffix: 4_filter | ||
| 187 | args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -st_filter_type {{filtlan chebyshev}} | ||
| 188 | requires: !__float128 | ||
| 189 | test: | ||
| 190 | suffix: 4_filter_cuda | ||
| 191 | args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijcusparse -st_filter_type {{filtlan chebyshev}} | ||
| 192 | requires: cuda | ||
| 193 | test: | ||
| 194 | suffix: 4_filter_hip | ||
| 195 | args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijhipsparse -st_filter_type {{filtlan chebyshev}} | ||
| 196 | requires: hip | ||
| 197 | test: | ||
| 198 | suffix: 4_evsl | ||
| 199 | args: -eps_type evsl | ||
| 200 | requires: evsl | ||
| 201 | |||
| 202 | test: | ||
| 203 | args: -n 25 -m 24 -eps_threshold_absolute .25 -eps_smallest_magnitude -eps_ncv 10 -terse | ||
| 204 | suffix: 5 | ||
| 205 | requires: !single | ||
| 206 | |||
| 207 | testset: | ||
| 208 | args: -n 25 -m 24 -st_type sinvert -terse | ||
| 209 | requires: double | ||
| 210 | test: | ||
| 211 | suffix: 6 | ||
| 212 | args: -eps_threshold_absolute .15 -eps_target 0.01 | ||
| 213 | test: | ||
| 214 | suffix: 6_rel_large | ||
| 215 | args: -eps_threshold_relative .98 -eps_target 8 | ||
| 216 | test: | ||
| 217 | suffix: 6_rel_small | ||
| 218 | args: -eps_threshold_relative 3 | ||
| 219 | |||
| 220 | TEST*/ | ||
| 221 |