Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DataSynchronizeInfo.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* DataSynchronizeInfo.cc (C) 2000-2024 */
9/* */
10/* Informations pour synchroniser les données. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/impl/DataSynchronizeInfo.h"
15
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/IMemoryRessourceMng.h"
19#include "arcane/utils/MemoryView.h"
20#include "arcane/utils/SmallArray.h"
21#include "arcane/utils/ITraceMng.h"
22#include "arcane/utils/TraceAccessor.h"
23#include "arcane/utils/ValueConvert.h"
24
25#include "arcane/core/VariableCollection.h"
26#include "arcane/core/ParallelMngUtils.h"
27#include "arcane/core/IParallelExchanger.h"
28#include "arcane/core/ISerializeMessage.h"
29#include "arcane/core/ISerializer.h"
30#include "arcane/core/IParallelMng.h"
31#include "arcane/core/IData.h"
32#include "arcane/core/internal/IParallelMngInternal.h"
33#include "arcane/core/internal/IDataInternal.h"
34
35#include "arcane/accelerator/core/Runner.h"
36
37#include "arcane/impl/IDataSynchronizeBuffer.h"
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace Arcane
43{
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48// TODO: plutôt que d'utiliser la mémoire managée, il est préférable d'avoir
49// une copie sur le device des IDs. Cela permettra d'éviter des transferts
50// potentiels si on mélange synchronisation de variables sur accélérateurs et
51// sur CPU.
52
53VariableSyncInfo::
54VariableSyncInfo()
55: m_share_ids(platform::getDefaultDataAllocator())
56, m_ghost_ids(platform::getDefaultDataAllocator())
57{
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63VariableSyncInfo::
64VariableSyncInfo(Int32ConstArrayView share_ids, Int32ConstArrayView ghost_ids,
65 Int32 rank)
66: VariableSyncInfo()
67{
68 m_target_rank = rank;
69 m_share_ids.copy(share_ids);
70 m_ghost_ids.copy(ghost_ids);
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76VariableSyncInfo::
77VariableSyncInfo(const VariableSyncInfo& rhs)
78: VariableSyncInfo()
79{
80 // NOTE: pour l'instant (avril 2023) il faut un constructeur de recopie
81 // explicite pour spécifier l'allocateur
82 m_target_rank = rhs.m_target_rank;
83 m_share_ids.copy(rhs.m_share_ids);
84 m_ghost_ids.copy(rhs.m_ghost_ids);
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90void VariableSyncInfo::
91_changeIds(Array<Int32>& ids, Int32ConstArrayView old_to_new_ids)
92{
93 UniqueArray<Int32> orig_ids(ids);
94 ids.clear();
95
96 for (Integer z = 0, zs = orig_ids.size(); z < zs; ++z) {
97 Int32 old_id = orig_ids[z];
98 Int32 new_id = old_to_new_ids[old_id];
99 if (new_id != NULL_ITEM_LOCAL_ID)
100 ids.add(new_id);
101 }
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107void VariableSyncInfo::
109{
110 _changeIds(m_share_ids, old_to_new_ids);
111 _changeIds(m_ghost_ids, old_to_new_ids);
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
120void DataSynchronizeInfo::
121recompute()
122{
123 Integer nb_message = this->size();
124
127
128 receive_info.m_displacements_base.resize(nb_message);
129 send_info.m_displacements_base.resize(nb_message);
130
131 receive_info.m_total_nb_item = 0;
132 send_info.m_total_nb_item = 0;
133
134 {
135 Integer ghost_displacement = 0;
136 Integer share_displacement = 0;
137 Int32 index = 0;
138 for (const VariableSyncInfo& vsi : m_ranks_info) {
139 Int32 ghost_size = vsi.nbGhost();
140 receive_info.m_displacements_base[index] = ghost_displacement;
142 Int32 share_size = vsi.nbShare();
143 send_info.m_displacements_base[index] = share_displacement;
145 ++index;
146 }
147 receive_info.m_total_nb_item = ghost_displacement;
148 send_info.m_total_nb_item = share_displacement;
149 }
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155void DataSynchronizeInfo::
157{
158 for (VariableSyncInfo& vsi : m_ranks_info) {
159 vsi.changeLocalIds(old_to_new_ids);
160 }
161 recompute();
162}
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167void DataSynchronizeInfo::
168add(const VariableSyncInfo& s)
169{
170 m_ranks_info.add(s);
171 m_communicating_ranks.add(s.targetRank());
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180ConstArrayView<Int32> DataSynchronizeBufferInfoList::
181localIds(Int32 index) const
182{
183 const VariableSyncInfo& s = m_sync_info->m_ranks_info[index];
184 return (m_is_share) ? s.shareIds() : s.ghostIds();
185}
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190Int32 DataSynchronizeBufferInfoList::
191nbItem(Int32 index) const
192{
193 const VariableSyncInfo& s = m_sync_info->m_ranks_info[index];
194 return (m_is_share) ? s.nbShare() : s.nbGhost();
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
202
203} // End namespace Arcane
204
205/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
Informations pour les message d'envoi (share) ou de réception (ghost)
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Informations sur la liste des entités partagées/fantômes pour un rang donné pour une synchronisation.
ConstArrayView< Int32 > ghostIds() const
localIds() des entités à réceptionner du rang targetRank()
ConstArrayView< Int32 > shareIds() const
localIds() des entités à envoyer au rang targetRank()
Int32 nbGhost() const
Nombre d'entités fantômes.
Int32 targetRank() const
Rang du processeur cible.
Int32 nbShare() const
Nombre d'entités partagées.
Vue constante d'un tableau de type T.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-