13#include "arcane/aleph/AlephArcane.h"
14#include "arcane/IMesh.h"
28AlephVector(AlephKernel* kernel)
29: TraceAccessor(kernel->parallel()->traceMng())
31, m_index(kernel->index())
34 ItacFunction(AlephVector);
36 if (kernel->isInitialized() ==
false) {
37 debug() <<
"\33[1;36m[AlephVector::AlephVector] New Aleph vector, but kernel is not initialized!\33[0m";
40 m_ranks = kernel->solverRanks(m_index);
41 m_participating_in_solver = kernel->subParallelMng(m_index) != NULL;
42 debug() <<
"\33[1;36m[AlephVector::AlephVector] New Aleph Vector\33[0m";
43 if (m_kernel->subParallelMng(m_index) == NULL) {
44 debug() <<
"\33[1;36m[AlephVector::AlephVector] Not concerned with this one!\33[0m";
47 debug() <<
"\33[1;36m[AlephVector::AlephVector] site size="
48 << m_kernel->subParallelMng(m_index)->commSize()
50 << m_kernel->subParallelMng(m_index)->commRank() <<
"\33[0m";
51 m_implementation = m_kernel->factory()->GetVector(m_kernel, m_index);
59 ItacFunction(AlephVector);
60 debug() <<
"\33[1;36m\t\t[~AlephVector]\33[0m";
69 ItacFunction(AlephVector);
70 if (m_kernel->isInitialized() ==
false)
72 if (m_kernel->configured()) {
73 debug() <<
"\33[1;36m[AlephVector::create] kernel is configured, returning"
77 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther()) {
78 m_kernel->world()->broadcast(UniqueArray<unsigned long>(1, 0x6bdba30al).view(), 0);
81 if (m_kernel->isParallel()) {
82 debug() <<
"\33[1;36m[AlephVector::create] // resizing idx & val to " << m_kernel->topology()->nb_row_rank() <<
"\33[0m";
83 m_aleph_vector_buffer_idx.resize(m_kernel->topology()->nb_row_rank());
84 m_aleph_vector_buffer_val.resize(m_kernel->topology()->nb_row_rank());
86 if (m_participating_in_solver) {
87 debug() <<
"\33[1;36m[AlephVector::create] Participating in solver!"
91 for (Integer iCpu = 0, idx = 0; iCpu < m_kernel->size(); ++iCpu) {
92 debug() <<
"\33[1;36m[AlephVector::create] m_kernel->rank()=" << m_kernel->rank() <<
", m_ranks[" << iCpu <<
"]=" << m_ranks[iCpu] <<
"\33[0m";
93 if (m_kernel->rank() != m_ranks[iCpu])
95 AlephInt nbRowsInCpu = m_kernel->topology()->gathered_nb_row(iCpu + 1) - m_kernel->topology()->gathered_nb_row(iCpu);
96 debug() <<
"\33[1;36m[AlephVector::create] Adding nb_row[iCpu=" << iCpu <<
"]=" << nbRowsInCpu <<
"\33[0m";
97 for (Integer i = 0; i < nbRowsInCpu; ++i, idx += 1) {
98 m_aleph_vector_buffer_idxs.add(m_kernel->ordering()->swap(m_kernel->topology()->gathered_nb_row(iCpu) + i));
102 m_aleph_vector_buffer_vals.resize(m_aleph_vector_buffer_idxs.size());
104 debug() <<
"\33[1;36m[AlephVector::create] resizing m_aleph_vector_buffer_[vals&idxs] to " << m_aleph_vector_buffer_vals.size() <<
"\33[0m";
108 debug() <<
"\33[1;36m[AlephVector::create] not participating, returning before 'create_really'"
114 debug() <<
"\33[1;36m[AlephVector::create] done"
122setLocalComponents(ConstArrayView<double> values)
124 UniqueArray<AlephInt> indexs;
125 if (m_bkp_num_values == 0) {
127 if (m_kernel->isInitialized())
128 row_offset = m_kernel->topology()->part()[m_kernel->rank()];
129 debug() <<
"\33[1;36m[AlephVector::setLocalComponents] m_bkp_num_values==0"
132 for (Integer i = 0, iMx = values.size(); i < iMx; i += 1)
133 indexs.add(i + row_offset);
135 setLocalComponents(values.size(), indexs, values);
142reSetLocalComponents(AlephVector* from)
144 const AlephInt row_offset = m_kernel->topology()->part()[m_kernel->rank()];
145 debug() <<
"\33[1;36m[AlephVector::reSetLocalComponents] Patching with row_offset=" << row_offset <<
"\33[0m";
146 for (
Int32 i = 0, mx = from->m_bkp_num_values; i < mx; i += 1)
147 from->m_bkp_indexs[i] += row_offset;
148 setLocalComponents(from->m_bkp_num_values, from->m_bkp_indexs, from->m_bkp_values);
155setLocalComponents(Integer num_values,
156 ConstArrayView<AlephInt> indexs,
157 ConstArrayView<double> values)
159 ItacFunction(AlephVector);
160 if (!m_kernel->isInitialized()) {
161 debug() <<
"\33[1;36m[AlephVector::setLocalComponents] Trying to setLocalComponents from an uninitialized kernel!\33[0m";
162 m_bkp_num_values = num_values;
163 debug() <<
"\33[1;36m[AlephVector::setLocalComponents] Backuping " << num_values <<
" values and indexes!\33[0m";
164 m_bkp_indexs.copy(indexs);
165 m_bkp_values.copy(values);
168 if (!m_kernel->isParallel()) {
169 debug() <<
"\33[1;36m[AlephVector::setLocalComponents] implementation AlephVectorSet, num_values=" << num_values <<
"\33[0m";
170 m_implementation->AlephVectorSet(values.data(),
175 debug() <<
"\33[1;36m[AlephVector::setLocalComponents]\33[0m";
176 for (Integer i = 0, is = num_values; i < is; ++i) {
178 if (m_participating_in_solver && (m_kernel->rank() == m_ranks[m_kernel->rank()])) {
179 if (!m_kernel->isCellOrdering()) {
182 m_aleph_vector_buffer_vals[indexs[i] - m_aleph_vector_buffer_idxs[0]] = values[i];
186 m_aleph_vector_buffer_vals[indexs[i]] = values[i];
190 m_aleph_vector_buffer_idx[i] = m_kernel->ordering()->swap(indexs[i]);
191 m_aleph_vector_buffer_val[i] = values[i];
201 ItacFunction(AlephVector);
202 debug() <<
"\33[1;36m[AlephVector::create_really] New UNconfigured vector"
204 m_implementation->AlephVectorCreate();
213 ItacFunction(AlephVector);
215 if (!m_kernel->isInitialized()) {
216 debug() <<
"\33[1;36m[AlephVector::AlephVector] Trying to assemble a vector from an uninitialized kernel!\33[0m";
219 if (m_kernel->thereIsOthers() && !m_kernel->isAnOther())
220 m_kernel->world()->broadcast(UniqueArray<unsigned long>(1, 0xec7a979fl).view(), 0);
222 if (!m_kernel->isParallel())
224 if (m_participating_in_solver) {
226 debug() <<
"\33[1;36m[AlephVector::assemble] m_participating_in_solver"
229 for (Integer iCpu = 0, iRows = 0; iCpu < m_kernel->size(); ++iCpu, iRows += nbRows) {
231 if (m_kernel->rank() != m_ranks[iCpu])
234 nbRows = m_kernel->topology()->gathered_nb_row(iCpu + 1) - m_kernel->topology()->gathered_nb_row(iCpu);
235 if (iCpu == m_kernel->rank())
237 debug() <<
"\33[1;36m[AlephVector::assemble]"
238 <<
" recv " << m_kernel->rank()
240 <<
", offset=" << iRows
241 <<
" for " << nbRows <<
"\33[0m";
242 m_parallel_requests.add(m_kernel->world()->recv(m_aleph_vector_buffer_vals.subView(iRows, nbRows),
247 if (m_kernel->rank() != m_ranks[m_kernel->rank()] && !m_kernel->isAnOther()) {
248 debug() <<
"\33[1;36m[AlephVector::assemble]"
249 <<
" send " << m_kernel->rank()
250 <<
" => " << m_ranks[m_kernel->rank()]
251 <<
" for " << m_aleph_vector_buffer_val.size() <<
"\33[0m";
252 m_parallel_requests.add(m_kernel->world()->send(m_aleph_vector_buffer_val,
253 m_ranks[m_kernel->rank()],
256 debug() <<
"\33[1;36m[AlephVector::assemble] done"
263assemble_waitAndFill(
void)
265 ItacFunction(AlephVector);
266 if (!m_kernel->isParallel())
268 debug() <<
"\33[1;36m[AlephVector::assemble_waitAndFill] wait for "
269 << m_parallel_requests.size()
270 <<
" Requests for solver "
271 << m_index <<
"\33[0m";
272 m_kernel->world()->waitAllRequests(m_parallel_requests);
273 m_parallel_requests.clear();
274 if (!m_participating_in_solver) {
275 debug() <<
"\33[1;36m[AlephVector::assemble_waitAndFill] Not participating in solver, returning"
279 debug() <<
"\33[1;36m[AlephVector::assemble_waitAndFill] " << m_index <<
" locfill"
281 m_implementation->AlephVectorSet(m_aleph_vector_buffer_vals.data(),
282 m_aleph_vector_buffer_idxs.data(),
283 m_aleph_vector_buffer_idxs.size());
284 debug() <<
"\33[1;36m[AlephVector::assemble_waitAndFill] " << m_index <<
" VECTOR ASSEMBLE"
286 m_implementation->AlephVectorAssemble();
287 debug() <<
"\33[1;36m[AlephVector::assemble_waitAndFill] done"
296 ItacFunction(AlephVector);
297 if (!m_kernel->isParallel())
300 if (m_kernel->rank() != m_ranks[m_kernel->rank()] && !m_kernel->isAnOther()) {
301 debug() <<
"\33[1;36m[AlephVector::REassemble] "
304 << m_ranks[m_kernel->rank()] <<
"\33[0m";
305 m_parallel_reassemble_requests.add(m_kernel->world()->recv(m_aleph_vector_buffer_val, m_ranks[m_kernel->rank()],
false));
308 if (m_participating_in_solver) {
310 debug() <<
"\33[1;36m[AlephVector::REassemble] J'ai participé, je récupère les résultats depuis l'implémentation"
312 m_implementation->AlephVectorGet(m_aleph_vector_buffer_vals.unguardedBasePointer(),
313 m_aleph_vector_buffer_idxs.unguardedBasePointer(),
314 m_aleph_vector_buffer_idxs.size());
317 for (Integer iCpu = 0, iRows = 0; iCpu < m_kernel->size(); ++iCpu, iRows += nbRows) {
319 if (m_kernel->rank() != m_ranks[iCpu])
321 nbRows = m_kernel->topology()->gathered_nb_row(iCpu + 1) - m_kernel->topology()->gathered_nb_row(iCpu);
322 if (iCpu == m_kernel->rank())
324 debug() <<
"\33[1;36m[AlephVector::REassemble] send "
327 <<
", offset=" << iRows
328 <<
" for " << nbRows <<
"\33[0m";
329 m_parallel_reassemble_requests.add(m_kernel->world()->send(m_aleph_vector_buffer_vals.view().subView(iRows, nbRows), iCpu,
false));
337reassemble_waitAndFill(
void)
339 ItacFunction(AlephVector);
340 if (!m_kernel->isParallel())
342 m_kernel->world()->waitAllRequests(m_parallel_reassemble_requests);
343 m_parallel_reassemble_requests.clear();
344 debug() <<
"\33[1;36m[AlephVector::REassemble_waitAndFill]"
351getLocalComponents(Integer vector_size,
352 ConstArrayView<AlephInt> global_indice,
353 ArrayView<double> vector_values)
355 ItacFunction(AlephVector);
356 debug() <<
"\33[1;36m[AlephVector::getLocalComponents] vector_size=" << vector_size <<
"\33[0m";
357 if (!m_kernel->isParallel()) {
359 m_implementation->AlephVectorGet(vector_values.data(),
360 global_indice.data(),
362 debug() <<
"\33[1;36m[AlephVector::getLocalComponents] seq done!\33[0m";
366 for (
int i = 0; i < vector_size; ++i) {
368 if (m_participating_in_solver && (m_kernel->rank() == m_ranks[m_kernel->rank()])) {
369 if (!m_kernel->isCellOrdering()) {
370 vector_values[i] = m_aleph_vector_buffer_vals[global_indice[i] - m_aleph_vector_buffer_idxs[0]];
373 vector_values[i] = m_aleph_vector_buffer_vals[global_indice[i]];
378 vector_values[i] = m_aleph_vector_buffer_val[i];
381 debug() <<
"\33[1;36m[AlephVector::getLocalComponents] parallel done!\33[0m";
388getLocalComponents(Array<double>& vector_values)
390 const Integer vector_size = m_kernel->topology()->nb_row_rank();
391 vector_values.resize(vector_size);
392 m_aleph_vector_buffer_idx.resize(vector_size);
393 ItacFunction(AlephVector);
394 debug() <<
"\33[1;36m[getLocalComponents(vector_values)] vector_size=" << vector_size <<
"\33[0m";
395 if (!m_kernel->isParallel()) {
396 for (Integer i = 0; i < vector_size; i += 1) {
397 m_aleph_vector_buffer_idx[i] = i;
402 m_implementation->AlephVectorGet(vector_values.data(), m_aleph_vector_buffer_idx.data(), vector_size);
403 debug() <<
"\33[1;36m[getLocalComponents(vector_values)] seq done!\33[0m";
407 for (
int i = 0; i < vector_size; ++i) {
409 if (m_participating_in_solver && (m_kernel->rank() == m_ranks[m_kernel->rank()])) {
410 vector_values[i] = m_aleph_vector_buffer_vals[i];
413 vector_values[i] = m_aleph_vector_buffer_val[i];
416 debug() <<
"\33[1;36m[getLocalComponents(vector_values)] parallel done!\33[0m";
424 ItacFunction(AlephVector);
425 debug() <<
"\33[1;36m[AlephVector::startFilling]"
432writeToFile(
const String base_file_name)
434 ItacFunction(AlephVector);
435 debug() <<
"\33[1;36m[AlephVector::writeToFile]"
437 m_implementation->writeToFile(base_file_name);
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
-*- 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.
Int32 Integer
Type représentant un entier.