Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephTopology.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/* AlephTopology.cc (C) 2000-2024 */
9/* */
10/*---------------------------------------------------------------------------*/
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/aleph/AlephTopology.h"
14
15#include "arcane/aleph/AlephKernel.h"
16#include "arcane/aleph/AlephArcane.h"
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27// *****************************************************************************
28// * Minimal AlephTopology for AlephIndexing
29// *****************************************************************************
30AlephTopology::
31AlephTopology(AlephKernel* kernel)
32: TraceAccessor(kernel->parallel()->traceMng())
33, m_kernel(kernel)
34, m_nb_row_size(0)
35, m_nb_row_rank(0)
36, m_gathered_nb_row_elements(0)
37, m_created(false)
38, m_has_set_row_nb_elements(false)
39, m_has_been_initialized(false)
40{
41 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] Loading MINIMALE AlephTopology"
42 << "\33[0m";
43}
44
45/******************************************************************************
46 *****************************************************************************/
47AlephTopology::
48AlephTopology(ITraceMng* tm,
49 AlephKernel* kernel,
50 Integer nb_row_size,
51 Integer nb_row_rank)
52: TraceAccessor(tm)
53, m_kernel(kernel)
54, m_nb_row_size(nb_row_size)
55, m_nb_row_rank(nb_row_rank)
56, m_gathered_nb_row_elements()
57, m_created(false)
58, m_has_set_row_nb_elements(false)
59, m_has_been_initialized(true)
60{
61 ItacFunction(AlephTopology);
62 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] Loading AlephTopology"
63 << "\33[0m";
64
65 m_gathered_nb_setValued.resize(m_kernel->size());
66 m_gathered_nb_row.resize(m_kernel->size() + 1);
67 m_gathered_nb_row[0] = 0;
68
69 if (!m_kernel->isParallel()) {
70 m_gathered_nb_row[1] = m_nb_row_size;
71 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] SEQ done"
72 << "\33[0m";
73 return;
74 }
75
76 if (m_kernel->isAnOther()) {
77 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] receiving m_gathered_nb_row"
78 << "\33[0m";
79 m_kernel->world()->broadcast(m_gathered_nb_row.view(), 0);
80 return;
81 }
82
83 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] Nous nous échangeons les indices locaux des lignes de la matrice"
84 << "\33[0m";
85 UniqueArray<Integer> all_rows;
86 UniqueArray<Integer> gathered_nb_row(m_kernel->size());
87 all_rows.add(m_nb_row_rank);
88 m_kernel->parallel()->allGather(all_rows, gathered_nb_row);
89 for (int iCpu = 0; iCpu < m_kernel->size(); ++iCpu) {
90 m_gathered_nb_row[iCpu + 1] = m_gathered_nb_row[iCpu] + gathered_nb_row[iCpu];
91 debug() << "\33[1;32m\t\t[AlephTopology::AlephTopology] " << iCpu << ":" << m_gathered_nb_row[iCpu] << "\33[0m";
92 }
93 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] m_parallel_info_partitioning done"
94 << "\33[0m";
95
96 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther()) {
97 debug() << "\33[1;32m\t[AlephTopology::AlephTopology] sending m_gathered_nb_row"
98 << "\33[0m";
99 m_kernel->world()->broadcast(m_gathered_nb_row.view(), 0);
100 }
101}
102
103/******************************************************************************
104 *****************************************************************************/
105AlephTopology::
106~AlephTopology()
107{
108 debug() << "\33[1;5;32m\t[~AlephTopology]"
109 << "\33[0m";
110}
111
112/******************************************************************************
113 * b1e13efe
114 *****************************************************************************/
115void AlephTopology::
116create(Integer setValue_idx)
117{
118 ItacFunction(AlephTopology);
119
120 if (m_created)
121 return;
122 m_created = true;
123
124 checkForInit();
125
126 if (!m_kernel->isParallel()) {
127 debug() << "\33[1;32m\t\t\t[AlephTopology::create] SEQ m_gathered_nb_setValued[0]=" << setValue_idx << "\33[0m";
128 m_gathered_nb_setValued[0] = setValue_idx;
129 return;
130 }
131
132 debug() << "\33[1;32m\t\t\t[AlephTopology::create]"
133 << "\33[0m";
134 if (m_kernel->isAnOther()) {
135 debug() << "\33[1;32m\t[AlephTopology::create] receiving m_gathered_nb_setValued"
136 << "\33[0m";
137 m_kernel->world()->broadcast(m_gathered_nb_setValued.view(), 0);
138 return;
139 }
140
141 // Nous allons nous échanger tous les setValue_idx
142 UniqueArray<AlephInt> all;
143 all.add(setValue_idx);
144 m_kernel->parallel()->allGather(all, m_gathered_nb_setValued);
145
146 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther()) {
147 debug() << "\33[1;32m\t[AlephTopology::create] sending m_gathered_nb_setValued"
148 << "\33[0m";
149 m_kernel->world()->broadcast(m_gathered_nb_setValued.view(), 0);
150 }
151 debug() << "\33[1;32m\t\t\t[AlephTopology::create] done"
152 << "\33[0m";
153}
154
155/******************************************************************************
156 * 1b264c6c
157 * Ce row_nb_element est positionné afin d'aider à la construction de la matrice
158 * lors des :
159 * - 'init_length' de Sloop
160 * - HYPRE_IJMatrixSetRowSizes
161 * - Trilinos Epetra_CrsMatrix
162 *****************************************************************************/
163void AlephTopology::
164setRowNbElements(IntegerConstArrayView row_nb_element)
165{
166 checkForInit();
167
168 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements]"
169 << "\33[0m";
170 if (m_has_set_row_nb_elements)
171 return;
172 m_has_set_row_nb_elements = true;
173 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements]"
174 << "\33[0m";
175
176 // Nous allons nous échanger les nombre d'éléments par lignes
177 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements] resize m_gathered_nb_row_elements to " << m_nb_row_size << "\33[0m";
178 m_gathered_nb_row_elements.resize(m_nb_row_size);
179
180 if (m_kernel->isAnOther()) {
181 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements] isAnOther from 0"
182 << "\33[0m";
183 traceMng()->flush();
184 m_kernel->world()->broadcast(m_gathered_nb_row_elements.view(), 0);
185 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements] done"
186 << "\33[0m";
187 traceMng()->flush();
188 return;
189 }
190
191 UniqueArray<AlephInt> local_row_nb_element(m_nb_row_rank);
192 for (int i = 0; i < m_nb_row_rank; ++i)
193 local_row_nb_element[i] = row_nb_element[i];
194 m_kernel->parallel()->allGatherVariable(local_row_nb_element, m_gathered_nb_row_elements);
195
196 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther()) {
197 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements] Sending m_gathered_nb_row_elements of size=" << m_gathered_nb_row_elements.size() << "\33[0m";
198 m_kernel->world()->broadcast(m_gathered_nb_row_elements.view(), 0);
199 }
200 debug() << "\33[1;32m\t\t\t[AlephTopology::setRowNbElements] done"
201 << "\33[0m";
202}
203
204/******************************************************************************
205 *****************************************************************************/
206IntegerConstArrayView AlephTopology::
207ptr_low_up_array()
208{
209 debug() << "\33[1;32m\t[AlephTopology::ptr_low_up_array]"
210 << "\33[0m";
211 return IntegerConstArrayView();
212}
213
214/******************************************************************************
215 *****************************************************************************/
216ConstArrayView<AlephInt> AlephTopology::
217part()
218{
219 checkForInit();
220 //debug() << "\33[1;32m\t[AlephTopology::part]"<<"\33[0m";
221 return m_gathered_nb_row;
222}
223
224/******************************************************************************
225 *****************************************************************************/
226IParallelMng* AlephTopology::
227parallelMng()
228{
229 debug() << "\33[1;32m\t[AlephTopology::parallelMng]"
230 << "\33[0m";
231 return m_kernel->parallel();
232}
233
234/******************************************************************************
235 *****************************************************************************/
236void AlephTopology::
237rowRange(Integer& min_row, Integer& max_row)
238{
239 const Integer rank = m_kernel->rank();
240 checkForInit();
241 debug() << "\33[1;32m\t[AlephTopology::rowRange] rank=" << rank << "\33[0m";
242 min_row = m_gathered_nb_row[rank];
243 max_row = m_gathered_nb_row[rank + 1];
244 debug() << "\33[1;32m\t[AlephTopology::rowRange] min_row=" << min_row << ", max_row=" << max_row << "\33[0m";
245}
246
247/******************************************************************************
248 *****************************************************************************/
249Integer AlephTopology::
250rowLocalRange(const Integer index)
251{
252 Integer ilower = -1;
253 Integer iupper = 0;
254 Integer range = 0;
255 checkForInit();
256 for (int iCpu = 0; iCpu < m_kernel->size(); ++iCpu) {
257 if (m_kernel->rank() != m_kernel->solverRanks(index)[iCpu])
258 continue;
259 if (ilower == -1)
260 ilower = m_kernel->topology()->gathered_nb_row(iCpu);
261 iupper = m_kernel->topology()->gathered_nb_row(iCpu + 1) - 1;
262 }
263 range = iupper - ilower + 1;
264 debug() << "\33[1;32m\t[AlephTopology::rowLocalRange] ilower=" << ilower
265 << ", iupper=" << iupper << ", range=" << range << "\33[0m";
266 return range;
267}
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
271
272} // namespace Arcane
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
ConstArrayView< Integer > IntegerConstArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:644
Int32 Integer
Type représentant un entier.