13#include "arcane/aleph/AlephArcane.h"
14#include "arcane/MeshVariableScalarRef.h"
28AlephMatrix(AlephKernel* kernel)
29: TraceAccessor(kernel->parallel()->traceMng())
31, m_index(kernel->index())
35 ItacFunction(AlephMatrix);
36 if (kernel->isInitialized() ==
false) {
37 debug() <<
"\33[1;32m[AlephMatrix::AlephMatrix] New Aleph matrix, but kernel is not initialized!\33[0m";
41 m_ranks = kernel->solverRanks(m_index);
43 m_participating_in_solver = kernel->subParallelMng(m_index) != NULL;
44 debug() <<
"\33[1;32m[AlephMatrix::AlephMatrix] New Aleph matrix\33[0m";
45 if (!m_participating_in_solver) {
46 debug() <<
"\33[1;32m[AlephMatrix::AlephMatrix] Not concerned by this one!\33[0m";
49 debug() <<
"\33[1;32m[AlephMatrix::AlephMatrix] site size="
50 << m_kernel->subParallelMng(m_index)->commSize()
52 << m_kernel->subParallelMng(m_index)->commRank() <<
"\33[0m";
54 m_implementation = m_kernel->factory()->GetMatrix(m_kernel, m_index);
63 ItacFunction(AlephMatrix);
64 debug() <<
"\33[1;32m\t\t[~AlephMatrix]\33[0m";
65 rowColMap::const_iterator i = m_row_col_map.begin();
66 for (; i != m_row_col_map.end(); ++i)
74void AlephMatrix::create(
void)
76 Timer::Action ta(m_kernel->subDomain(),
"AlephMatrix::create");
77 debug() <<
"\33[1;32m[AlephMatrix::create(void)]\33[0m";
79 if (!m_kernel->isInitialized())
83 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther())
84 m_kernel->world()->broadcast(UniqueArray<unsigned long>(1, 0xfff06e2l).view(), 0);
95create(IntegerConstArrayView row_nb_element,
bool has_many_elements)
97 ARCANE_UNUSED(row_nb_element);
98 ARCANE_UNUSED(has_many_elements);
99 debug() <<
"\33[1;32m[AlephMatrix::create(old API)] API with row_nb_element + has_many_elements\33[0m";
110 debug() <<
"\33[1;32m[AlephMatrix::reset]\33[0m";
111 m_setValue_val.fill(0.0);
112 m_addValue_val.fill(0.0);
131 if (m_kernel->isInitialized()) {
137 addValue(row, col, val);
141updateKnownRowCol(Integer row,
146 m_addValue_row.add(row);
147 m_addValue_col.add(col);
148 m_addValue_val.add(val);
151 m_setValue_row.add(row);
152 m_setValue_col.add(col);
153 m_setValue_val.add(0.);
157rowMapMapCol(Integer row,
161 rowColMap::const_iterator iRowMap = m_row_col_map.find(row);
164 if (iRowMap == m_row_col_map.end()) {
165 colMap* jMap =
new colMap();
169 m_row_col_map.insert(std::make_pair(row, jMap));
170 jMap->insert(std::make_pair(col, m_addValue_idx));
171 updateKnownRowCol(row, col, val);
175 colMap* jMap = iRowMap->second;
176 colMap::const_iterator iColMap = jMap->find(col);
179 if (iColMap == jMap->end()) {
183 jMap->insert(std::make_pair(col, m_addValue_idx));
184 updateKnownRowCol(row, col, val);
190 m_addValue_val[iColMap->second] += val;
197addValue(Integer row, Integer
col, Real
val)
200 row = m_kernel->ordering()->swap(row);
201 col = m_kernel->ordering()->swap(
col);
203 rowMapMapCol(row,
col,
val);
225 Integer row = m_kernel->indexing()->get(
rowVar,
rowItm);
228 if (m_kernel->isInitialized()) {
229 const Integer
row_offset = m_kernel->topology()->part()[m_kernel->rank()];
240setValue(Integer row, Integer
col, Real
val)
243 row = m_kernel->ordering()->swap(row);
244 col = m_kernel->ordering()->swap(
col);
247 if (m_kernel->configured()) {
248 if ((m_setValue_row[m_setValue_idx] != row) ||
249 (m_setValue_col[m_setValue_idx] !=
col))
251 m_setValue_row[m_setValue_idx] = row;
252 m_setValue_col[m_setValue_idx] =
col;
253 m_setValue_val[m_setValue_idx] =
val;
256 m_setValue_row.add(row);
257 m_setValue_col.add(
col);
258 m_setValue_val.add(
val);
280 for (Integer
k = 0,
kMx = m_setValue_idx;
k <
kMx;
k += 1) {
294 for (Integer
k = 0,
kMx = m_addValue_row.size();
k <
kMx;
k += 1) {
297 const Real
val = m_addValue_val[
k];
311 if (!m_kernel->isInitialized()) {
312 debug() <<
"\33[1;32m[AlephMatrix::assemble] Trying to assemble a matrix"
313 <<
"from an uninitialized kernel!\33[0m";
317 if (m_addValue_idx != 0 && m_setValue_idx != 0)
318 throw FatalErrorException(
"AlephMatrix::assemble",
"Still exclusives [add||set]Value required!");
321 if (m_addValue_idx != 0) {
322 debug() <<
"\33[1;32m[AlephMatrix::assemble] m_addValue_idx!=0\33[0m";
326 debug() <<
"\t\33[32m[AlephMatrix::assemble] Flatenning addValues size=" << m_addValue_row.size() <<
"\33[0m";
327 for (Integer
k = 0,
kMx = m_addValue_row.size();
k <
kMx; ++
k) {
328 m_setValue_row[
k] = m_addValue_row[
k];
329 m_setValue_col[
k] = m_addValue_col[
k];
330 m_setValue_val[
k] = m_addValue_val[
k];
337 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther()) {
338 debug() <<
"\33[1;32m[AlephMatrix::assemble] On informe les autres kappa que l'on assemble"
345 if (!m_kernel->isAnOther()) {
346 debug() <<
"\33[1;32m[AlephMatrix::assemble] Initializing topology"
349 m_kernel->topology()->create(m_setValue_idx);
353 debug() <<
"\33[1;32m[AlephMatrix::assemble] Updating row_nb_element"
355 if (!m_kernel->topology()->hasSetRowNbElements()) {
360 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther()) {
361 debug() <<
"\33[1;32m[AlephMatrix::assemble] Kernel's topology has not set its nb_row_elements, now doing it!"
363 const Integer
row_offset = m_kernel->topology()->part()[m_kernel->rank()];
364 debug() <<
"\33[1;32m[AlephMatrix::assemble] row_offset=" <<
row_offset <<
"\33[0m";
365 debug() <<
"\33[1;32m[AlephMatrix::assemble] filled, row_nb_element.size=" <<
row_nb_element.size() <<
"\33[0m";
367 for (Integer i = 0,
iMx = m_setValue_row.size(); i <
iMx; ++i)
371 debug() <<
"\33[1;32m[AlephMatrix::assemble] done hasSetRowNbElements"
375 debug() <<
"\33[1;32m[AlephMatrix::assemble] Récupération des parties de matrices"
377 if (m_participating_in_solver && (!m_kernel->configured())) {
382 for (Integer
iCpu = 0;
iCpu < m_kernel->size(); ++
iCpu) {
383 if (m_kernel->rank() != m_ranks[
iCpu])
391 m_aleph_matrix_buffer_rows.resize(
nbValues);
392 m_aleph_matrix_buffer_cols.resize(
nbValues);
393 m_aleph_matrix_buffer_vals.resize(
nbValues);
397 if (!m_kernel->isParallel())
400 if (m_participating_in_solver) {
402 debug() <<
"\33[1;32m[AlephMatrix::assemble] I am part of the solver, let's iRecv"
405 for (Integer
iCpu = 0;
iCpu < m_kernel->size(); ++
iCpu) {
407 if (
iCpu == m_kernel->rank())
410 if (m_kernel->rank() != m_ranks[
iCpu])
412 debug() <<
"\33[1;32m[AlephMatrix::assemble] "
413 <<
" recv " << m_kernel->rank()
415 <<
" size=" << m_aleph_matrix_buffer_cols[
iCpu].size() <<
"\33[0m";
416 m_aleph_matrix_mpi_data_requests.add(m_kernel->world()->recv(m_aleph_matrix_buffer_vals[
iCpu],
iCpu,
false));
418 if (!m_kernel->configured()) {
419 m_aleph_matrix_mpi_data_requests.add(m_kernel->world()->recv(m_aleph_matrix_buffer_rows[
iCpu],
iCpu,
false));
420 m_aleph_matrix_mpi_data_requests.add(m_kernel->world()->recv(m_aleph_matrix_buffer_cols[
iCpu],
iCpu,
false));
425 if ((m_kernel->rank() != m_ranks[m_kernel->rank()]) && (!m_kernel->isAnOther())) {
427 debug() <<
"\33[1;32m[AlephMatrix::assemble]"
428 <<
" send " << m_kernel->rank()
429 <<
" => " << m_ranks[m_kernel->rank()]
430 <<
" for " << m_setValue_val.size() <<
"\33[0m";
431 m_aleph_matrix_mpi_data_requests.add(m_kernel->world()->send(m_setValue_val, m_ranks[m_kernel->rank()],
false));
432 if (!m_kernel->configured()) {
433 debug() <<
"\33[1;32m[AlephMatrix::assemble] iSend my row to " << m_ranks[m_kernel->rank()] <<
"\33[0m";
434 m_aleph_matrix_mpi_data_requests.add(m_kernel->world()->send(m_setValue_row, m_ranks[m_kernel->rank()],
false));
435 debug() <<
"\33[1;32m[AlephMatrix::assemble] iSend my col to " << m_ranks[m_kernel->rank()] <<
"\33[0m";
436 m_aleph_matrix_mpi_data_requests.add(m_kernel->world()->send(m_setValue_col, m_ranks[m_kernel->rank()],
false));
449 debug() <<
"\33[1;32m[AlephMatrix::create_really]"
452 debug() <<
"\33[1;32m[AlephMatrix::create_really] new MATRIX"
455 m_implementation->AlephMatrixCreate();
456 debug() <<
"\33[1;32m[AlephMatrix::create_really] done"
464assemble_waitAndFill(
void)
467 Timer::Action ta(m_kernel->subDomain(),
"AlephMatrix::assemble_waitAndFill");
468 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill]"
470 if (m_kernel->isParallel()) {
472 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] wait for "
473 << m_aleph_matrix_mpi_data_requests.size() <<
" Requests"
475 m_kernel->world()->waitAllRequests(m_aleph_matrix_mpi_data_requests);
476 m_aleph_matrix_mpi_data_requests.clear();
477 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] clear"
479 if (m_participating_in_solver ==
false) {
480 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] nothing more to do"
485 if (!m_participating_in_solver)
488 if (!m_kernel->configured()) {
490 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] solver " << m_index <<
" create_really"
497 if (m_kernel->configured())
498 m_implementation->AlephMatrixSetFilled(
false);
499 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] " << m_index <<
" fill"
505 if (m_kernel->rank() != m_ranks[
iCpu])
507 if (
iCpu == m_kernel->rank()) {
511 m_implementation->AlephMatrixFill(m_setValue_val.size(),
520 m_implementation->AlephMatrixFill(m_aleph_matrix_buffer_vals[
iCpu].size(),
529 m_implementation->AlephMatrixSetFilled(
true);
530 if (!m_kernel->configured()) {
531 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] " << m_index <<
" MATRIX ASSEMBLE"
534 assrtnd = m_implementation->AlephMatrixAssemble();
535 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] AlephMatrixAssemble=" <<
assrtnd <<
"\33[0m";
539 debug() <<
"\33[1;32m[AlephMatrix::assemble_waitAndFill] done"
556 debug() <<
"\33[1;32m[AlephMatrix::solve] Queuing solver " << m_index <<
"\33[0m";
561 debug() <<
"\33[1;32m[AlephMatrix::solve] SYNCHRONOUS MODE has been requested, syncing!"
587 (m_kernel->rank() == 0) &&
588 (params->writeMatrixToFileErrorStrategy()) &&
589 (m_kernel->subDomain()->commonVariables().globalIteration() == 1) &&
590 (m_kernel->nbRanksPerSolver() == 1);
592 if (!m_participating_in_solver) {
593 debug() <<
"\33[1;32m[AlephMatrix::solveNow] Nothing to do here!"
597 debug() <<
"\33[1;32m[AlephMatrix::solveNow]"
600 const Integer globalIteration = m_kernel->subDomain()->commonVariables().globalIteration();
603 warning() <<
"[AlephMatrix::solveNow] mtxFileName rhsFileName write_to_file";
608 m_implementation->AlephMatrixSolve(x,
b,
tmp,
613 const Integer globalIteration = m_kernel->subDomain()->commonVariables().globalIteration();
617 if (m_kernel->isCellOrdering())
618 debug() <<
"\33[1;32m[AlephMatrix::solveSync_waitAndFill] // nb_iteration="
620 if (m_kernel->isParallel())
622 debug() <<
"\33[1;32m[AlephMatrix::solveSync_waitAndFill] // nb_iteration="
637 if (!m_kernel->isParallel())
639 m_aleph_matrix_buffer_n_iteration.resize(1);
641 m_aleph_matrix_buffer_residual_norm.resize(4);
647 if (m_kernel->rank() != m_ranks[m_kernel->rank()] && !m_kernel->isAnOther()) {
648 debug() <<
"\33[1;32m[AlephMatrix::REassemble] " << m_kernel->rank()
649 <<
"<=" << m_ranks[m_kernel->rank()] <<
"\33[0m";
650 m_aleph_matrix_mpi_results_requests.add(m_kernel->world()->recv(m_aleph_matrix_buffer_n_iteration,
651 m_ranks[m_kernel->rank()],
false));
652 m_aleph_matrix_mpi_results_requests.add(m_kernel->world()->recv(m_aleph_matrix_buffer_residual_norm,
653 m_ranks[m_kernel->rank()],
false));
655 if (m_participating_in_solver) {
656 debug() <<
"\33[1;32m[AlephMatrix::REassemble] have participated, should send:"
658 for (Integer
iCpu = 0;
iCpu < m_kernel->size(); ++
iCpu) {
659 if (
iCpu == m_kernel->rank())
661 if (m_kernel->rank() != m_ranks[
iCpu])
663 debug() <<
"\33[1;32m[AlephMatrix::REassemble] " << m_kernel->rank() <<
" => " <<
iCpu <<
"\33[0m";
664 m_aleph_matrix_mpi_results_requests.add(m_kernel->world()->send(m_aleph_matrix_buffer_n_iteration,
666 m_aleph_matrix_mpi_results_requests.add(m_kernel->world()->send(m_aleph_matrix_buffer_residual_norm,
679 Timer::Action ta(m_kernel->subDomain(),
"AlephMatrix::reassemble_waitAndFill");
680 if (!m_kernel->isParallel())
682 debug() <<
"\33[1;32m[AlephMatrix::REassemble_waitAndFill]"
685 m_kernel->world()->waitAllRequests(m_aleph_matrix_mpi_results_requests);
686 m_aleph_matrix_mpi_results_requests.clear();
687 if (!m_participating_in_solver) {
694 debug() <<
"\33[1;32m[AlephMatrix::REassemble_waitAndFill] // nb_iteration="
706 debug() <<
"[AlephMatrix::startFilling] void"
717 debug() <<
"\33[1;32m[AlephMatrix::writeToFile] Dumping matrix to " <<
file_name <<
"\33[0m";
718 m_implementation->writeToFile(
file_name);
Matrice d'un système linéaire.
Paramètres d'un système linéraire.
Vecteur d'un système linéaire.
Classe de base d'un élément de maillage.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Postionne le nom de l'action en cours d'exécution.
Référence à une variable.
Exception lorsqu'une erreur fatale est survenue.
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-