Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
SynchronizerMatrixPrinter.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* SynchronizerMatrixPrinter.h (C) 2011-2011 */
9/* */
10/* Displays the synchronization matrix. */
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/utils/Array.h"
14#include "arcane/utils/String.h"
15#include "arcane/utils/CheckedConvert.h"
16
17#include "arcane/core/IParallelMng.h"
19#include "arcane/core/SynchronizerMatrixPrinter.h"
20
21#include <iomanip>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32SynchronizerMatrixPrinter::
33SynchronizerMatrixPrinter(IVariableSynchronizer* synchronizer)
34: m_synchronizer(synchronizer)
35{
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44void SynchronizerMatrixPrinter::
45print(std::ostream& o) const
46{
47 IParallelMng* parallel_mng = m_synchronizer->parallelMng();
48 Int32ConstArrayView communicating_ranks = m_synchronizer->communicatingRanks();
49 Int32UniqueArray shared_counts(communicating_ranks.size());
50 for (Integer i = 0; i < communicating_ranks.size(); ++i)
51 shared_counts[i] = m_synchronizer->sharedItems(i).size();
52 Int32UniqueArray ghost_counts(communicating_ranks.size());
53 for (Integer i = 0; i < communicating_ranks.size(); ++i)
54 ghost_counts[i] = m_synchronizer->ghostItems(i).size();
55 Int32UniqueArray comm_size(1);
56 comm_size[0] = communicating_ranks.size();
57
58 Int32UniqueArray all_comm_sizes(parallel_mng->commSize());
59 parallel_mng->gather(comm_size, all_comm_sizes, 0);
60 Int32UniqueArray all_communicating_ranks;
61 parallel_mng->gatherVariable(communicating_ranks, all_communicating_ranks, 0);
62 Int32UniqueArray all_shared_counts;
63 parallel_mng->gatherVariable(shared_counts, all_shared_counts, 0);
64 Int32UniqueArray all_ghost_counts;
65 parallel_mng->gatherVariable(ghost_counts, all_ghost_counts, 0);
66 ARCANE_ASSERT((all_ghost_counts.size() == all_shared_counts.size()), ("Incompatible shared / ghost counts"));
67
68 if (parallel_mng->commRank() == 0) {
69 Int32UniqueArray all_offsets(all_comm_sizes.size() + 1);
70 all_offsets[0] = 0;
71 for (Integer i = 0; i < all_comm_sizes.size(); ++i)
72 all_offsets[i + 1] = all_offsets[i] + all_comm_sizes[i];
73
74 Int64 text_width0 = String::format("{0}", parallel_mng->commSize()).length();
75 for (Integer i = 0; i < all_shared_counts.size(); ++i)
76 text_width0 = math::max(text_width0, String::format("{0} / {1}", all_shared_counts[i], all_ghost_counts[i]).length());
77 text_width0 = math::max(6, text_width0);
78 Int32 text_width = CheckedConvert::toInt32(text_width0);
79
80 o << "\n"
81 << std::setw(text_width) << "" << " ";
82 for (Integer j = 0; j < parallel_mng->commSize(); ++j)
83 o << std::setw(text_width) << j << " ";
84 o << "\n";
85
86 for (Integer i = 0; i < parallel_mng->commSize(); ++i) {
87 o << std::setw(text_width) << i << " : ";
88 Integer jstart = all_offsets[i];
89 Integer jend = all_offsets[i + 1];
90 for (Integer j = 0; j < parallel_mng->commSize(); ++j) {
91 if (jstart != jend && all_communicating_ranks[jstart] == j) {
92 o << std::setw(text_width) << String::format("{0} / {1}", all_shared_counts[jstart], all_ghost_counts[jstart]) << " ";
93 ++jstart;
94 }
95 else
96 o << std::setw(text_width) << "" << " ";
97 }
98 o << "\n";
99 }
100 o << "(i,j) = S/G : proc 'i' shares S items with 'j' / has G ghosts items from 'j'\n";
101 }
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107} // End namespace Arcane
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
Various mathematical functions.
Interface of a variable synchronization service.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341