Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephOrdering.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* AlephOrdering.cc (C) 2000-2024 */
9/* */
10/*---------------------------------------------------------------------------*/
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/aleph/AlephArcane.h"
14#include "arcane/core/IMesh.h"
15
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19namespace Arcane
20{
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25// *****************************************************************************
26// * Minimal AlephOrdering for AlephIndexing
27// *****************************************************************************
28AlephOrdering::
29AlephOrdering(AlephKernel* kernel)
30: TraceAccessor(kernel->parallel()->traceMng())
31, m_do_swap(false)
32, m_kernel(kernel)
33, m_swap(0)
34{}
35
36/******************************************************************************
37 *****************************************************************************/
38AlephOrdering::
39AlephOrdering(AlephKernel* kernel,
40 Integer global_nb_row,
41 Integer local_nb_row,
42 bool do_swap)
43: TraceAccessor(kernel->parallel()->traceMng())
44, m_do_swap(do_swap)
45, m_kernel(kernel)
46, m_swap(0)
47{
48 ItacFunction(AlephOrdering);
49 if (!do_swap) {
50 debug() << "\t[AlephOrdering::AlephOrdering] No ordering!";
51 return;
52 }
53 debug() << "\t[AlephOrdering::AlephOrdering] Ordering!";
54
55 if (m_kernel->nbRanksPerSolver() != 1)
56 throw FatalErrorException("AlephOrdering", "Ordering not allowed in parallel");
57
58 Integer local_nb_cell = m_kernel->subDomain()->defaultMesh()->ownCells().size();
59 Integer total_nb_cell = m_kernel->subDomain()->parallelMng()->reduce(Parallel::ReduceSum, local_nb_cell);
60
61 if ((local_nb_cell == local_nb_row) && (total_nb_cell == global_nb_row)) {
62 debug() << "\t[AlephOrdering::AlephOrdering] Now cell ordering";
63 this->initCellOrder();
64 return;
65 }
66
67 if ((2 * local_nb_cell == local_nb_row) && (2 * total_nb_cell == global_nb_row)) {
68 debug() << "\t[AlephOrdering::AlephOrdering] Now 2*cell ordering";
69 this->initTwiceCellOrder();
70 return;
71 }
72
73 Integer local_nb_face = m_kernel->subDomain()->defaultMesh()->ownFaces().size();
74 Integer total_nb_face = m_kernel->subDomain()->parallelMng()->reduce(Parallel::ReduceSum, local_nb_face);
75 if (((local_nb_cell + local_nb_face) == local_nb_row) && ((total_nb_cell + total_nb_face) == global_nb_row)) {
76 debug() << "\t[AlephOrdering::AlephOrdering] Now cell+face ordering";
77 this->initCellFaceOrder();
78 return;
79 }
80
81 if ((local_nb_face == local_nb_row) && (total_nb_face == global_nb_row)) {
82 debug() << "\t[AlephOrdering::AlephOrdering] Now face ordering";
83 this->initFaceOrder();
84 return;
85 }
86
87 Integer local_nb_node = m_kernel->subDomain()->defaultMesh()->ownNodes().size();
88 Integer total_nb_node = m_kernel->subDomain()->parallelMng()->reduce(Parallel::ReduceSum, local_nb_node);
89
90 if ((((local_nb_cell + local_nb_node)) == local_nb_row) && (((total_nb_cell + total_nb_node)) == global_nb_row)) {
91 debug() << "\t[AlephOrdering::AlephOrdering] Now (cell+node) ordering";
92 this->initCellNodeOrder();
93 return;
94 }
95
96 if (((2 * (local_nb_cell + local_nb_node)) == local_nb_row) && ((2 * (total_nb_cell + total_nb_node)) == global_nb_row)) {
97 debug() << "\t[AlephOrdering::AlephOrdering] Now 2*(cell+node) ordering";
98 this->initTwiceCellNodeOrder();
99 return;
100 }
101
102 throw FatalErrorException("AlephOrdering", "Could not guess cell||face||cell+face");
103}
104
105/******************************************************************************
106 *****************************************************************************/
107AlephOrdering::
108~AlephOrdering()
109{
110 debug() << "\33[5m\t[~AlephOrdering]\33[0m";
111}
112
113/******************************************************************************
114 * initCellOrder
115 *****************************************************************************/
116void AlephOrdering::
117initCellOrder(void)
118{
119 ItacFunction(AlephOrdering);
120 debug() << "\t[AlephOrdering::InitializeCellOrder] " << m_kernel->topology()->gathered_nb_row(m_kernel->size());
121 m_swap.resize(m_kernel->topology()->gathered_nb_row(m_kernel->size()));
122 UniqueArray<Int64> all;
123 Integer added = 0;
124 ENUMERATE_CELL (cell, m_kernel->subDomain()->defaultMesh()->ownCells()) {
125 all.add(cell->uniqueId().asInt64());
126 added += 1;
127 }
128 debug() << "\t[AlephOrdering::InitializeCellOrder] added=" << added;
129 m_kernel->parallel()->allGatherVariable(all, m_swap);
130}
131
132/******************************************************************************
133 * initTwiceCellOrder
134 * Pour le mode Complexe
135 *****************************************************************************/
136void AlephOrdering::
137initTwiceCellOrder(void)
138{
139 ItacFunction(AlephOrdering);
140 debug() << "\t[AlephOrdering::InitializeTwiceCellOrder] " << m_kernel->topology()->gathered_nb_row(m_kernel->size());
141 m_swap.resize(m_kernel->topology()->gathered_nb_row(m_kernel->size()));
142 UniqueArray<Int64> all;
143 Integer added = 0;
144 ENUMERATE_CELL (cell, m_kernel->subDomain()->defaultMesh()->ownCells()) {
145 all.add(2 * cell->uniqueId().asInt64());
146 added += 1;
147 all.add(2 * cell->uniqueId().asInt64() + 1);
148 added += 1;
149 }
150 debug() << "\t[AlephOrdering::InitializeTwiceCellOrder] added=" << added;
151 m_kernel->parallel()->allGatherVariable(all, m_swap);
152}
153
154/******************************************************************************
155 * initFaceOrder
156 *****************************************************************************/
157void AlephOrdering::
158initFaceOrder(void)
159{
160 ItacFunction(AlephOrdering);
161 debug() << "\t[AlephOrdering::InitializeFaceOrder] " << m_kernel->topology()->gathered_nb_row(m_kernel->size());
162 m_swap.resize(m_kernel->topology()->gathered_nb_row(m_kernel->size()));
163 UniqueArray<Int64> all;
164 Integer added = 0;
165 ENUMERATE_FACE (face, m_kernel->subDomain()->defaultMesh()->ownFaces()) {
166 all.add(face->uniqueId().asInt64());
167 added += 1;
168 }
169 debug() << "\t[AlephOrdering::InitializeFaceOrder] added=" << added;
170 m_kernel->parallel()->allGatherVariable(all, m_swap);
171}
172
173/******************************************************************************
174 * initCellFaceOrder
175 *****************************************************************************/
176void AlephOrdering::
177initCellFaceOrder(void)
178{
179 ItacFunction(AlephOrdering);
180 debug() << "\t[AlephOrdering::InitializeCellFaceOrder] " << m_kernel->topology()->gathered_nb_row(m_kernel->size());
181
182 UniqueArray<Integer> all_cells;
183 UniqueArray<Integer> all_faces;
184 UniqueArray<Integer> gathered_nb_cells(m_kernel->size());
185 UniqueArray<Integer> gathered_nb_faces(m_kernel->size());
186 all_cells.add(m_kernel->subDomain()->defaultMesh()->ownCells().size());
187 all_faces.add(m_kernel->subDomain()->defaultMesh()->ownFaces().size());
188 m_kernel->parallel()->allGather(all_cells, gathered_nb_cells);
189 m_kernel->parallel()->allGather(all_faces, gathered_nb_faces);
190 /* for(Integer i=0,N=gathered_nb_cells.size();i<N;++i)
191 debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] gathered_nb_cells["<<i<<"]="<<gathered_nb_cells.at(i);
192 for(Integer i=0,N=gathered_nb_faces.size();i<N;++i)
193 debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] gathered_nb_faces["<<i<<"]="<<gathered_nb_faces.at(i);
194*/
195
196 UniqueArray<Int64> all;
197 UniqueArray<Int64> m_swap_cell;
198 ENUMERATE_CELL (cell, m_kernel->subDomain()->defaultMesh()->ownCells()) {
199 all.add(cell->uniqueId().asInt64());
200 }
201 //debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] added for cells="<<all.size();
202 m_kernel->parallel()->allGatherVariable(all, m_swap_cell);
203 /* for(Integer i=0,N=m_swap_cell.size();i<N;++i)
204 debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] m_swap_cell["<<i<<"]="<<m_swap_cell.at(i);
205*/
206 all.clear();
207 UniqueArray<Int64> m_swap_face;
208 ENUMERATE_FACE (face, m_kernel->subDomain()->defaultMesh()->ownFaces()) {
209 all.add(face->uniqueId().asInt64());
210 }
211 //debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] added for faces="<<all.size();
212 m_kernel->parallel()->allGatherVariable(all, m_swap_face);
213 /* for(Integer i=0,N=m_swap_face.size();i<N;++i)
214 debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] m_swap_face["<<i<<"]="<<m_swap_face.at(i);
215*/
216
217 Int64 cell_offset = m_swap_cell.size();
218 // debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] Now combining cells+faces of size="<<m_swap_cell.size()+m_swap_face.size();
219 /* m_swap.resize(m_swap_cell.size()+m_swap_face.size());
220 m_swap.copy(m_swap_cell.constView());
221 debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] Shifting faces of "<<m_swap_cell.size();
222 for(Integer i=0,N=m_swap_face.size();i<N;++i)
223 m_swap_face[i]+=cell_offset;
224 m_swap.addRange(m_swap_face.constView());
225*/
226
227 m_swap.resize(m_swap_cell.size() + m_swap_face.size());
228 //debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] Now combining cells";
229 Integer iCell = 0;
230 for (Integer i = 0; i < m_kernel->size(); ++i) {
231 Integer offset = m_kernel->topology()->gathered_nb_row(i);
232 for (Integer j = 0; j < gathered_nb_cells.at(i); ++j) {
233 //debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] m_swap["<<offset+j<<"]="<<m_swap_cell.at(iCell);
234 m_swap[offset + j] = m_swap_cell.at(iCell);
235 iCell += 1;
236 }
237 }
238 //debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] Now combining faces";
239 Integer iFace = 0;
240 for (Integer i = 0; i < m_kernel->size(); ++i) {
241 Integer offset = 0;
242 if (i > 0)
243 offset = m_kernel->topology()->gathered_nb_row(i);
244 offset += gathered_nb_cells.at(i);
245 for (Integer j = 0; j < gathered_nb_faces.at(i); ++j) {
246 //debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] m_swap["<<offset+j<<"]="<<m_swap_face.at(iFace);
247 m_swap[offset + j] = cell_offset + m_swap_face.at(iFace);
248 iFace += 1;
249 }
250 }
251
252 /* debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] Like it?";
253 for(Integer i=0,N=m_swap.size();i<N;++i){
254 debug()<<"\t[AlephOrdering::InitializeCellFaceOrder] m_swap["<<i<<"]="<<m_swap.at(i);
255 }*/
256}
257
258/******************************************************************************
259 * initCellNodeOrder
260 *****************************************************************************/
261void AlephOrdering::
262initCellNodeOrder(void)
263{
264 ItacFunction(AlephOrdering);
265 debug() << "\t[AlephOrdering::InitializeCellNodeOrder] " << m_kernel->topology()->gathered_nb_row(m_kernel->size());
266
267 UniqueArray<Integer> all_cells;
268 UniqueArray<Integer> all_nodes;
269 UniqueArray<Integer> gathered_nb_cells(m_kernel->size());
270 UniqueArray<Integer> gathered_nb_nodes(m_kernel->size());
271 all_cells.add(m_kernel->subDomain()->defaultMesh()->ownCells().size());
272 all_nodes.add(m_kernel->subDomain()->defaultMesh()->ownNodes().size());
273 m_kernel->parallel()->allGather(all_cells, gathered_nb_cells);
274 m_kernel->parallel()->allGather(all_nodes, gathered_nb_nodes);
275
276 UniqueArray<Int64> all;
277 UniqueArray<Int64> m_swap_cell;
278 ENUMERATE_CELL (cell, m_kernel->subDomain()->defaultMesh()->ownCells()) {
279 all.add(cell->uniqueId().asInt64());
280 }
281 m_kernel->parallel()->allGatherVariable(all, m_swap_cell);
282 all.clear();
283 UniqueArray<Int64> m_swap_node;
284 ENUMERATE_NODE (node, m_kernel->subDomain()->defaultMesh()->ownNodes()) {
285 all.add(node->uniqueId().asInt64());
286 }
287 m_kernel->parallel()->allGatherVariable(all, m_swap_node);
288
289 Int64 cell_offset = m_swap_cell.size();
290
291 m_swap.resize(m_swap_cell.size() + m_swap_node.size());
292 Integer iCell = 0;
293 for (Integer i = 0; i < m_kernel->size(); ++i) {
294 AlephInt offset = m_kernel->topology()->gathered_nb_row(i);
295 for (Integer j = 0; j < gathered_nb_cells.at(i); ++j) {
296 m_swap[offset + j] = m_swap_cell.at(iCell);
297 iCell += 1;
298 }
299 }
300 Integer iNode = 0;
301 for (Integer i = 0; i < m_kernel->size(); ++i) {
302 AlephInt offset = 0;
303 if (i > 0)
304 offset = m_kernel->topology()->gathered_nb_row(i);
305 offset += gathered_nb_cells.at(i);
306 for (Integer j = 0; j < gathered_nb_nodes.at(i); ++j) {
307 m_swap[offset + j] = cell_offset + m_swap_node.at(iNode);
308 iNode += 1;
309 }
310 }
311}
312
313void AlephOrdering::
314initTwiceCellNodeOrder(void)
315{
316 ItacFunction(AlephOrdering);
317 debug() << "\t[AlephOrdering::initTwiceCellNodeOrder] " << m_kernel->topology()->gathered_nb_row(m_kernel->size());
318
319 UniqueArray<Integer> all_cells;
320 UniqueArray<Integer> all_nodes;
321 UniqueArray<Integer> gathered_nb_cells(m_kernel->size());
322 UniqueArray<Integer> gathered_nb_nodes(m_kernel->size());
323 all_cells.add(m_kernel->subDomain()->defaultMesh()->ownCells().size());
324 all_nodes.add(m_kernel->subDomain()->defaultMesh()->ownNodes().size());
325 m_kernel->parallel()->allGather(all_cells, gathered_nb_cells);
326 m_kernel->parallel()->allGather(all_nodes, gathered_nb_nodes);
327
328 UniqueArray<Int64> all;
329 UniqueArray<Int64> m_swap_cell;
330 ENUMERATE_CELL (cell, m_kernel->subDomain()->defaultMesh()->ownCells()) {
331 all.add(2 * cell->uniqueId().asInt64());
332 all.add(2 * cell->uniqueId().asInt64() + 1);
333 }
334 m_kernel->parallel()->allGatherVariable(all, m_swap_cell);
335 all.clear();
336 UniqueArray<Int64> m_swap_node;
337 ENUMERATE_NODE (node, m_kernel->subDomain()->defaultMesh()->ownNodes()) {
338 all.add(2 * node->uniqueId().asInt64());
339 all.add(2 * node->uniqueId().asInt64() + 1);
340 }
341 m_kernel->parallel()->allGatherVariable(all, m_swap_node);
342
343 Int64 cell_offset = m_swap_cell.size();
344
345 m_swap.resize(m_swap_cell.size() + m_swap_node.size());
346 Integer iCell = 0;
347 for (Integer i = 0; i < m_kernel->size(); ++i) {
348 Integer offset = m_kernel->topology()->gathered_nb_row(i);
349 for (Integer j = 0; j < gathered_nb_cells.at(i); ++j) {
350 m_swap[offset + j] = m_swap_cell.at(iCell);
351 iCell += 1;
352 }
353 }
354 Integer iNode = 0;
355 for (Integer i = 0; i < m_kernel->size(); ++i) {
356 Integer offset = 0;
357 if (i > 0)
358 offset = m_kernel->topology()->gathered_nb_row(i);
359 offset += gathered_nb_cells.at(i);
360 for (Integer j = 0; j < gathered_nb_nodes.at(i); ++j) {
361 m_swap[offset + j] = cell_offset + m_swap_node.at(iNode);
362 iNode += 1;
363 }
364 }
365}
366
367/*---------------------------------------------------------------------------*/
368/*---------------------------------------------------------------------------*/
369
370} // namespace Arcane
371
372/*---------------------------------------------------------------------------*/
373/*---------------------------------------------------------------------------*/
#define ENUMERATE_FACE(name, group)
Enumérateur générique d'un groupe de faces.
#define ENUMERATE_CELL(name, group)
Enumérateur générique d'un groupe de mailles.
#define ENUMERATE_NODE(name, group)
Enumérateur générique d'un groupe de noeuds.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
int AlephInt
Type par défaut pour indexer les lignes et les colonnes des matrices et vecteurs.
Definition AlephGlobal.h:50
Int32 Integer
Type représentant un entier.