Arcane  v3.16.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MetisGraphDigest.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* MetisGraphDigest.cc (C) 2000-2025 */
9/* */
10/* Calcule une somme de contrôle globale des entrées/sorties Metis. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/MD5HashAlgorithm.h"
15#include "arcane/utils/FatalErrorException.h"
16#include "arcane/utils/ValueConvert.h"
17
18#include "arcane/core/IParallelMng.h"
19
20#include "arcane/std/internal/MetisGraphDigest.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace
32{
33MD5HashAlgorithm hash_algo;
34const Integer idx_t_size = sizeof(idx_t);
35const Integer real_t_size = sizeof(real_t);
36
37} // namespace
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42MetisGraphDigest::
43MetisGraphDigest(IParallelMng* pm)
44: TraceAccessor(pm->traceMng())
45, m_parallel_mng(pm)
46, m_my_rank(pm->commRank())
47, m_nb_rank(pm->commSize())
48{
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
58String MetisGraphDigest::
59_digestString(ConstArrayView<Byte> my_digest)
60{
61 String digest_string;
62
63 bool is_master_io = m_parallel_mng->isMasterIO();
64 Int32 io_master_rank = m_parallel_mng->masterIORank();
65
66 UniqueArray<Byte> concat_digest;
67
68 m_parallel_mng->gatherVariable(my_digest, concat_digest, io_master_rank);
69
70 if (is_master_io) {
71 UniqueArray<Byte> final_digest;
72 hash_algo.computeHash64(concat_digest, final_digest);
73 digest_string = Convert::toHexaString(final_digest);
74 info() << "DigestString s=" << digest_string;
75 }
76
77 return digest_string;
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83void MetisGraphDigest::
84_computeHash(Span<const idx_t> data, ByteArray& output, const char* name)
85{
87 hash_algo.computeHash64(Arccore::asBytes(data), bytes);
88 info() << "COMPUTE_HASH=" << name << " v=" << Convert::toHexaString(bytes);
89 output.addRange(bytes);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95void MetisGraphDigest::
96_computeHash(Span<const real_t> data, ByteArray& output, const char* name)
97{
98 UniqueArray<Byte> bytes;
99 hash_algo.computeHash64(Arccore::asBytes(data), bytes);
100 info() << "COMPUTE_HASH=" << name << " v=" << Convert::toHexaString(bytes);
101 output.addRange(bytes);
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106#define COMPUTE_HASH1(array, output) _computeHash(array, output, #array)
107#define COMPUTE_HASH(array, n, output) _computeHash({ array, n }, output, #array)
108
109String MetisGraphDigest::
110computeInputDigest(const bool need_part, const int nb_options, const MetisGraphView& my_graph,
111 const idx_t* vtxdist, const idx_t* wgtflag, const idx_t* numflag, const idx_t* ncon,
112 const idx_t* nparts, const real_t* tpwgts, const real_t* ubvec, const real_t* ipc2redist,
113 const idx_t* options)
114{
115 UniqueArray<Byte> hash_value;
116
117 // Signature du graph lui-meme
118
119 COMPUTE_HASH1(my_graph.xadj, hash_value);
120 COMPUTE_HASH1(my_graph.adjncy, hash_value);
121 COMPUTE_HASH1(my_graph.vwgt, hash_value);
122
123 if (my_graph.have_vsize) {
124 COMPUTE_HASH1(my_graph.vsize, hash_value);
125 }
126
127 if (my_graph.have_adjwgt) {
128 COMPUTE_HASH1(my_graph.adjwgt, hash_value);
129 }
130
131 if (need_part) {
132 COMPUTE_HASH1(my_graph.part, hash_value);
133 }
134
135 // Ajout de la signature des options, des dimensions
136
137 COMPUTE_HASH(vtxdist, m_nb_rank + 1, hash_value);
138 COMPUTE_HASH(wgtflag, 1, hash_value);
139 COMPUTE_HASH(numflag, 1, hash_value);
140 COMPUTE_HASH(ncon, 1, hash_value);
141 COMPUTE_HASH(nparts, 1, hash_value);
142 COMPUTE_HASH(tpwgts, (*nparts) * (*ncon), hash_value);
143 COMPUTE_HASH(ubvec, (*ncon), hash_value);
144
145 if (ipc2redist) {
146 COMPUTE_HASH(ipc2redist, 1, hash_value);
147 }
148
149 // Cf. doc Metis : si options[0] == 1 alors la taille de "options" est 3 ou 4
150 if ((*options) == 1) {
151 COMPUTE_HASH(options, nb_options, hash_value);
152 }
153 else {
154 COMPUTE_HASH(options, 1, hash_value);
155 }
156
157 return _digestString(hash_value);
158}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163String MetisGraphDigest::
164computeOutputDigest(const MetisGraphView& my_graph, const idx_t* edgecut)
165{
166 UniqueArray<Byte> hash_value;
167
168 COMPUTE_HASH1(my_graph.part, hash_value);
169 COMPUTE_HASH(edgecut, 1, hash_value);
170
171 return _digestString(hash_value);
172}
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176} // End namespace Arcane
177
178/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
Vue constante d'un tableau de type T.
Interface du gestionnaire de parallélisme pour un sous-domaine.
Calcule la fonction de hashage MD5 d'un tableau.
String _digestString(ConstArrayView< Byte > my_digest)
A partir de la somme locale, calcule la somme globale et retourne une chaine de caractères représenta...
Vue d'un tableau d'éléments de type T.
Definition Span.h:513
Chaîne de caractères unicode.
TraceMessage info() const
Flot pour un message d'information.
Vecteur 1D de données avec sémantique par valeur (style STL).
String toHexaString(ByteConstArrayView input)
Converti un tableau d'octet en sa représentation hexadécimale.
Definition Convert.cc:75
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
Array< Byte > ByteArray
Tableau dynamique à une dimension de caractères.
Definition UtilsTypes.h:208
std::int32_t Int32
Type entier signé sur 32 bits.
impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets non modifiables.
Definition Span.h:884