Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MetisGraphDigest.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/* MetisGraphDigest.cc (C) 2000-2025 */
9/* */
10/* Calculates a global checksum of Metis inputs/outputs. */
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{
33 MD5HashAlgorithm hash_algo;
34 const Integer idx_t_size = sizeof(idx_t);
35 const Integer real_t_size = sizeof(real_t);
36} // namespace
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41MetisGraphDigest::
42MetisGraphDigest(IParallelMng* pm)
43: TraceAccessor(pm->traceMng())
44, m_parallel_mng(pm)
45, m_my_rank(pm->commRank())
46, m_nb_rank(pm->commSize())
47{
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
57String MetisGraphDigest::
58_digestString(ConstArrayView<Byte> my_digest)
59{
60 String digest_string;
61
62 bool is_master_io = m_parallel_mng->isMasterIO();
63 Int32 io_master_rank = m_parallel_mng->masterIORank();
64
65 UniqueArray<Byte> concat_digest;
66
67 m_parallel_mng->gatherVariable(my_digest, concat_digest, io_master_rank);
68
69 if (is_master_io) {
70 UniqueArray<Byte> final_digest;
71 hash_algo.computeHash64(concat_digest, final_digest);
72 digest_string = Convert::toHexaString(final_digest);
73 info() << "DigestString s=" << digest_string;
74 }
75
76 return digest_string;
77}
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82void MetisGraphDigest::
83_computeHash(Span<const idx_t> data, ByteArray& output, const char* name)
84{
86 hash_algo.computeHash64(Arccore::asBytes(data), bytes);
87 info() << "COMPUTE_HASH=" << name << " v=" << Convert::toHexaString(bytes);
88 output.addRange(bytes);
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94void MetisGraphDigest::
95_computeHash(Span<const real_t> data, ByteArray& output, const char* name)
96{
97 UniqueArray<Byte> bytes;
98 hash_algo.computeHash64(Arccore::asBytes(data), bytes);
99 info() << "COMPUTE_HASH=" << name << " v=" << Convert::toHexaString(bytes);
100 output.addRange(bytes);
101}
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 of the graph itself
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 // Addition of the signature of options and 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 : if options[0] == 1 then the size of "options" is 3 or 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)
Adds n elements of value val to the end of the array.
Constant view of an array of type T.
Interface of the parallelism manager for a subdomain.
Calculates the MD5 hashing function of an array.
String _digestString(ConstArrayView< Byte > my_digest)
From the local sum, calculates the global sum and returns a string representing this sum (only on pro...
View of an array of elements of type T.
Definition Span.h:635
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
String toHexaString(ByteConstArrayView input)
Converts a byte array to its hexadecimal representation.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
std::int32_t Int32
Signed integer type of 32 bits.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
Definition Span.h:1032