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