Actual source code: test3.c
slepc-3.17.2 2022-08-09
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7: SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: */
11: static char help[] = "Tests multiple calls to EPSSolve with different matrix.\n\n";
13: #include <slepceps.h>
15: int main(int argc,char **argv)
16: {
17: Mat A1,A2; /* problem matrices */
18: EPS eps; /* eigenproblem solver context */
19: PetscReal tol=PETSC_SMALL,v;
20: Vec d;
21: PetscInt n=30,i,Istart,Iend;
22: PetscRandom myrand;
24: SlepcInitialize(&argc,&argv,(char*)0,help);
26: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
27: PetscPrintf(PETSC_COMM_WORLD,"\nTridiagonal with random diagonal, n=%" PetscInt_FMT "\n\n",n);
29: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30: Create matrix tridiag([-1 0 -1])
31: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
32: MatCreate(PETSC_COMM_WORLD,&A1);
33: MatSetSizes(A1,PETSC_DECIDE,PETSC_DECIDE,n,n);
34: MatSetFromOptions(A1);
35: MatSetUp(A1);
37: MatGetOwnershipRange(A1,&Istart,&Iend);
38: for (i=Istart;i<Iend;i++) {
39: if (i>0) MatSetValue(A1,i,i-1,-1.0,INSERT_VALUES);
40: if (i<n-1) MatSetValue(A1,i,i+1,-1.0,INSERT_VALUES);
41: }
42: MatAssemblyBegin(A1,MAT_FINAL_ASSEMBLY);
43: MatAssemblyEnd(A1,MAT_FINAL_ASSEMBLY);
45: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46: Create two matrices by filling the diagonal with rand values
47: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
48: MatDuplicate(A1,MAT_COPY_VALUES,&A2);
49: MatCreateVecs(A1,NULL,&d);
50: PetscRandomCreate(PETSC_COMM_WORLD,&myrand);
51: PetscRandomSetFromOptions(myrand);
52: PetscRandomSetInterval(myrand,0.0,1.0);
53: for (i=Istart;i<Iend;i++) {
54: PetscRandomGetValueReal(myrand,&v);
55: VecSetValue(d,i,v,INSERT_VALUES);
56: }
57: VecAssemblyBegin(d);
58: VecAssemblyEnd(d);
59: MatDiagonalSet(A1,d,INSERT_VALUES);
60: for (i=Istart;i<Iend;i++) {
61: PetscRandomGetValueReal(myrand,&v);
62: VecSetValue(d,i,v,INSERT_VALUES);
63: }
64: VecAssemblyBegin(d);
65: VecAssemblyEnd(d);
66: MatDiagonalSet(A2,d,INSERT_VALUES);
67: VecDestroy(&d);
68: PetscRandomDestroy(&myrand);
70: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71: Create the eigensolver
72: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73: EPSCreate(PETSC_COMM_WORLD,&eps);
74: EPSSetProblemType(eps,EPS_HEP);
75: EPSSetTolerances(eps,tol,PETSC_DEFAULT);
76: EPSSetOperators(eps,A1,NULL);
77: EPSSetFromOptions(eps);
79: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80: Solve first eigenproblem
81: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82: EPSSolve(eps);
83: PetscPrintf(PETSC_COMM_WORLD," - - - First matrix - - -\n");
84: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
86: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87: Solve second eigenproblem
88: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
89: EPSSetOperators(eps,A2,NULL);
90: EPSSolve(eps);
91: PetscPrintf(PETSC_COMM_WORLD," - - - Second matrix - - -\n");
92: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
94: EPSDestroy(&eps);
95: MatDestroy(&A1);
96: MatDestroy(&A2);
97: SlepcFinalize();
98: return 0;
99: }
101: /*TEST
103: testset:
104: args: -eps_nev 4
105: requires: !single
106: output_file: output/test3_1.out
107: test:
108: suffix: 1
109: args: -eps_type {{krylovschur subspace arnoldi lapack}}
110: test:
111: suffix: 1_lanczos
112: args: -eps_type lanczos -eps_lanczos_reorthog local
113: test:
114: suffix: 1_power
115: args: -eps_type power -eps_max_it 20000
116: test:
117: suffix: 1_jd
118: args: -eps_type jd -eps_jd_initial_size 7
119: test:
120: suffix: 1_gd
121: args: -eps_type gd -eps_gd_initial_size 7
122: test:
123: suffix: 1_gd2
124: args: -eps_type gd -eps_gd_double_expansion
125: test:
126: suffix: 1_arpack
127: args: -eps_type arpack
128: requires: arpack
129: test:
130: suffix: 1_primme
131: args: -eps_type primme -eps_conv_abs -eps_primme_blocksize 4
132: requires: primme
133: test:
134: suffix: 1_trlan
135: args: -eps_type trlan
136: requires: trlan
137: test:
138: suffix: 1_scalapack
139: args: -eps_type scalapack
140: requires: scalapack
141: test:
142: suffix: 1_elpa
143: args: -eps_type elpa
144: requires: elpa
145: test:
146: suffix: 1_elemental
147: args: -eps_type elemental
148: requires: elemental
150: testset:
151: args: -eps_nev 4 -eps_smallest_real -eps_max_it 500
152: output_file: output/test3_2.out
153: test:
154: suffix: 2_rqcg
155: args: -eps_type rqcg -eps_rqcg_reset 5 -eps_ncv 32
156: test:
157: suffix: 2_lobpcg
158: args: -eps_type lobpcg -eps_lobpcg_blocksize 5 -st_pc_type none
159: test:
160: suffix: 2_lanczos
161: args: -eps_type lanczos -eps_lanczos_reorthog local
162: requires: !single
163: test:
164: suffix: 2_lanczos_delayed
165: args: -eps_type lanczos -eps_lanczos_reorthog delayed -eps_tol 1e-8
166: requires: !single
167: test:
168: suffix: 2_trlan
169: args: -eps_type trlan
170: requires: trlan
171: test:
172: suffix: 2_blopex
173: args: -eps_type blopex -eps_conv_abs -st_shift -2
174: requires: blopex
176: TEST*/