Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
NonBlockingParticleExchanger.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/* NonBlockingParticleExchanger.h (C) 2000-2020 */
9/* */
10/* Particle Exchanger. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_NONBLOCKINGPARTICLEEXCHANGER_H
13#define ARCANE_NONBLOCKINGPARTICLEEXCHANGER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/List.h"
18#include "arcane/utils/ScopedPtr.h"
19
20#include "arcane/mesh/MeshGlobal.h"
21
22#include "arcane/core/IParticleExchanger.h"
23#include "arcane/core/BasicService.h"
24#include "arcane/core/VariableCollection.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31class Timer;
33} // namespace Arcane
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace Arcane::mesh
39{
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
46class NonBlockingParticleExchanger
47: public BasicService
48, public IParticleExchanger
49{
50 private:
51
52 static const Integer MESSAGE_EXCHANGE = 1;
53 static const Integer MESSAGE_NB_FINISH_EXCHANGE = 2;
54 static const Integer MESSAGE_FINISH_EXCHANGE_STATUS = 3;
55 static const Integer MESSAGE_CHANGE_BLOCKING = 4;
56
57 public:
58
59 explicit NonBlockingParticleExchanger(const ServiceBuildInfo& sbi);
60 ~NonBlockingParticleExchanger() override;
61
62 public:
63
64 void build() override {}
65 void initialize(IItemFamily* item_family) override;
66
67 public:
68
69 void beginNewExchange(Integer nb_particule) override;
70 IItemFamily* itemFamily() override { return m_item_family; }
71 bool exchangeItems(Integer nb_particle_finish_exchange,
72 Int32ConstArrayView local_ids,
73 Int32ConstArrayView sub_domains_to_send, ItemGroup item_group,
74 IFunctor* functor) override;
75 bool exchangeItems(Integer nb_particle_finish_exchange,
76 Int32ConstArrayView local_ids,
77 Int32ConstArrayView sub_domains_to_send,
78 Int32Array* new_particle_local_ids,
79 IFunctor* functor) override;
80 void sendItems(Integer nb_particle_finish_exchange,
81 Int32ConstArrayView local_ids,
82 Int32ConstArrayView sub_domains_to_send) override;
83
84 bool waitMessages(Integer nb_pending_particle, Int32Array* new_particle_local_ids,
85 IFunctor* functor) override;
86 void addNewParticles(Integer nb_particle) override
87 {
88 ARCANE_UNUSED(nb_particle);
89 throw NotImplementedException(A_FUNCINFO);
90 }
91 void setVerboseLevel(Integer level) override { m_verbose_level = level; }
92 Integer verboseLevel() const override { return m_verbose_level; }
93 IAsyncParticleExchanger* asyncParticleExchanger() override { return nullptr; }
94
95 void reset();
96
97 private:
98
99 IItemFamily* m_item_family;
100 IParallelMng* m_parallel_mng;
101 UniqueArray<SerializeMessage*> m_accumulate_infos;
102
103 Int32 m_rank;
104
107 Real m_total_time_functor;
108 Real m_total_time_waiting;
109
112
115
118
119 Ref<ISerializeMessageList> m_message_list;
120
121 Int64 m_nb_total_particle_finish_exchange;
122 Int64 m_nb_total_particle;
123
124 Integer m_nb_original_blocking_size;
127
128 bool m_exchange_finished;
129 Int32 m_master_proc;
130 bool m_need_general_receive;
131 bool m_end_message_sended;
132 bool m_can_process_messages;
133 bool m_can_process_non_blocking;
134
135 bool m_want_process_non_blocking;
136 bool m_want_fast_send_particles;
137
138 Integer m_nb_receive_message;
139
140 Int64 m_nb_particle_finished_exchange;
141
142 Int32UniqueArray m_waiting_local_ids;
143 Int32UniqueArray m_waiting_sub_domains_to_send;
144 Integer m_verbose_level;
145 bool m_is_debug;
146
147 private:
148
149 void _clearMessages();
150 void _serializeMessage(ISerializeMessage* msg,
151 Int32ConstArrayView acc_ids,
152 Int64Array& items_to_send_uid,
153 Int64Array& items_to_send_cells_uid);
154 void _deserializeMessage(ISerializeMessage* msg,
155 Int64Array& items_to_create_id,
156 Int64Array& items_to_create_cell_id,
157 ItemGroup item_group,
158 Int32Array* new_particle_local_ids);
159 void _processFinishTrackingMessage();
160 void _addFinishExchangeParticle(Int64 nb_particle_finish_exchange);
161 void _sendFinishExchangeParticle();
162 void _addItemsToSend(Int32ConstArrayView local_ids,
163 Int32ConstArrayView sub_domains_to_send,
164 Int32ConstArrayView communicating_sub_domains,
165 UniqueArray<SharedArray<Int32>>& ids_to_send);
166 void _sendPendingMessages();
167 void _checkNeedReceiveMessage();
168 bool _exchangeItems(Int32ConstArrayView local_ids,
169 Int32ConstArrayView sub_domains_to_send,
170 ItemGroup item_group,
171 Int32Array* new_particle_local_ids,
172 IFunctor* functor);
173 void _checkSendItems(Int32ConstArrayView local_ids, Int32ConstArrayView sub_domains_to_send);
174 void _generateSendItemsMessages(Int32ConstArrayView local_ids, Int32ConstArrayView sub_domains_to_send);
175 void _checkInitialized();
176 void _processMessages(ItemGroup item_group, Int32Array* new_particle_local_ids, bool wait_all, IFunctor* functor);
177 bool _waitMessages(Integer nb_pending_particle, ItemGroup group, Int32Array* new_particle_local_ids, IFunctor* functor);
178};
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183} // namespace Arcane::mesh
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188#endif
Interface of an asynchronous particle exchanger.
Interface of an entity family.
Definition IItemFamily.h:83
Interface of the parallelism manager for a subdomain.
Interface of a particle exchanger.
Mesh entity group.
Definition ItemGroup.h:51
Reference to an instance.
Message using a SerializeBuffer.
Structure containing the information to create a service.
1D vector of data with reference semantics.
Management of a timer.
Definition Timer.h:63
1D data vector with value semantics (STL style).
void initialize(IItemFamily *item_family) override
Initializes the exchanger for the item_family item_family.
UniqueArray< ISerializeMessage * > m_pending_messages
List of messages pending sending.
bool exchangeItems(Integer nb_particle_finish_exchange, Int32ConstArrayView local_ids, Int32ConstArrayView sub_domains_to_send, ItemGroup item_group, IFunctor *functor) override
Exchanges particles between sub-domains.
IAsyncParticleExchanger * asyncParticleExchanger() override
Asynchronism management (returns nullptr if functionality is not available).
UniqueArray< ISerializeMessage * > m_waiting_messages
List of messages sent but currently being processed.
VariableList m_variables_to_exchange
List of variables to exchange.
void beginNewExchange(Integer nb_particule) override
Starts a new particle exchange.
void sendItems(Integer nb_particle_finish_exchange, Int32ConstArrayView local_ids, Int32ConstArrayView sub_domains_to_send) override
bool waitMessages(Integer nb_pending_particle, Int32Array *new_particle_local_ids, IFunctor *functor) override
void build() override
Build-level construction of the service.
void addNewParticles(Integer nb_particle) override
Adds nb_particle to the current exchange.
Integer verboseLevel() const override
Verbosity level.
Integer m_nb_blocking_size
Number of remaining particles before switching to blocking mode.
IItemFamily * itemFamily() override
Associated family.
void setVerboseLevel(Integer level) override
Sets the verbosity level (0 for no messages).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Definition UtilsTypes.h:125
std::int64_t Int64
Signed integer type of 64 bits.
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
double Real
Type representing a real number.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127
std::int32_t Int32
Signed integer type of 32 bits.