/[escript]/trunk/paso/profiling/Test.cpp
ViewVC logotype

Contents of /trunk/paso/profiling/Test.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4520 - (show annotations)
Thu Aug 22 06:42:57 2013 UTC (5 years, 8 months ago) by caltinay
File size: 7966 byte(s)
Removing spurious usage of C compiler:
-Changed all scons tests to use C++ compiler
-Renamed paso profiling files (unused)
-Updated most options files (removal of options and updated comments)

1 #include <stdio.h>
2 #include <unistd.h>
3 #include "paso/Common.h"
4 #include "paso/Solver.h"
5 #include "paso/SystemMatrix.h"
6 #include "Paso_tests.h"
7 #include "getopt.h"
8 #include <math.h>
9
10 #define PI (3.141592653589793)
11
12 /*
13 Usage: PasoTests -f filename [-s solver] [-p preconditioner] [-l level] [-r rhs matrix] [-c coarsening method] [-t threshold parameter for AMG coarsening]
14 filename - matrix to be loaded in CSR Matrix-Market format
15 solver - PCG, GMRES, PRES20, TFQMR and MINRES
16 preconditioner - ILU0, RILU, JACOBI, GS and AMG
17 level - options are 1,2 and 3
18 0 - default option just solves with default of specified parameters
19 1 - test all solvers with default preconditioner
20 2 - test all preconditioners with default solver
21 3 - compare solution obtained by using AMG and Jacobi preconditioners
22 coarsening method - YS, RS, AGG and STD.
23 threshold parameter for AMG - this is the threshold value used in AMG in the coarsening process. Default is 0.25. For YS and AGG, please, use 0.05.
24 */
25
26 double Lsup(double* x, int n) {
27 double max=0;
28 int i;
29
30 for (i=0;i<n;i++) {
31 max=MAX(ABS(x[i]),max);
32 }
33
34 return max;
35 }
36
37 int main (int argc, char *argv[]) {
38 Paso_SystemMatrix *A = NULL;
39 double *b,*x,*x_ref;
40 dim_t i,n,level=0;
41 double *error;
42 double Lsuperror;
43
44 int c;
45 char *filename,*solver,*prec,*rhs;
46 extern char *optarg;
47 extern int optopt;
48
49 Paso_Options options;
50 Paso_Options_setDefaults(&options);
51
52
53
54 options.verbose=TRUE;
55 options.level_max=2;
56 options.tolerance=1.E-6;
57 options.smoother=PASO_GAUSS_SEIDEL;
58 options.pre_sweeps=5;
59 options.post_sweeps=5;
60
61 while ((c = getopt(argc, argv, "s:p:f:r:l:t:c:h")) != -1) {
62 switch(c) {
63 case 's':
64 solver=optarg;
65 if (strcmp(solver,"PCG")==0)
66 options.method=PASO_PCG;
67 else if (strcmp(solver,"GMRES")==0)
68 options.method=PASO_GMRES;
69 else if (strcmp(solver,"PRES20")==0)
70 options.method=PASO_PRES20;
71 else if (strcmp(solver,"BICGSTAB")==0)
72 options.method=PASO_BICGSTAB;
73 else if (strcmp(solver,"TFQMR")==0)
74 options.method=PASO_TFQMR;
75 else if (strcmp(solver,"MINRES")==0)
76 options.method=PASO_MINRES;
77 else if (strcmp(solver,"DIRECT")==0) {
78 options.package=PASO_MKL;
79 options.verbose=1;
80 }
81 break;
82 case 'p':
83 prec=optarg;
84 if (strcmp(prec,"JACOBI")==0)
85 options.preconditioner=PASO_JACOBI;
86 else if (strcmp(prec,"RILU")==0)
87 options.preconditioner=PASO_RILU;
88 else if (strcmp(prec,"ILU0")==0)
89 options.preconditioner=PASO_ILU0;
90 else if (strcmp(prec,"GS")==0)
91 options.preconditioner=PASO_GS;
92 else if (strcmp(prec,"AMG")==0) {
93 options.preconditioner=PASO_AMG;
94 }
95 else if (strcmp(prec,"AMLI")==0) {
96 options.preconditioner=PASO_AMG;
97 }
98 break;
99 case 'f':
100 filename = optarg;
101 A=MEMALLOC(1,Paso_SystemMatrix);
102 A=Paso_SystemMatrix_loadMM_toCSR(filename);
103 n=Paso_SystemMatrix_getTotalNumRows(A);
104 b=MEMALLOC(n,double);
105 x=MEMALLOC(n,double);
106 x_ref=MEMALLOC(n,double);
107 error=MEMALLOC(n,double);
108 for(i=0;i<n;i++) {
109 x_ref[i]=cos(i*PI/n);
110 }
111 Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(DBLE(1),A,x_ref,DBLE(0),b);
112 break;
113 case 'r':
114 rhs=optarg;
115 if (A==NULL) {
116 fprintf(stderr,"System matrix is not loaded yet.\n");
117 break;
118 }
119 n=Paso_SystemMatrix_getTotalNumRows(A);
120 Paso_RHS_loadMM_toCSR(rhs,b,n);
121 break;
122 case 'l':
123 level=atoi(optarg);
124 break;
125 case 't':
126 options.coarsening_threshold=atof(optarg);
127 break;
128 case 'c':
129 prec=optarg;
130 if (strcmp(prec,"RS")==0)
131 options.coarsening_method=PASO_RUGE_STUEBEN_COARSENING;
132 else if (strcmp(prec,"YS")==0)
133 options.coarsening_method=PASO_YAIR_SHAPIRA_COARSENING;
134 else if (strcmp(prec,"AGG")==0)
135 options.coarsening_method=PASO_AGGREGATION_COARSENING;
136 else if (strcmp(prec,"STD")==0)
137 options.coarsening_method=PASO_STANDARD_COARSENING;
138 break;
139 case '?':
140 printf("unknown arg %c\n", optopt);
141 break;
142 case 'h':
143 printf("Usage: PasoTests -f filename [-s solver] [-p preconditioner] [-l level] [-r rhs vector] [-c coarsening method] [-t threshold parameter for AMG coarsening] \n");
144 printf("\t filename - matrix to be loaded in CSR Matrix-Market format\n");
145 printf("\t solver - PCG, GMRES, PRES20, TFQMR and MINRES\n");
146 printf("\t preconditioner - ILU0, RILU, JACOBI, GS and AMG\n");
147 printf("\t level - options are 1,2 and 3\n");
148 printf("\t\t 0 - default option just solves with default of specified parameters\n");
149 printf("\t\t 1 - test all solvers with default preconditioner\n");
150 printf("\t\t 2 - test all preconditioners with default solver\n");
151 printf("\t\t 3 - compare solution obtained by using AMG and Jacobi precondioners\n");
152 printf("\trhs vector - right hand side vector in CSR Matrix Market format.\n");
153 printf("\tcoarsening method - YS, RS, AGG and STD.\n");
154 printf("\tthreshold parameter for AMG - this is the threshold value used in AMG in the coarsening process. Default is 0.25. For YS and AGG, please, use 0.05.\n");
155 break;
156 }
157 }
158
159 if (A==NULL) {
160 /*fprintf(stderr,"CSR Matrix not Loaded\n");*/
161 return 0;
162 }
163
164
165 if (level==0) {
166 Paso_solve(A,x,b,&options);
167 }
168 else if (level==3) {
169 options.method=PASO_PCG;
170 options.verbose=TRUE;
171 options.preconditioner=PASO_JACOBI;
172
173 Paso_solve(A,x,b,&options);
174
175 for(i=0;i<n;i++) {
176 error[i]=x[i]-x_ref[i];
177 }
178 Lsuperror=Lsup(error,n)/Lsup(x_ref,n);
179 fprintf(stdout,"Lsup error Jacobi %e\n",Lsuperror);
180
181 A->solver=NULL;
182 options.method=PASO_PCG;
183 options.preconditioner=PASO_AMG;
184
185 Paso_solve(A,x,b,&options);
186
187 for(i=0;i<n;i++) {
188 error[i]=x[i]-x_ref[i];
189 }
190 Lsuperror=Lsup(error,n)/Lsup(x_ref,n);
191 fprintf(stdout,"Lsup error AMG %e\n",Lsuperror);
192 }
193 else if (level==4) {
194 options.method=PASO_PCG;
195 options.verbose=TRUE;
196 options.preconditioner=PASO_AMG;
197
198 Paso_Solver_setPreconditioner(A,&options);
199 Paso_Solver_solvePreconditioner(A,x,b);
200
201
202 for(i=0;i<n;i++) {
203 error[i]=x[i]-x_ref[i];
204 }
205 Lsuperror=Lsup(error,n)/Lsup(x_ref,n);
206 fprintf(stdout,"Lsup error AMG as a solver %e\n\n",Lsuperror);
207
208 A->solver=NULL;
209 options.method=PASO_PCG;
210 options.preconditioner=PASO_AMG;
211
212 Paso_solve(A,x,b,&options);
213
214 for(i=0;i<n;i++) {
215 error[i]=x[i]-x_ref[i];
216 }
217 Lsuperror=Lsup(error,n)/Lsup(x_ref,n);
218 fprintf(stdout,"Lsup error AMG %e\n",Lsuperror);
219 }
220 else {
221 Paso_test_run(A,b,level);
222 }
223
224 if (A!=NULL) {
225 MEMFREE(b);
226 MEMFREE(x);
227 MEMFREE(x_ref);
228 MEMFREE(error);
229 Paso_SystemMatrix_free(A);
230 }
231
232 return 1;
233 }
234
235

  ViewVC Help
Powered by ViewVC 1.1.26