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[] = "Tests multiple calls to EPSSolve with different matrix.\n\n";
12 :
13 : #include <slepceps.h>
14 :
15 18 : int main(int argc,char **argv)
16 : {
17 18 : Mat A1,A2; /* problem matrices */
18 18 : EPS eps; /* eigenproblem solver context */
19 18 : PetscReal tol=PETSC_SMALL,v;
20 18 : Vec d;
21 18 : PetscInt n=30,i,Istart,Iend;
22 18 : PetscRandom myrand;
23 :
24 18 : PetscFunctionBeginUser;
25 18 : PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
26 :
27 18 : PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
28 18 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nTridiagonal with random diagonal, n=%" PetscInt_FMT "\n\n",n));
29 :
30 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 : Create matrix tridiag([-1 0 -1])
32 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
33 18 : PetscCall(MatCreate(PETSC_COMM_WORLD,&A1));
34 18 : PetscCall(MatSetSizes(A1,PETSC_DECIDE,PETSC_DECIDE,n,n));
35 18 : PetscCall(MatSetFromOptions(A1));
36 :
37 18 : PetscCall(MatGetOwnershipRange(A1,&Istart,&Iend));
38 558 : for (i=Istart;i<Iend;i++) {
39 540 : if (i>0) PetscCall(MatSetValue(A1,i,i-1,-1.0,INSERT_VALUES));
40 540 : if (i<n-1) PetscCall(MatSetValue(A1,i,i+1,-1.0,INSERT_VALUES));
41 : }
42 18 : PetscCall(MatAssemblyBegin(A1,MAT_FINAL_ASSEMBLY));
43 18 : PetscCall(MatAssemblyEnd(A1,MAT_FINAL_ASSEMBLY));
44 :
45 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46 : Create two matrices by filling the diagonal with rand values
47 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
48 18 : PetscCall(MatDuplicate(A1,MAT_COPY_VALUES,&A2));
49 18 : PetscCall(MatCreateVecs(A1,NULL,&d));
50 18 : PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&myrand));
51 18 : PetscCall(PetscRandomSetFromOptions(myrand));
52 18 : PetscCall(PetscRandomSetInterval(myrand,0.0,1.0));
53 558 : for (i=Istart;i<Iend;i++) {
54 540 : PetscCall(PetscRandomGetValueReal(myrand,&v));
55 540 : PetscCall(VecSetValue(d,i,v,INSERT_VALUES));
56 : }
57 18 : PetscCall(VecAssemblyBegin(d));
58 18 : PetscCall(VecAssemblyEnd(d));
59 18 : PetscCall(MatDiagonalSet(A1,d,INSERT_VALUES));
60 558 : for (i=Istart;i<Iend;i++) {
61 540 : PetscCall(PetscRandomGetValueReal(myrand,&v));
62 540 : PetscCall(VecSetValue(d,i,v,INSERT_VALUES));
63 : }
64 18 : PetscCall(VecAssemblyBegin(d));
65 18 : PetscCall(VecAssemblyEnd(d));
66 18 : PetscCall(MatDiagonalSet(A2,d,INSERT_VALUES));
67 18 : PetscCall(VecDestroy(&d));
68 18 : PetscCall(PetscRandomDestroy(&myrand));
69 :
70 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71 : Create the eigensolver
72 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73 18 : PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
74 18 : PetscCall(EPSSetProblemType(eps,EPS_HEP));
75 18 : PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
76 18 : PetscCall(EPSSetOperators(eps,A1,NULL));
77 18 : PetscCall(EPSSetFromOptions(eps));
78 :
79 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 : Solve first eigenproblem
81 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82 18 : PetscCall(EPSSolve(eps));
83 18 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - First matrix - - -\n"));
84 18 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
85 :
86 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 : Solve second eigenproblem
88 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
89 18 : PetscCall(EPSSetOperators(eps,A2,NULL));
90 18 : PetscCall(EPSSolve(eps));
91 18 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - Second matrix - - -\n"));
92 18 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
93 :
94 18 : PetscCall(EPSDestroy(&eps));
95 18 : PetscCall(MatDestroy(&A1));
96 18 : PetscCall(MatDestroy(&A2));
97 18 : PetscCall(SlepcFinalize());
98 : return 0;
99 : }
100 :
101 : /*TEST
102 :
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
149 :
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
175 :
176 : TEST*/
|