48 m_sloop_comminfo(
NULL),
49 m_world_comminfo(
NULL),
51 m_sloop_topology(
NULL){
54 if (!m_kernel->isParallel()){
55 m_world_comminfo=
new SLOOP::SLOOPSeqCommInfo();
60 if (!m_participating_in_solver){
61 debug() <<
"\33[1;32m\t[AlephTopologySloop::AlephParallelInfoSloop] Not concerned with this solver, returning\33[0m";
65 debug() <<
"\33[1;32m\t\t[AlephTopologySloop::AlephTopologySloop] @"<<
this<<
"\33[0m";
67 if (!m_kernel->isParallel()){
68 m_sloop_comminfo=
new SLOOP::SLOOPSeqCommInfo();
69 debug() <<
"\33[1;32m\t\t[AlephTopologySloop::AlephTopologySloop] SEQCommInfo @"<<m_sloop_comminfo<<
"\33[0m";
71 m_sloop_comminfo=
new SLOOP::SLOOPMPICommInfo(*(SLOOP::SLOOP_Comm*)
73 debug() <<
"\33[1;32m\t\t[AlephTopologySloop::AlephTopologySloop] MPICommInfo @"<<m_sloop_comminfo<<
"\33[0m";
76 m_sloop_msg=
new SLOOP::SLOOPMsg(m_sloop_comminfo);
77 debug() <<
"\33[1;32m\t\t[AlephTopologySloop::AlephTopologySloop] SLOOPMsg @"<<m_sloop_msg<<
"\33[0m";
79 m_sloop_topology=
new SLOOP::SLOOPTopology(nb_row_size,
80 m_kernel->topology()->rowLocalRange(index),
81 *m_sloop_comminfo, *m_sloop_msg);
82 debug() <<
"\33[1;32m\t\t[AlephTopologySloop::AlephTopologySloop] SLOOPTopology @"<<m_sloop_topology<<
"\33[0m";
85 debug() <<
"\33[1;5;32m\t\t\t[~AlephTopologySloop] deleting m_sloop_msg, m_sloop_comminfo & m_sloop_topology\33[0m";
87 delete m_sloop_comminfo;
88 delete m_sloop_topology;
92 void backupAndInitialize(){
93 if (!m_participating_in_solver)
return;
94 SLOOP::SLOOPInitSession(m_sloop_comminfo,SLOOP::WITHOUT_EXCEPTIONS,SLOOP::OUTPUT_UNIQ);
98 SLOOP::SLOOPInitSession(m_world_comminfo,SLOOP::WITHOUT_EXCEPTIONS,SLOOP::OUTPUT_UNIQ);
102 SLOOP::SLOOPCommInfo *m_sloop_comminfo;
103 SLOOP::SLOOPCommInfo *m_world_comminfo;
104 SLOOP::SLOOPMsg *m_sloop_msg;
105 SLOOP::SLOOPTopology *m_sloop_topology;
205 m_sloop_matrix(
NULL){
206 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixSloop] NEW AlephMatrixSloop";
213 debug() <<
"\33[1;5;32m\t\t\t[~AlephMatrixSloop]\33[0m";
214 delete m_sloop_matrix;
222 void AlephMatrixCreate(
void)
225 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixCreate] create new SLOOP::SLOOPDistMatrix";
233 if (!m_sloop_matrix)
throw Exception(
"AlephSolverMatrix::create",
"new SLOOPDistMatrix() failed");
237 m_sloop_matrix->set_renumbering_opt(SLOOP::SLOOPDistMatrix::interface,
false);
238 m_sloop_matrix->set_renumbering_opt(SLOOP::SLOOPDistMatrix::processor,
false);
239 m_sloop_matrix->set_renumbering_opt(SLOOP::SLOOPDistMatrix::interior,
false);
240 m_sloop_matrix->init_length(m_kernel->topology()->gathered_nb_row_elements().unguardedBasePointer());
241 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixCreate] done";
248 void AlephMatrixSetFilled(
bool toggle){
250 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixSetFilled]";
251 m_sloop_matrix->setfilled(
toggle);
258 int AlephMatrixAssemble(
void){
260 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixAssemble]";
261 m_sloop_matrix->configure();
269 void AlephMatrixFill(
int size,
int *
rows,
int *
cols,
double *values){
271 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixFill] size="<<size;
272 m_sloop_matrix->locfill(values,
rows,
cols, size);
273 debug()<<
"\t\t[AlephMatrixSloop::AlephMatrixFill] done";
280 bool isAlreadySolved(SLOOP::SLOOPDistVector* x,
281 SLOOP::SLOOPDistVector*
b,
282 SLOOP::SLOOPDistVector*
tmp,
285 const Real
res0 =
b->norm_max();
290 debug() <<
"analyse convergence : norme max du second membre res0 : " <<
res0;
296 debug() <<
"analyse convergence : le second membre du système linéaire est inférieur à "
301 if (params->xoUser()) {
303 m_sloop_matrix->vector_multiply(*
tmp,*x);
306 debug() <<
"[IAlephSloop::isAlreadySolved] residu="<<
residu;
311 debug() <<
"analyse convergence : x0 est déjà solution du système.";
318 debug() <<
"analyse convergence : résidu initial : " <<
residu
319 <<
" --- residu relatif initial (residu/res0) : " <<
residu /
res0;
323 debug() <<
"analyse convergence : X est déjà solution du système";
345 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] getTopologyImplementation #"<<m_index;
357 SLOOP::SLOOPDistVector*
RHS =
b_sloop->m_sloop_vector;
361 debug() <<
"\t[AlephMatrixSloop::AlephMatrixSolve] isAlreadySolved !";
376 this->setSloopPreconditionnerParameters(
solver_param, precond.get());
379 const bool normalize = normalizeSolverMatrix(
solver_param);
381 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] Normalize";
388 case TypesSolver::NONE:
391 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] xo à true (sans preconditionnement)";
394 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] xo à false (sans preconditionnement)";
401 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] xo à true (avec preconditionnement)";
404 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] xo à false (avec preconditionnement)";
411 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] INV-normalize";
425 info() <<
"\n============================================================";
427 info() <<
"\nOn a atteind le nombre max d'itérations du solveur ";
428 info() <<
"\nIl est possible de demander au code de ne pas tenir compte de cette erreur.";
429 info() <<
"\nVoir la documentation du jeu de données concernant le service solveur.";
430 info() <<
"\n============================================================";
431 throw Exception(
"AlephMatrixSloop::SloopSolve",
"On a atteind le nombre max d'itérations du solveur");
434 debug() <<
"\t\t[AlephMatrixSloop::SloopSolve] nbIteration="<<
global_solver->get_iteration()
445 m_sloop_matrix->write_to_file(
file_name.localstr());
462 case TypesSolver::SuperLU:{
464 solver->set_parameter(SLOOP::sv_residual_calculation, 1);
467 default:
throw Exception(
"AlephMatrixSloop::createSloopSolver",
"Type de solver non accessible pour la bibliothèque SLOOP");
481 case TypesSolver::AINV:
496 case TypesSolver::NONE:
return NULL;
497 default:
throw Exception(
"AlephMatrixSloop::createSloopPreconditionner",
498 "préconditionneur non accessible pour la bibliothèque SLOOP");
511 case TypesSolver::RR0:
return new SLOOP::SLOOPStopCriteriaRR0();
512 case TypesSolver::R:
return new SLOOP::SLOOPStopCriteriaR();
513 case TypesSolver::RCB:
return new SLOOP::SLOOPStopCriteriaRCB();
514 case TypesSolver::RBinf:
return new SLOOP::SLOOPStopCriteriaRBinf();
515 case TypesSolver::EpsA:
return new SLOOP::SLOOPStopCriteriaEpsA();
516 case TypesSolver::NIter:
return new SLOOP::SLOOPStopCriteriaNIter();
517 case TypesSolver::RR0inf:
return new SLOOP::SLOOPStopCriteriaRR0inf();
518 case TypesSolver::STAG:
return new SLOOP::SLOOPStopCriteriaSTAG();
519 case TypesSolver::RB:
520 default:
return new SLOOP::SLOOPStopCriteriaRB();
537 case TypesSolver::PCG:
break;
538 case TypesSolver::QMR:
break;
539 case TypesSolver::SuperLU:
break;
540 case TypesSolver::BiCGStab:
error +=
sloop_solver->set_parameter(SLOOP::bicg_dimension, 1);
break;
541 case TypesSolver::BiCGStab2:
error +=
sloop_solver->set_parameter(SLOOP::bicg_dimension, 2);
break;
542 case TypesSolver::GMRES:
546 case TypesSolver::SAMG: {
549 if (gamma == -1) gamma = 50;
553 if (alpha < 0.0) alpha = 0.1;
562 static_cast<SLOOP::SLOOPAMGCoarseningOption
> (
solver_param->getAmgCoarseningOption());
567 static_cast<SLOOP::SLOOPAMGCoarseSolverOption
> (
solver_param->getAmgCoarseSolverOption());
572 static_cast<SLOOP::SLOOPAMGSmootherOption
> (
solver_param->getAmgSmootherOption());
577 default:
throw Exception(
"AlephMatrixSloop::setSloopSolverParameters",
578 "Type de solver SLOOP non prévu dans la gestion des paramètres");
581 throw Exception(
"AlephMatrixSloop::setSloopSolverParameters",
"set_parameter() failed");
592 const String function_id =
"SolverMatrixSloop::setSloopPreconditionnerParameters";
595 if (alpha < 0.0) alpha = 0.1;
597 case TypesSolver::NONE:
break;
598 case TypesSolver::DIAGONAL:
break;
599 case TypesSolver::AMG: {
600 if (gamma == -1) gamma = 50;
608 static_cast<SLOOP::SLOOPAMGSmootherOption
> (
solver_param->getAmgSmootherOption());
611 static_cast<SLOOP::SLOOPAMGCoarseningOption
> (
solver_param->getAmgCoarseningOption());
614 static_cast<SLOOP::SLOOPAMGCoarseSolverOption
> (
solver_param->getAmgCoarseSolverOption());
619 case TypesSolver::CG_smoother:
620 case TypesSolver::Rich_IC_smoother:
621 case TypesSolver::Rich_AINV_smoother:
622 case TypesSolver::SymHybGSJ_smoother:
623 case TypesSolver::Rich_IC_block_smoother:
624 case TypesSolver::SymHybGSJ_block_smoother:
626 default:
throw Exception(
"AlephMatrixSloop::setSloopPreconditionnerParameters",
627 "choix du smoother incorrect pour une matrice symetrique");
632 case TypesSolver::CG_smoother:
633 case TypesSolver::Rich_IC_smoother:
634 case TypesSolver::Rich_AINV_smoother:
635 case TypesSolver::Rich_IC_block_smoother:
636 case TypesSolver::SymHybGSJ_block_smoother:
637 throw Exception(
"AlephMatrixSloop::setSloopPreconditionnerParameters",
638 "choix du smoother incorrect avec une matrice non-symetrique ");
639 case TypesSolver::SymHybGSJ_smoother:
641 solver_param->setAmgSmootherOption(TypesSolver::HybGSJ_smoother);
647 case TypesSolver::CG_coarse_solver:
648 case TypesSolver::Cholesky_coarse_solver:
649 solver_param->setAmgCoarseSolverOption(TypesSolver::LU_coarse_solver);
651 default:
solver_param->setAmgCoarseSolverOption(TypesSolver::BiCGStab_coarse_solver);
664 case TypesSolver::POLY:
665 if (gamma == -1) gamma = 3;
667 case TypesSolver::AINV:
668 if (gamma == -1) gamma = 0;
671 case TypesSolver::IC:
672 case TypesSolver::ILU:
if (gamma == -1) gamma = 0;
break;
673 case TypesSolver::ILUp:
if (gamma == -1) gamma = 1;
break;
674 case TypesSolver::SPAIstat:
675 preconditionner->set_parameter(SLOOP::spai_sparsity,SLOOP::StatSparsity);
676 preconditionner->set_parameter(SLOOP::spai_init_sparsity,SLOOP::PowerSparsity);
681 case TypesSolver::SPAIdyn:
682 preconditionner->set_parameter(SLOOP::spai_sparsity, SLOOP::DynSparsity);
683 preconditionner->set_parameter(SLOOP::spai_init_sparsity, SLOOP::DiagSparsity);
688 throw Exception(
"AlephMatrixSloop::setSloopPreconditionnerParameters",
"Préconditionneur inconnu.");
693 case TypesSolver::NONE:
694 case TypesSolver::SPAIstat:
695 case TypesSolver::SPAIdyn:
698 case TypesSolver::AMG:
703 preconditionner->set_parameter(SLOOP::amg_coarse_solver_sc_option,SLOOP::RB);
722 case TypesSolver::AINV:
724 case TypesSolver::SPAIstat:
725 case TypesSolver::SPAIdyn:
return true;
726 case TypesSolver::AMG:
727 case TypesSolver::NONE:
728 case TypesSolver::DIAGONAL:
729 case TypesSolver::IC:
730 case TypesSolver::POLY:
731 case TypesSolver::ILU:
732 case TypesSolver::ILUp:
return false;
733 default:
throw Exception(
"AlephMatrixSloop::normalizeSolverMatrix",
"Préconditionneur inconnu.");
738 SLOOP::SLOOPMatrix* m_sloop_matrix;