Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
GatherGroup.h
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/* GatherGroup.h (C) 2000-2026 */
9/* */
10/* Class allowing the management of data groupings across the writer */
11/* sub-domains. */
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_CORE_INTERNAL_GATHERGROUP_H
14#define ARCANE_CORE_INTERNAL_GATHERGROUP_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/core/internal/IGatherGroup.h"
19
20#include "arcane/utils/Array.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class GatherGroupInfo;
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
43class ARCANE_CORE_EXPORT GatherGroup
44: public IGatherGroup
45{
46
47 public:
48
54 explicit GatherGroup(GatherGroupInfo* gather_group_info);
55
62
63 ~GatherGroup() override;
64
65 public:
66
67 bool isNeedGather() override;
68 void gatherToMasterIO(Int64 sizeof_elem, Span<const Byte> in, Span<Byte> out) override;
69
70 public:
71
78 void setGatherGroupInfo(GatherGroupInfo* gather_group_info);
79
91 template <class T>
93
105 template <class T>
107
108 private:
109
110 GatherGroupInfo* m_gather_group_info = nullptr;
111};
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
122class ARCANE_CORE_EXPORT GatherGroupInfo
123: public IGatherGroupInfo
124{
125 friend class GatherGroup;
126
127 public:
128
137 GatherGroupInfo(IParallelMng* parallel_mng, bool use_collective_io);
138
139 ~GatherGroupInfo() override;
140
141 public:
142
143 void computeSize(Int32 nb_elem_in) override;
144 void setNeedRecompute() override { m_is_computed = false; }
145 bool isComputed() override { return m_is_computed; }
146 Int32 nbElemOutput() override { return m_nb_elem_output; }
147 Int32 sizeOfOutput(Int32 sizeof_type) override { return m_nb_elem_output * sizeof_type; }
148 SmallSpan<Int32> nbElemRecvGatherToMasterIO() override;
149 Int32 nbWriterGlobal() override { return m_nb_writer_global; }
150
151 public:
152
153 void setCollectiveIO(bool enable) { m_use_collective_io = enable; }
154
165 template <class T>
166 void computeSizeT(Span<const T> in);
167
178 template <class T>
179 void computeSizeT(Span2<const T> in);
180
181 private:
182
183 IParallelMng* m_parallel_mng = nullptr;
184 bool m_use_collective_io = false;
185 UniqueArray<Int32> m_nb_elem_recv;
186 Int32 m_nb_elem_output = -1;
187 Int32 m_writer = -1;
188 Int32 m_nb_sender_to_writer = -1;
189 Int32 m_nb_writer_global = -1;
190 bool m_is_computed = false;
191};
192
193/*---------------------------------------------------------------------------*/
194/*---------------------------------------------------------------------------*/
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
198
199template <class T>
202{
203 out.clear();
204
205 Span<const Byte> in_b(reinterpret_cast<const Byte*>(in.data()), in.sizeBytes());
206
207 Int32 final_nb_elem = m_gather_group_info->m_nb_elem_output;
208 out.resizeNoInit(final_nb_elem);
209
210 Span<Byte> out_b(reinterpret_cast<Byte*>(out.data()), final_nb_elem * sizeof(T));
211
212 gatherToMasterIO(sizeof(T), in_b, out_b);
213}
214
215/*---------------------------------------------------------------------------*/
216/*---------------------------------------------------------------------------*/
217
218template <class T>
221{
222 out.clear();
223
224 Span<const Byte> in_b(reinterpret_cast<const Byte*>(in.data()), in.totalNbElement() * sizeof(T));
225
226 Int32 final_nb_elem = m_gather_group_info->m_nb_elem_output;
227 out.resizeNoInit(final_nb_elem, in.dim2Size());
228
229 Span<Byte> out_b(reinterpret_cast<Byte*>(out.span().data()), final_nb_elem * in.dim2Size() * sizeof(T));
230
231 gatherToMasterIO(in.dim2Size() * sizeof(T), in_b, out_b);
232}
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237/*---------------------------------------------------------------------------*/
238/*---------------------------------------------------------------------------*/
239
240template <class T>
246
247/*---------------------------------------------------------------------------*/
248/*---------------------------------------------------------------------------*/
249
250template <class T>
256
257/*---------------------------------------------------------------------------*/
258/*---------------------------------------------------------------------------*/
259
260} // End namespace Arcane
261
262/*---------------------------------------------------------------------------*/
263/*---------------------------------------------------------------------------*/
264
265#endif
Class representing a classic 2D array.
void resizeNoInit(Int64 new_size)
Resizes only the first dimension, leaving the second dimension unchanged.
Base class for 1D data vectors.
void resizeNoInit(Int64 s)
Resizes without initializing new values.
void clear()
Removes the elements from the array.
const T * data() const
Access to the root of the array without any protection.
Class allowing the calculation and storage of grouping information.
Int32 sizeOfOutput(Int32 sizeof_type) override
Method allowing knowledge of the size, in bytes, of the set of elements that our subdomain must proce...
void computeSizeT(Span< const T > in)
Method allowing the calculation of grouping information.
void setNeedRecompute() override
Method allowing a request for recalculation of grouping information. To do this, the method computeSi...
void computeSize(Int32 nb_elem_in) override
Method allowing the calculation of grouping information.
GatherGroupInfo(IParallelMng *parallel_mng, bool use_collective_io)
Constructor.
Int32 nbWriterGlobal() override
Method allowing knowledge of the number of writing subdomains.
Int32 nbElemOutput() override
Method allowing knowledge of the number of elements that our subdomain must process after reception.
bool isComputed() override
Method allowing determination of whether the method computeSize() has already been called.
GatherGroup()
Constructor. For the object to be usable, it is necessary to call setGatherGroupInfo().
bool isNeedGather() override
Method allowing determination of whether the grouping needs to be performed or if the data can be wri...
void gatherToMasterIOT(Span< const T > in, Array< T > &out)
Method allowing the grouping of data from several sub-domains onto one or more sub-domains.
void gatherToMasterIO(Int64 sizeof_elem, Span< const Byte > in, Span< Byte > out) override
Method allowing the grouping of data from multiple subdomains onto one or more subdomains.
void setGatherGroupInfo(GatherGroupInfo *gather_group_info)
Method allowing the definition of grouping information.
GatherGroup(GatherGroupInfo *gather_group_info)
Constructor.
Interface class allowing the calculation and storage of grouping information.
Interface class allowing the grouping of data from certain subdomains onto other subdomains.
Interface of the parallelism manager for a subdomain.
View of an array of elements of type T.
Definition Span.h:805
constexpr __host__ __device__ ElementType * data()
Pointer to the allocated memory.
Definition Span2.h:196
constexpr __host__ __device__ SizeType dim2Size() const
Number of elements in the second dimension.
Definition Span2.h:122
constexpr __host__ __device__ SizeType totalNbElement() const
Total number of elements.
Definition Span2.h:124
constexpr __host__ __device__ SizeType dim1Size() const
Number of elements in the first dimension.
Definition Span2.h:120
View for a 2D array whose size is an 'Int64'.
Definition Span2.h:324
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
Definition Span.h:539
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
constexpr __host__ __device__ SizeType sizeBytes() const noexcept
Returns the size of the array in bytes.
Definition Span.h:329
View of an array of elements of type T.
Definition Span.h:635
constexpr __host__ __device__ ElementType * data()
Pointer to the allocated memory.
Definition Span2.h:196
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
std::int32_t Int32
Signed integer type of 32 bits.