1 |
artak |
2160 |
|
2 |
|
|
/******************************************************* |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2003-2008 by University of Queensland |
5 |
|
|
* Earth Systems Science Computational Center (ESSCC) |
6 |
|
|
* http://www.uq.edu.au/esscc |
7 |
|
|
* |
8 |
|
|
* Primary Business: Queensland, Australia |
9 |
|
|
* Licensed under the Open Software License version 3.0 |
10 |
|
|
* http://www.opensource.org/licenses/osl-3.0.php |
11 |
|
|
* |
12 |
|
|
*******************************************************/ |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
/**************************************************************/ |
16 |
|
|
|
17 |
|
|
/* Paso: interface to the direct solvers */ |
18 |
|
|
|
19 |
|
|
/**************************************************************/ |
20 |
|
|
|
21 |
|
|
/* Copyrights by ACcESS Australia 2003 */ |
22 |
|
|
/* Author: artak@access.edu.au */ |
23 |
|
|
|
24 |
|
|
/**************************************************************/ |
25 |
|
|
|
26 |
|
|
#include "paso/Paso.h" |
27 |
|
|
#include "paso/Solver.h" |
28 |
|
|
#include "paso/SystemMatrix.h" |
29 |
|
|
#include "paso/Options.h" |
30 |
|
|
#include "Paso_tests.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************/ |
34 |
|
|
|
35 |
|
|
void Paso_test_run(Paso_SystemMatrix* A,double* b,dim_t level) { |
36 |
|
|
|
37 |
|
|
Paso_Options options; |
38 |
|
|
Paso_Options_setDefaults(&options); |
39 |
|
|
|
40 |
|
|
if(level==1) /* Solvers only*/ |
41 |
|
|
{ |
42 |
|
|
options.method=PASO_PCG; |
43 |
|
|
options.verbose=TRUE; |
44 |
|
|
options.preconditioner=PASO_JACOBI; |
45 |
|
|
fprintf(stdout,"Test solver: PCG with JACOBI\n"); |
46 |
|
|
Paso_test_matrix(A,b,&options); |
47 |
|
|
|
48 |
artak |
2275 |
fprintf(stdout,"Test solver: BICGSTAB with JACOBI\n"); |
49 |
|
|
A->solver=NULL; |
50 |
|
|
options.method=PASO_BICGSTAB; |
51 |
|
|
Paso_test_matrix(A,b,&options); |
52 |
|
|
|
53 |
artak |
2160 |
fprintf(stdout,"Test solver: GMRES with JACOBI\n"); |
54 |
|
|
A->solver=NULL; |
55 |
|
|
options.method=PASO_GMRES; |
56 |
|
|
Paso_test_matrix(A,b,&options); |
57 |
|
|
|
58 |
|
|
fprintf(stdout,"Test solver: PRES20 with JACOBI\n"); |
59 |
|
|
A->solver=NULL; |
60 |
|
|
options.method=PASO_PRES20; |
61 |
|
|
Paso_test_matrix(A,b,&options); |
62 |
|
|
|
63 |
|
|
fprintf(stdout,"Test solver: MINRES with JACOBI\n"); |
64 |
|
|
A->solver=NULL; |
65 |
|
|
options.method=PASO_MINRES; |
66 |
|
|
Paso_test_matrix(A,b,&options); |
67 |
|
|
|
68 |
|
|
fprintf(stdout,"Test solver: TFQMR with JACOBI\n"); |
69 |
|
|
A->solver=NULL; |
70 |
|
|
options.method=PASO_TFQMR; |
71 |
|
|
Paso_test_matrix(A,b,&options); |
72 |
|
|
} |
73 |
|
|
else if (level==2) /* Preconditiones only with default solver*/ |
74 |
|
|
{ |
75 |
|
|
Paso_Options_setDefaults(&options); |
76 |
|
|
options.method=PASO_DEFAULT; |
77 |
|
|
options.verbose=TRUE; |
78 |
|
|
options.preconditioner=PASO_JACOBI; |
79 |
|
|
fprintf(stdout,"Test preconditioner: PASO_DEFAULT with JACOBI\n"); |
80 |
|
|
Paso_test_matrix(A,b,&options); |
81 |
|
|
|
82 |
|
|
Paso_Options_setDefaults(&options); |
83 |
|
|
A->solver=NULL; |
84 |
|
|
options.verbose=TRUE; |
85 |
|
|
fprintf(stdout,"Test preconditioner: PASO_DEFAULT with ILU\n"); |
86 |
|
|
options.method=PASO_DEFAULT; |
87 |
|
|
options.preconditioner=PASO_ILU0; |
88 |
|
|
Paso_test_matrix(A,b,&options); |
89 |
|
|
|
90 |
|
|
Paso_Options_setDefaults(&options); |
91 |
|
|
A->solver=NULL; |
92 |
|
|
options.verbose=TRUE; |
93 |
|
|
fprintf(stdout,"Test preconditioner: PASO_DEFAULT with RILU\n"); |
94 |
|
|
options.method=PASO_DEFAULT; |
95 |
|
|
options.preconditioner=PASO_RILU; |
96 |
|
|
Paso_test_matrix(A,b,&options); |
97 |
|
|
|
98 |
|
|
Paso_Options_setDefaults(&options); |
99 |
|
|
A->solver=NULL; |
100 |
|
|
options.verbose=TRUE; |
101 |
|
|
fprintf(stdout,"Test preconditioner: PASO_DEFAULT with GS\n"); |
102 |
|
|
options.method=PASO_DEFAULT; |
103 |
|
|
options.preconditioner=PASO_GS; |
104 |
|
|
Paso_test_matrix(A,b,&options); |
105 |
|
|
|
106 |
|
|
Paso_Options_setDefaults(&options); |
107 |
|
|
A->solver=NULL; |
108 |
|
|
options.verbose=TRUE; |
109 |
|
|
fprintf(stdout,"Test preconditioner: PASO_DEFAULT with AMG\n"); |
110 |
|
|
options.method=PASO_DEFAULT; |
111 |
|
|
options.preconditioner=PASO_AMG; |
112 |
|
|
Paso_test_matrix(A,b,&options); |
113 |
|
|
|
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
void Paso_test_matrix(Paso_SystemMatrix* A, double* b, Paso_Options* options ) { |
118 |
|
|
|
119 |
|
|
dim_t n=Paso_SystemMatrix_getTotalNumRows(A); |
120 |
|
|
double *out=NULL; |
121 |
|
|
out=MEMALLOC(n,double); |
122 |
|
|
|
123 |
|
|
if (Paso_checkPtr(out)) { |
124 |
|
|
fprintf(stderr,"Cannot allocate memory\n"); |
125 |
|
|
return; |
126 |
|
|
} |
127 |
|
|
Paso_solve(A,out,b,options); |
128 |
|
|
|
129 |
|
|
MEMFREE(out); |
130 |
|
|
|
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
void Paso_test_data(char *fileName_p, double* b, Paso_Options* options ) { |
134 |
|
|
|
135 |
|
|
Paso_SystemMatrix* A=NULL; |
136 |
|
|
dim_t n=Paso_SystemMatrix_getTotalNumRows(A); |
137 |
|
|
double *out=MEMALLOC(n,double); |
138 |
|
|
A=Paso_SystemMatrix_loadMM_toCSR(fileName_p); |
139 |
|
|
|
140 |
|
|
if (Paso_checkPtr(out)) { |
141 |
|
|
return; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
Paso_solve(A,out,b,options); |
145 |
|
|
|
146 |
|
|
Paso_SystemMatrix_free(A); |
147 |
|
|
MEMFREE(out); |
148 |
|
|
} |
149 |
artak |
2275 |
|