Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephKappa.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* AlephKappa.cc (C) 2012 */
9/* */
10/*---------------------------------------------------------------------------*/
11/*---------------------------------------------------------------------------*/
12#include "arcane_packages.h"
13
14#include "arcane/IParallelMng.h"
15#include "arcane/IDirectExecution.h"
16#include "arcane/BasicService.h"
17#include "arcane/ArcaneVersion.h"
18#include "arcane/FactoryService.h"
19#include "arcane/utils/ScopedPtr.h"
20#include "arcane/utils/ITraceMng.h"
21#include "arcane/utils/MultiArray2.h"
22#include "arcane/utils/ArgumentException.h"
23
24#include "arcane/Timer.h"
25#include "arcane/utils/TraceAccessor.h"
26#include "arcane/utils/String.h"
27#include "arcane/utils/StringBuilder.h"
28#include "arcane/aleph/AlephTypesSolver.h"
29#include "arcane/aleph/AlephParams.h"
30
31#include "arcane/utils/PlatformUtils.h"
32#include "arcane/utils/IProcessorAffinityService.h"
33#include "arcane/IParallelSuperMng.h"
34#include "arcane/IApplication.h"
35
36#include "arcane/aleph/Aleph.h"
37#include "arcane/aleph/IAlephFactory.h"
38
39#include "arcane/aleph/kappa/AlephKappa.h"
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44ARCANE_BEGIN_NAMESPACE
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49ARCANE_REGISTER_APPLICATION_FACTORY(AlephKappaService, IDirectExecution, AlephKappa);
50
51AlephKappaService::
52AlephKappaService(const ServiceBuildInfo& sbi)
53: AbstractService(sbi)
54, m_kernel(NULL)
55, m_world_parallel(NULL)
56, m_world_rank(-1)
57, m_size(-1)
58, m_world_size(-1)
59, m_factory(NULL)
60, m_underlying_solver(-1)
61, m_solver_size(-1)
62, m_reorder(false)
63{
64 debug() << "[AlephKappaService] NEW";
65 traceMng()->flush();
66 m_application = sbi.application();
67}
68
69AlephKappaService::
70~AlephKappaService()
71{
72 if (m_kernel)
73 delete m_kernel;
74 if (m_factory)
75 delete m_factory;
76}
77
78void AlephKappaService::
79execute(void)
80{
81 debug() << "[AlephKappaService] Retrieving world size...";
82 m_world_size = m_world_parallel->commSize();
83 m_world_rank = m_world_parallel->commRank();
84
85 debug() << "[AlephKappaService] I should be an additional site #"
86 << m_world_rank << " among " << m_world_size;
87
88 debug() << "[AlephKappaService] Retrieving configuration...";
89 // cfg(0): m_underlying_solver
90 // cfg(1): m_solver_size
91 // cfg(2): m_reorder
92 // cfg(3): m_size
94 m_world_parallel->broadcast(cfg, 0);
95 for (Integer rnk = 0, max = cfg.size(); rnk < max; rnk += 1) {
96 debug() << "[AlephKappaService] cfg[" << rnk << "]=" << cfg[rnk];
97 }
98
99 debug() << "[AlephKappaService] factory";
100 m_factory = new AlephFactory(m_application, m_world_parallel->traceMng());
101 debug() << "[AlephKappaService] kernel";
102 m_kernel = new AlephKernel(m_world_parallel,
103 m_size = cfg.at(3),
104 m_factory,
105 m_underlying_solver = cfg.at(0),
106 m_solver_size = cfg.at(1),
107 m_reorder = (cfg.at(2) == 1) ? true : false);
108
109 AlephParams* params =
110 new AlephParams(traceMng(),
111 1.0e-10, // m_param_epsilon epsilon de convergence
112 2000, // m_param_max_iteration nb max iterations
113 TypesSolver::DIAGONAL, // m_param_preconditioner_method: DIAGONAL, AMG, IC
114 TypesSolver::PCG, // m_param_solver_method méthode de résolution
115 -1, // m_param_gamma
116 -1.0, // m_param_alpha
117 false, // m_param_xo_user par défaut Xo n'est pas égal à 0
118 false, // m_param_check_real_residue
119 false, // m_param_print_real_residue
120 false, // m_param_debug_info
121 1.e-40, // m_param_min_rhs_norm
122 false, // m_param_convergence_analyse
123 true, // m_param_stop_error_strategy
124 false, // m_param_write_matrix_to_file_error_strategy
125 "SolveErrorAlephMatrix.dbg", // m_param_write_matrix_name_error_strategy
126 false, // m_param_listing_output
127 0., // m_param_threshold
128 false, // m_param_print_cpu_time_resolution
129 0, // m_param_amg_coarsening_method
130 0, // m_param_output_level
131 1, // m_param_amg_cycle
132 1, // m_param_amg_solver_iterations
133 1, // m_param_amg_smoother_iterations
134 TypesSolver::SymHybGSJ_smoother, // m_param_amg_smootherOption
135 TypesSolver::ParallelRugeStuben, // m_param_amg_coarseningOption
136 TypesSolver::CG_coarse_solver, // m_param_amg_coarseSolverOption
137 false, // m_param_keep_solver_structure
138 false, // m_param_sequential_solver
139 TypesSolver::RB); // m_param_criteria_stop
140
142 Integer aleph_vector_idx = 0;
145 // Ce flag permet d'éviter de prendre en compte le create() du vecteur temporaire des arguments du solveur
146 bool firstVectorCreateForTmp = true;
147
148 traceMng()->flush();
149
150 while (true) {
152 debug() << "[AlephKappaService] listening for a token...";
153 traceMng()->flush();
154 m_world_parallel->broadcast(token.view(), 0);
155 traceMng()->flush();
156 debug() << "[AlephKappaService] found token " << token.at(0);
157 traceMng()->flush();
158
159 switch (token.at(0)) {
160 /************************************************************************
161 * AlephKernel::initialize
162 ************************************************************************/
163 case (0xd80dee82l): {
164 debug() << "[AlephKappaService] AlephKernel::initialize!";
165 UniqueArray<Integer> args(2);
166 // Récupération des global_nb_row et local_nb_row
167 m_world_parallel->broadcast(args.view(), 0);
168 m_kernel->initialize((Integer)args.at(0), (Integer)args.at(1));
169 break;
170 }
171
172 /************************************************************************
173 * AlephKernel::createSolverMatrix
174 ************************************************************************/
175 case (0xef162166l):
176 debug() << "[AlephKappaService] AlephKernel::createSolverMatrix (new A[" << A_matrix_queue.size() << "])!";
177 firstVectorCreateForTmp = true; // On indique que le prochain create() est relatif au vecteur tmp
178 A_matrix_queue.add(m_kernel->createSolverMatrix());
179 break;
180
181 /************************************************************************
182 * AlephKernel::postSolver
183 ************************************************************************/
184 case (0xba9488bel): {
185 debug() << "[AlephKappaService] AlephKernel::postSolver!";
187 m_world_parallel->broadcast(real_args.view(), 0);
188 params->setEpsilon(real_args.at(0));
189 params->setAlpha(real_args.at(1));
190 params->setMinRHSNorm(real_args.at(2));
191 params->setDDMCParameterAmgDiagonalThreshold(real_args.at(3));
192
194 m_world_parallel->broadcast(bool_args.view(), 0);
195 params->setXoUser((bool)bool_args.at(0));
196 params->setCheckRealResidue((bool)bool_args.at(1));
197 params->setPrintRealResidue((bool)bool_args.at(2));
198 params->setDebugInfo((bool)bool_args.at(3));
199 params->setConvergenceAnalyse((bool)bool_args.at(4));
200 params->setStopErrorStrategy((bool)bool_args.at(5));
201 params->setWriteMatrixToFileErrorStrategy((bool)bool_args.at(6));
202 params->setDDMCParameterListingOutput((bool)bool_args.at(7));
203 params->setPrintCpuTimeResolution((bool)bool_args.at(8));
204 params->setKeepSolverStructure((bool)bool_args.at(9));
205 params->setSequentialSolver((bool)bool_args.at(10));
206
208 m_world_parallel->broadcast(int_args.view(), 0);
209 params->setMaxIter(int_args.at(0));
210 params->setGamma(int_args.at(1));
211 params->setPrecond((TypesSolver::ePreconditionerMethod)int_args.at(2));
212 params->setMethod((TypesSolver::eSolverMethod)int_args.at(3));
213 params->setAmgCoarseningMethod((TypesSolver::eAmgCoarseningMethod)int_args.at(4));
214 params->setOutputLevel(int_args.at(5));
215 params->setAmgCycle(int_args.at(6));
216 params->setAmgSolverIter(int_args.at(7));
217 params->setAmgSmootherIter(int_args.at(8));
218 params->setAmgSmootherOption((TypesSolver::eAmgSmootherOption)int_args.at(9));
219 params->setAmgCoarseningOption((TypesSolver::eAmgCoarseningOption)int_args.at(10));
220 params->setAmgCoarseSolverOption((TypesSolver::eAmgCoarseSolverOption)int_args.at(11));
221 params->setCriteriaStop((TypesSolver::eCriteriaStop)int_args.at(12));
222
223 m_kernel->postSolver(params, NULL, NULL, NULL);
224 break;
225 }
226
227 /************************************************************************
228 * AlephKernel::createSolverVector
229 ************************************************************************/
230 case (0xc4b28f2l): {
231 if ((aleph_vector_idx % 2) == 0) {
232 debug() << "[AlephKappaService] AlephKernel::createSolverVector (new b[" << b.size() << "])";
233 b.add(m_kernel->createSolverVector());
234 }
235 else {
236 debug() << "[AlephKappaService] AlephKernel::createSolverVector (new x[" << x.size() << "])";
237 x.add(m_kernel->createSolverVector());
238 }
239 aleph_vector_idx += 1;
240 break;
241 }
242
243 /************************************************************************
244 * AlephMatrix::create(void)
245 ************************************************************************/
246 case (0xfff06e2l): {
247 debug() << "[AlephKappaService] AlephMatrix::create(void)!";
248 A_matrix_queue.at(m_kernel->index())->create();
249 break;
250 }
251
252 /************************************************************************
253 * AlephVector::create
254 ************************************************************************/
255 case (0x6bdba30al): {
256 if (firstVectorCreateForTmp) { // Si c'est pour le vecteur tmp, on skip
257 debug() << "[AlephKappaService] firstVectorCreateForTmp";
258 firstVectorCreateForTmp = false; // Et on annonce que c'est fait pour le tmp
259 break;
260 }
261
262 if ((aleph_vector_idx % 2) == 0) {
263 debug() << "[AlephKappaService] AlephVector::create (b[" << m_kernel->index() << "])";
264 b.at(m_kernel->index())->create();
265 }
266 else {
267 debug() << "[AlephKappaService] AlephVector::create (x[" << m_kernel->index() << "])";
268 x.at(m_kernel->index())->create();
269 }
270 aleph_vector_idx += 1;
271 break;
272 }
273
274 /************************************************************************
275 * AlephMatrix::assemble
276 ************************************************************************/
277 case (0x74f253cal): {
278 debug() << "[AlephKappaService] AlephMatrix::assemble! (kernel->index=" << m_kernel->index() << ")";
280 m_world_parallel->broadcast(setValue_idx.view(), 0);
281 // On le fait avant pour seter le flag à true
282 m_kernel->topology()->create(setValue_idx.at(0));
283 A_matrix_queue.at(m_kernel->index())->assemble();
284 break;
285 }
286
287 /************************************************************************
288 * AlephVector::assemble
289 ************************************************************************/
290 case (0xec7a979fl): {
291 if ((aleph_vector_idx % 2) == 0) {
292 debug() << "[AlephKappaService] AlephVector::assemble! (b" << m_kernel->index() << ")";
293 b.at(m_kernel->index())->assemble();
294 }
295 else {
296 debug() << "[AlephKappaService] AlephVector::assemble! (x" << m_kernel->index() << ")";
297 x.at(m_kernel->index())->assemble();
298 }
299 aleph_vector_idx += 1;
300 break;
301 }
302
303 /************************************************************************
304 * AlephKernel::syncSolver
305 ************************************************************************/
306 case (0xbf8d3adfl): {
307 debug() << "[AlephKappaService] AlephKernel::syncSolver";
308 traceMng()->flush();
310 m_world_parallel->broadcast(gid.view(), 0);
311
312 Integer nb_iteration;
313 Real residual_norm[4];
314 debug() << "[AlephKappaService] AlephKernel::syncSolver group id=" << gid.at(0);
315 traceMng()->flush();
316 m_kernel->syncSolver(gid.at(0), nb_iteration, &residual_norm[0]);
317 break;
318 }
319
320 /************************************************************************
321 * ArcaneMainBatch::SessionExec::executeRank
322 ************************************************************************/
323 case (0xdfeb699fl): {
324 debug() << "[AlephKappaService] AlephKernel::finalize!";
325 traceMng()->flush();
326 delete params;
327 return;
328 }
329
330 /************************************************************************
331 * Should never happen
332 ************************************************************************/
333 default:
334 debug() << "[AlephKappaService] default";
335 traceMng()->flush();
336 throw FatalErrorException("execute", "Unknown token for handshake");
337 }
338 traceMng()->flush();
339 }
340 throw FatalErrorException("execute", "Should never be there!");
341}
342
343/*---------------------------------------------------------------------------*/
344/*---------------------------------------------------------------------------*/
345
346ARCANE_END_NAMESPACE
347
348/*---------------------------------------------------------------------------*/
349/*---------------------------------------------------------------------------*/
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Enregistre un service de fabrique pour la classe aclass.
Paramètres d'un système linéraire.
Definition AlephParams.h:34
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Exception lorsqu'une erreur fatale est survenue.