1 #ifndef SELDON_FILE_HYPRE_CXX
4 #include "HypreInline.cxx"
13 solver_created =
false;
20 type_preconditioner = BOOMER_AMG;
27 amg_smoother = HYBRID_GS_BACKWARD;
34 euclid_use_ilut =
false;
37 euclid_droptol = 0.01;
55 if (type_preconditioner == BOOMER_AMG)
56 HYPRE_BoomerAMGDestroy(solver);
57 else if (type_preconditioner == PARASAILS)
58 HYPRE_ParaSailsDestroy(solver);
59 else if (type_preconditioner == EUCLID)
60 HYPRE_EuclidDestroy(solver);
61 else if (type_preconditioner == AMS)
62 HYPRE_AMSDestroy(solver);
64 HYPRE_IJMatrixDestroy(A);
65 HYPRE_IJVectorDestroy(vec_b);
66 HYPRE_IJVectorDestroy(vec_x);
69 solver_created =
false;
79 type_preconditioner = BOOMER_AMG;
80 for (
int k = 0; k < params.GetM(); k += 2)
82 if (params(k) ==
"MaximumLevel")
83 amg_max_levels = to_num<int>(params(k+1));
84 else if (params(k) ==
"NumberSweeps")
85 amg_num_sweeps = to_num<int>(params(k+1));
86 else if (params(k) ==
"Smoother")
88 if (params(k+1) ==
"Jacobi")
89 amg_smoother = JACOBI;
90 else if (params(k+1) ==
"GaussSeidel")
91 amg_smoother = GS_PAR_SEQ;
92 else if (params(k+1) ==
"HybridGaussSeidel")
93 amg_smoother = HYBRID_GS_BACKWARD;
94 else if (params(k+1) ==
"HybridGaussSeidelForward")
95 amg_smoother = HYBRID_GS_FORWARD;
96 else if (params(k+1) ==
"HybridGaussSeidelSymmetric")
97 amg_smoother = HYBRID_GS_SYMMETRIC;
98 else if (params(k+1) ==
"L1_GaussSeidel")
99 amg_smoother = L1_GAUSS_SEIDEL;
100 else if (params(k+1) ==
"Chebyshev")
101 amg_smoother = CHEBYSHEV;
102 else if (params(k+1) ==
"FCF_Jacobi")
103 amg_smoother = FCF_JACOBI;
104 else if (params(k+1) ==
"L1_Jacobi")
105 amg_smoother = L1_JACOBI;
107 amg_smoother = to_num<int>(params(k+1));
111 else if (keyword ==
"ParaSails")
113 type_preconditioner = PARASAILS;
114 for (
int k = 0; k < params.GetM(); k += 2)
116 if (params(k) ==
"Filter")
117 sai_filter = to_num<HYPRE_Real>(params(k+1));
118 else if (params(k) ==
"Threshold")
119 sai_threshold = to_num<HYPRE_Real>(params(k+1));
120 else if (params(k) ==
"MaximumLevel")
121 sai_max_levels = to_num<int>(params(k+1));
122 else if (params(k) ==
"Symmetry")
123 sai_sym = to_num<int>(params(k+1));
126 else if (keyword ==
"Euclid")
128 type_preconditioner = EUCLID;
129 for (
int k = 0; k < params.GetM(); k += 2)
131 if (params(k) ==
"Threshold")
132 euclid_threshold = to_num<HYPRE_Real>(params(k+1));
133 else if (params(k) ==
"Droptol")
134 euclid_droptol = to_num<HYPRE_Real>(params(k+1));
135 else if (params(k) ==
"Level")
136 euclid_level = to_num<int>(params(k+1));
137 else if (params(k) ==
"Algorithm")
139 if (params(k+1) ==
"ILU")
140 euclid_use_ilut =
false;
141 else if (params(k+1) ==
"ILUT")
142 euclid_use_ilut =
true;
146 else if (keyword ==
"AMS")
148 type_preconditioner = AMS;
152 cout <<
"Unknown preconditioning : " << keyword << endl;
159 template<
class T>
template<
class Prop,
class Storage,
class Allocator>
168 int nb_proc; MPI_Comm_size(comm, &nb_proc);
183 AssembleDistributed(A, prop, comm, row_numbers,
184 local_rows, size_rows, cols, values,
false,
true);
187 AssembleDistributed(A0, prop, comm, row_numbers,
188 local_rows, size_rows, cols, values,
false,
true);
193 ConvertToCSR(A0, prop, size_rows, cols, values);
197 row_numbers.Reallocate(N);
199 local_rows.Reallocate(N);
204 FinalizePreconditioner(row_numbers, size_rows, cols, values);
214 int Nloc = local_rows.GetM();
215 int ilower = row_numbers(0);
216 int iupper = row_numbers(Nloc-1);
221 for (
int i = 0; i < Nloc; i++)
222 length_rows(i) = size_rows(i+1) - size_rows(i);
227 HYPRE_IJMatrixCreate(comm, ilower, iupper, ilower, iupper, &A);
230 HYPRE_IJMatrixSetObjectType(A, HYPRE_PARCSR);
233 HYPRE_IJMatrixInitialize(A);
236 HYPRE_IJMatrixSetValues(A, Nloc, length_rows.GetData(), row_numbers.GetData(), cols.GetData(), values.GetData());
239 cols.Clear(); values.Clear(); size_rows.Clear();
243 HYPRE_IJMatrixAssemble(A);
246 HYPRE_IJMatrixGetObject(A, (
void**) &parcsr_A);
249 HYPRE_IJVectorCreate(comm, ilower, iupper, &vec_b);
250 HYPRE_IJVectorSetObjectType(vec_b, HYPRE_PARCSR);
251 HYPRE_IJVectorInitialize(vec_b);
253 HYPRE_IJVectorCreate(comm, ilower, iupper, &vec_x);
254 HYPRE_IJVectorSetObjectType(vec_x, HYPRE_PARCSR);
255 HYPRE_IJVectorInitialize(vec_x);
257 HYPRE_IJVectorGetObject(vec_b, (
void **) &par_b);
258 HYPRE_IJVectorGetObject(vec_x, (
void **) &par_x);
261 solver_created =
true;
262 if (type_preconditioner == BOOMER_AMG)
264 HYPRE_BoomerAMGCreate(&solver);
265 HYPRE_BoomerAMGSetPrintLevel(solver, print_level);
267 HYPRE_BoomerAMGSetOldDefault(solver);
268 HYPRE_BoomerAMGSetRelaxType(solver, amg_smoother);
269 HYPRE_BoomerAMGSetRelaxOrder(solver, 1);
270 HYPRE_BoomerAMGSetNumSweeps(solver, amg_num_sweeps);
271 HYPRE_BoomerAMGSetMaxLevels(solver, amg_max_levels);
272 HYPRE_BoomerAMGSetTol(solver, 0);
273 HYPRE_BoomerAMGSetMaxIter(solver, 1);
276 HYPRE_BoomerAMGSetup(solver, parcsr_A, par_b, par_x);
279 HYPRE_BoomerAMGSetPrintLevel(solver, 0);
281 else if (type_preconditioner == PARASAILS)
284 HYPRE_ParaSailsCreate(comm, &solver);
287 HYPRE_ParaSailsSetParams(solver, sai_threshold, sai_max_levels);
288 HYPRE_ParaSailsSetFilter(solver, sai_filter);
289 HYPRE_ParaSailsSetSym(solver, sai_sym);
290 HYPRE_ParaSailsSetLogging(solver, print_level);
293 HYPRE_ParaSailsSetup(solver, parcsr_A, par_b, par_x);
295 else if (type_preconditioner == EUCLID)
297 HYPRE_EuclidCreate(comm, &solver);
298 HYPRE_EuclidSetLevel(solver, euclid_level);
300 HYPRE_EuclidSetSparseA(solver, euclid_threshold);
302 HYPRE_EuclidSetILUT(solver, euclid_droptol);
306 HYPRE_EuclidSetStats(solver, 1);
307 HYPRE_EuclidSetMem(solver, 1);
311 HYPRE_EuclidSetup(solver, parcsr_A, par_b, par_x);
315 cout <<
"Unknown preconditioning : " << type_preconditioner << endl;
327 HYPRE_Complex* b_data = par_b->local_vector->data;
328 HYPRE_Complex* x_data = par_x->local_vector->data;
332 for (
int i = 0; i < num.GetM(); i++)
333 b_data[i] = r(num(i));
335 for (
int i = 0; i < num.GetM(); i++)
339 if (trans.NoTrans() || A.IsSymmetric())
341 switch(type_preconditioner)
344 HYPRE_BoomerAMGSolve(solver, parcsr_A, par_b, par_x);
347 HYPRE_ParaSailsSolve(solver, parcsr_A, par_b, par_x);
350 HYPRE_EuclidSolve(solver, parcsr_A, par_b, par_x);
356 switch(type_preconditioner)
359 HYPRE_BoomerAMGSolveT(solver, parcsr_A, par_b, par_x);
362 cout <<
"Transpose preconditioning not available" << endl;
369 for (
int i = 0; i < num.GetM(); i++)
370 z(num(i)) = x_data[i];
372 int nb_proc; MPI_Comm_size(comm, &nb_proc);
374 AssembleVector(z, MPI_SUM, *ProcNumber, *DofNumber, comm, nodl_scalar, nb_u, 11);
379 #define SELDON_FILE_HYPRE_CXX