Arcane  v3.16.7.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
MpiDynamicMachineMemoryWindowBaseInternal.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* MpiDynamicMachineMemoryWindowBaseInternal.h (C) 2000-2025 */
9/* */
10/* Classe permettant de créer des fenêtres mémoires pour un noeud de calcul. */
11/* Les segments de ces fenêtres ne sont pas contigües en mémoire et peuvent */
12/* être redimensionnées. */
13/*---------------------------------------------------------------------------*/
14
15#include "arccore/message_passing_mpi/internal/MpiDynamicMachineMemoryWindowBaseInternal.h"
16
17#include "arccore/base/FatalErrorException.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::MessagePassing::Mpi
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28MpiDynamicMachineMemoryWindowBaseInternal::
29MpiDynamicMachineMemoryWindowBaseInternal(Int64 sizeof_segment, Int32 sizeof_type, const MPI_Comm& comm_machine, Int32 comm_machine_rank, Int32 comm_machine_size, ConstArrayView<Int32> machine_ranks)
30: m_win_need_resize()
31, m_win_actual_sizeof()
32, m_win_target_segments()
33, m_comm_machine(comm_machine)
34, m_comm_machine_size(comm_machine_size)
35, m_comm_machine_rank(comm_machine_rank)
36, m_sizeof_type(sizeof_type)
37, m_machine_ranks(machine_ranks)
38{
39 if (m_sizeof_type <= 0) {
40 ARCCORE_FATAL("Invalid sizeof_type");
41 }
42 if (sizeof_segment < 0 || sizeof_segment % m_sizeof_type != 0) {
43 ARCCORE_FATAL("Invalid initial sizeof_segment");
44 }
45 m_all_mpi_win.resize(m_comm_machine_size);
46
47 MPI_Info win_info_true;
48 MPI_Info_create(&win_info_true);
49 MPI_Info_set(win_info_true, "alloc_shared_noncontig", "true");
50
51 MPI_Info win_info_false;
52 MPI_Info_create(&win_info_false);
53 MPI_Info_set(win_info_false, "alloc_shared_noncontig", "false");
54
55 {
56 for (Integer i = 0; i < m_comm_machine_size; ++i) {
57 Int64 size_seg = 0;
58 if (m_comm_machine_rank == i) {
59 if (sizeof_segment == 0)
60 size_seg = m_sizeof_type;
61 else
62 size_seg = sizeof_segment;
63 }
64
65 std::byte* ptr_seg = nullptr;
66 int error = MPI_Win_allocate_shared(size_seg, m_sizeof_type, win_info_true, m_comm_machine, &ptr_seg, &m_all_mpi_win[i]);
67
68 if (error != MPI_SUCCESS) {
69 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
70 }
71 }
72 {
73 MPI_Aint size_seg;
74 int size_type;
75 std::byte* ptr_seg = nullptr;
76 int error = MPI_Win_shared_query(m_all_mpi_win[m_comm_machine_rank], m_comm_machine_rank, &size_seg, &size_type, &ptr_seg);
77
78 if (error != MPI_SUCCESS) {
79 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
80 }
81
82 // Attention : L'utilisateur demande un nombre minimum d'éléments réservés.
83 // Mais MPI réserve la taille qu'il veut (effet du alloc_shared_noncontig=true).
84 // On est juste sûr que la taille qu'il a réservée est supérieure ou égale à sizeof_segment.
85 m_reserved_part_span = Span<std::byte>{ ptr_seg, size_seg };
86 }
87 }
88
89 {
90 Int64* ptr_seg = nullptr;
91 Int64* ptr_win = nullptr;
92 {
93 int error = MPI_Win_allocate_shared(sizeof(Int64), sizeof(Int64), win_info_false, m_comm_machine, &ptr_seg, &m_win_need_resize);
94
95 if (error != MPI_SUCCESS) {
96 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
97 }
98 }
99 {
100 MPI_Aint size_seg;
101 int size_type;
102 int error = MPI_Win_shared_query(m_win_need_resize, 0, &size_seg, &size_type, &ptr_win);
103
104 if (error != MPI_SUCCESS) {
105 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
106 }
107
108 m_need_resize = Span<Int64>{ ptr_win, m_comm_machine_size };
109 m_need_resize[m_comm_machine_rank] = -1;
110 }
111 if (ptr_win + m_comm_machine_rank != ptr_seg) {
112 ARCCORE_FATAL("m_win_need_resize is noncontig");
113 }
114 }
115
116 {
117 Int64* ptr_seg = nullptr;
118 Int64* ptr_win = nullptr;
119 {
120 int error = MPI_Win_allocate_shared(sizeof(Int64), sizeof(Int64), win_info_false, m_comm_machine, &ptr_seg, &m_win_actual_sizeof);
121
122 if (error != MPI_SUCCESS) {
123 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
124 }
125 }
126 {
127 MPI_Aint size_seg;
128 int size_type;
129 int error = MPI_Win_shared_query(m_win_actual_sizeof, 0, &size_seg, &size_type, &ptr_win);
130
131 if (error != MPI_SUCCESS) {
132 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
133 }
134
135 m_sizeof_used_part = Span<Int64>{ ptr_win, m_comm_machine_size };
136 m_sizeof_used_part[m_comm_machine_rank] = sizeof_segment;
137 }
138 if (ptr_win + m_comm_machine_rank != ptr_seg) {
139 ARCCORE_FATAL("m_win_actual_sizeof is noncontig");
140 }
141 }
142
143 {
144 Int32* ptr_seg = nullptr;
145 Int32* ptr_win = nullptr;
146 {
147 int error = MPI_Win_allocate_shared(sizeof(Int32), sizeof(Int32), win_info_false, m_comm_machine, &ptr_seg, &m_win_target_segments);
148
149 if (error != MPI_SUCCESS) {
150 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
151 }
152 }
153 {
154 MPI_Aint size_seg;
155 int size_type;
156 int error = MPI_Win_shared_query(m_win_target_segments, 0, &size_seg, &size_type, &ptr_win);
157
158 if (error != MPI_SUCCESS) {
159 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
160 }
161
162 m_target_segments = Span<Int32>{ ptr_win, m_comm_machine_size };
163 m_target_segments[m_comm_machine_rank] = -1;
164 }
165 if (ptr_win + m_comm_machine_rank != ptr_seg) {
166 ARCCORE_FATAL("m_win_owner_segments is noncontig");
167 }
168 }
169
170 MPI_Info_free(&win_info_false);
171 MPI_Info_free(&win_info_true);
172
173 MPI_Barrier(m_comm_machine);
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179MpiDynamicMachineMemoryWindowBaseInternal::
180~MpiDynamicMachineMemoryWindowBaseInternal()
181{
182 for (Integer i = 0; i < m_comm_machine_size; ++i) {
183 MPI_Win_free(&m_all_mpi_win[i]);
184 }
185 MPI_Win_free(&m_win_need_resize);
186 MPI_Win_free(&m_win_actual_sizeof);
187 MPI_Win_free(&m_win_target_segments);
188}
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193Int32 MpiDynamicMachineMemoryWindowBaseInternal::
194sizeofOneElem() const
195{
196 return m_sizeof_type;
197}
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202ConstArrayView<Int32> MpiDynamicMachineMemoryWindowBaseInternal::
203machineRanks() const
204{
205 return m_machine_ranks;
206}
207
208/*---------------------------------------------------------------------------*/
209/*---------------------------------------------------------------------------*/
210
211void MpiDynamicMachineMemoryWindowBaseInternal::
212barrier() const
213{
214 MPI_Barrier(m_comm_machine);
215}
216
217/*---------------------------------------------------------------------------*/
218/*---------------------------------------------------------------------------*/
219
220Span<std::byte> MpiDynamicMachineMemoryWindowBaseInternal::
221segmentView()
222{
223 return m_reserved_part_span.subSpan(0, m_sizeof_used_part[m_comm_machine_rank]);
224}
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
228
229Span<std::byte> MpiDynamicMachineMemoryWindowBaseInternal::
230segmentView(Int32 rank)
231{
232 const Int32 machine_rank = _worldToMachine(rank);
233
234 MPI_Aint size_seg;
235 int size_type;
236 std::byte* ptr_seg = nullptr;
237 int error = MPI_Win_shared_query(m_all_mpi_win[machine_rank], machine_rank, &size_seg, &size_type, &ptr_seg);
238
239 if (error != MPI_SUCCESS) {
240 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
241 }
242
243 return Span<std::byte>{ ptr_seg, m_sizeof_used_part[machine_rank] };
244}
245
246/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
248
249Span<const std::byte> MpiDynamicMachineMemoryWindowBaseInternal::
250segmentConstView() const
251{
252 return m_reserved_part_span.subSpan(0, m_sizeof_used_part[m_comm_machine_rank]);
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258Span<const std::byte> MpiDynamicMachineMemoryWindowBaseInternal::
259segmentConstView(Int32 rank) const
260{
261 const Int32 machine_rank = _worldToMachine(rank);
262
263 MPI_Aint size_seg;
264 int size_type;
265 std::byte* ptr_seg = nullptr;
266 int error = MPI_Win_shared_query(m_all_mpi_win[machine_rank], machine_rank, &size_seg, &size_type, &ptr_seg);
267
268 if (error != MPI_SUCCESS) {
269 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
270 }
271
272 return Span<const std::byte>{ ptr_seg, m_sizeof_used_part[machine_rank] };
273}
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
277
278void MpiDynamicMachineMemoryWindowBaseInternal::
279add(Span<const std::byte> elem)
280{
281 if (elem.size() % m_sizeof_type) {
282 ARCCORE_FATAL("Sizeof elem not valid");
283 }
284
285 const Int64 actual_sizeof_win = m_sizeof_used_part[m_comm_machine_rank];
286 const Int64 future_sizeof_win = actual_sizeof_win + elem.size();
287 const Int64 old_reserved = m_reserved_part_span.size();
288
289 if (future_sizeof_win > old_reserved) {
290 _reallocBarrier(future_sizeof_win);
291 if (m_reserved_part_span.size() < future_sizeof_win) {
292 ARCCORE_FATAL("Bad realloc -- Old size : {0} -- New size : {1} -- Needed size : {2}", old_reserved, m_reserved_part_span.size(), future_sizeof_win);
293 }
294 }
295 else {
296 _reallocBarrier();
297 }
298
299 for (Int64 pos_win = actual_sizeof_win, pos_elem = 0; pos_win < future_sizeof_win; ++pos_win, ++pos_elem) {
300 m_reserved_part_span[pos_win] = elem[pos_elem];
301 }
302 m_sizeof_used_part[m_comm_machine_rank] = future_sizeof_win;
303
304 // Barrière car d'autres peuvent utiliser la taille du segment
305 // (m_sizeof_used_part) que nous possédons (segmentView(Int32 rank) par
306 // exemple).
307 MPI_Barrier(m_comm_machine);
308}
309
310/*---------------------------------------------------------------------------*/
311/*---------------------------------------------------------------------------*/
312
313void MpiDynamicMachineMemoryWindowBaseInternal::
314add()
315{
316 _reallocBarrier();
317 MPI_Barrier(m_comm_machine);
318}
319
320/*---------------------------------------------------------------------------*/
321/*---------------------------------------------------------------------------*/
322
323void MpiDynamicMachineMemoryWindowBaseInternal::
324addToAnotherSegment(Int32 rank, Span<const std::byte> elem)
325{
326 if (elem.size() % m_sizeof_type) {
327 ARCCORE_FATAL("Sizeof elem not valid");
328 }
329
330 const Int32 machine_rank = _worldToMachine(rank);
331
332 m_target_segments[m_comm_machine_rank] = machine_rank;
333 MPI_Barrier(m_comm_machine);
334
335 // On doit savoir si quelqu'un va ajouter des éléments dans notre segment
336 // pour pouvoir mettre à jour la vue.
337 bool is_my_seg_edited = false;
338 {
339 bool is_found = false;
340 for (const Int32 rank_asked : m_target_segments) {
341 if (rank_asked == machine_rank) {
342 if (!is_found) {
343 is_found = true;
344 }
345 else {
346 ARCCORE_FATAL("Two subdomains ask same rank for addToAnotherSegment()");
347 }
348 }
349 if (rank_asked == m_comm_machine_rank) {
350 is_my_seg_edited = true;
351 }
352 }
353 }
354
355 Span<std::byte> rank_reserved_part_span;
356 {
357 MPI_Aint size_seg;
358 std::byte* ptr_seg = nullptr;
359 int size_type;
360 int error = MPI_Win_shared_query(m_all_mpi_win[machine_rank], machine_rank, &size_seg, &size_type, &ptr_seg);
361
362 if (error != MPI_SUCCESS) {
363 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
364 }
365 rank_reserved_part_span = Span<std::byte>{ ptr_seg, size_seg };
366 }
367
368 const Int64 actual_sizeof_win = m_sizeof_used_part[machine_rank];
369 const Int64 future_sizeof_win = actual_sizeof_win + elem.size();
370 const Int64 old_reserved = rank_reserved_part_span.size();
371
372 if (future_sizeof_win > old_reserved) {
373 _reallocBarrier(machine_rank, future_sizeof_win);
374
375 {
376 MPI_Aint size_seg;
377 std::byte* ptr_seg = nullptr;
378 int size_type;
379 int error = MPI_Win_shared_query(m_all_mpi_win[machine_rank], machine_rank, &size_seg, &size_type, &ptr_seg);
380
381 if (error != MPI_SUCCESS) {
382 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
383 }
384 rank_reserved_part_span = Span<std::byte>{ ptr_seg, size_seg };
385 }
386
387 if (rank_reserved_part_span.size() < future_sizeof_win) {
388 ARCCORE_FATAL("Bad realloc -- Old size : {0} -- New size : {1} -- Needed size : {2}", old_reserved, rank_reserved_part_span.size(), future_sizeof_win);
389 }
390 }
391 else {
392 _reallocBarrier();
393 }
394
395 for (Int64 pos_win = actual_sizeof_win, pos_elem = 0; pos_win < future_sizeof_win; ++pos_win, ++pos_elem) {
396 rank_reserved_part_span[pos_win] = elem[pos_elem];
397 }
398 m_sizeof_used_part[machine_rank] = future_sizeof_win;
399
400 // Barrière car d'autres peuvent utiliser la taille du segment
401 // (m_sizeof_used_part) que nous possédons (segmentView(Int32 machine_rank) par
402 // exemple).
403 MPI_Barrier(m_comm_machine);
404 m_target_segments[m_comm_machine_rank] = -1;
405
406 // On met à jour notre vue.
407 if (is_my_seg_edited) {
408 MPI_Aint size_seg;
409 std::byte* ptr_seg = nullptr;
410 int size_type;
411 int error = MPI_Win_shared_query(m_all_mpi_win[m_comm_machine_rank], m_comm_machine_rank, &size_seg, &size_type, &ptr_seg);
412
413 if (error != MPI_SUCCESS) {
414 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
415 }
416 m_reserved_part_span = Span<std::byte>{ ptr_seg, size_seg };
417 }
418}
419
420/*---------------------------------------------------------------------------*/
421/*---------------------------------------------------------------------------*/
422
423void MpiDynamicMachineMemoryWindowBaseInternal::
424addToAnotherSegment()
425{
426 // Même si on n'ajoute rien, un autre processus pourrait ajouter des
427 // éléments dans notre segment.
428 MPI_Barrier(m_comm_machine);
429
430 bool is_my_seg_edited = false;
431 for (const Int32 rank : m_target_segments) {
432 if (rank == m_comm_machine_rank) {
433 is_my_seg_edited = true;
434 break;
435 }
436 }
437
438 _reallocBarrier();
439 MPI_Barrier(m_comm_machine);
440
441 if (is_my_seg_edited) {
442 MPI_Aint size_seg;
443 std::byte* ptr_seg = nullptr;
444 int size_type;
445 int error = MPI_Win_shared_query(m_all_mpi_win[m_comm_machine_rank], m_comm_machine_rank, &size_seg, &size_type, &ptr_seg);
446
447 if (error != MPI_SUCCESS) {
448 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
449 }
450 m_reserved_part_span = Span<std::byte>{ ptr_seg, size_seg };
451 }
452}
453
454/*---------------------------------------------------------------------------*/
455/*---------------------------------------------------------------------------*/
456
457void MpiDynamicMachineMemoryWindowBaseInternal::
458reserve(Int64 new_capacity)
459{
460 if (new_capacity <= m_reserved_part_span.size()) {
461 _reallocBarrier();
462 }
463 else {
464 _reallocBarrier(new_capacity);
465 }
466}
467
468/*---------------------------------------------------------------------------*/
469/*---------------------------------------------------------------------------*/
470
471void MpiDynamicMachineMemoryWindowBaseInternal::
472reserve()
473{
474 _reallocBarrier();
475}
476
477/*---------------------------------------------------------------------------*/
478/*---------------------------------------------------------------------------*/
479
480void MpiDynamicMachineMemoryWindowBaseInternal::
481resize(Int64 new_size)
482{
483 if (new_size == -1) {
484 _reallocBarrier();
485 MPI_Barrier(m_comm_machine);
486 return;
487 }
488
489 if (new_size < 0 || new_size % m_sizeof_type) {
490 ARCCORE_FATAL("new_size not valid");
491 }
492
493 Int64 old_reserved = m_reserved_part_span.size();
494
495 if (new_size > old_reserved) {
496 _reallocBarrier(new_size);
497 if (m_reserved_part_span.size() < new_size) {
498 ARCCORE_FATAL("Bad realloc -- Old size : {0} -- New size : {1} -- Needed size : {2}", old_reserved, m_reserved_part_span.size(), new_size);
499 }
500 }
501 else {
502 _reallocBarrier();
503 }
504 m_sizeof_used_part[m_comm_machine_rank] = new_size;
505
506 // Barrière car d'autres peuvent utiliser la taille du segment
507 // (m_sizeof_used_part) que nous possédons (segmentView(Int32 rank) par
508 // exemple).
509 MPI_Barrier(m_comm_machine);
510}
511
512/*---------------------------------------------------------------------------*/
513/*---------------------------------------------------------------------------*/
514
515void MpiDynamicMachineMemoryWindowBaseInternal::
516resize()
517{
518 _reallocBarrier();
519 MPI_Barrier(m_comm_machine);
520}
521
522/*---------------------------------------------------------------------------*/
523/*---------------------------------------------------------------------------*/
524
525void MpiDynamicMachineMemoryWindowBaseInternal::
526shrink()
527{
528 if (m_reserved_part_span.size() == m_sizeof_used_part[m_comm_machine_rank]) {
529 _reallocBarrier();
530 }
531 else {
532 _reallocBarrier(m_sizeof_used_part[m_comm_machine_rank]);
533 }
534}
535
536/*---------------------------------------------------------------------------*/
537/*---------------------------------------------------------------------------*/
538
539void MpiDynamicMachineMemoryWindowBaseInternal::
540_reallocBarrier(Int64 new_sizeof)
541{
542 m_need_resize[m_comm_machine_rank] = new_sizeof;
543
544 // Barrière importante car tout le monde doit savoir que l'on doit
545 // redimensionner le segment que nous possédons.
546 MPI_Barrier(m_comm_machine);
547
548 _reallocCollective();
549
550 // Pas besoin de barrière car MPI_Win_allocate_shared() de
551 // _reallocCollective() est bloquant.
552 m_need_resize[m_comm_machine_rank] = -1;
553
554 // Barrière importante dans le cas où un MPI_Win_shared_query() de
555 // _reallocCollective() durerait trop longtemps (un autre processus pourrait
556 // rappeler cette méthode et remettre m_need_resize[m_comm_machine_rank] à
557 // true => deadlock dans _reallocCollective() sur MPI_Win_allocate_shared()
558 // à cause du continue).
559 MPI_Barrier(m_comm_machine);
560}
561
562/*---------------------------------------------------------------------------*/
563/*---------------------------------------------------------------------------*/
564
565void MpiDynamicMachineMemoryWindowBaseInternal::
566_reallocBarrier(Int32 machine_rank, Int64 new_sizeof)
567{
568 m_need_resize[machine_rank] = new_sizeof;
569
570 // Barrière importante car tout le monde doit savoir que l'on doit
571 // redimensionner le segment que nous possédons.
572 MPI_Barrier(m_comm_machine);
573
574 _reallocCollective();
575
576 // Pas besoin de barrière car MPI_Win_allocate_shared() de
577 // _reallocCollective() est bloquant.
578 m_need_resize[machine_rank] = -1;
579
580 // Barrière importante dans le cas où un MPI_Win_shared_query() de
581 // _reallocCollective() durerait trop longtemps (un autre processus pourrait
582 // rappeler cette méthode et remettre m_need_resize[machine_rank] à
583 // true => deadlock dans _reallocCollective() sur MPI_Win_allocate_shared()
584 // à cause du continue).
585 MPI_Barrier(m_comm_machine);
586}
587
588/*---------------------------------------------------------------------------*/
589/*---------------------------------------------------------------------------*/
590
591void MpiDynamicMachineMemoryWindowBaseInternal::
592_reallocBarrier()
593{
594 MPI_Barrier(m_comm_machine);
595 _reallocCollective();
596 MPI_Barrier(m_comm_machine);
597}
598
599/*---------------------------------------------------------------------------*/
600/*---------------------------------------------------------------------------*/
601
602void MpiDynamicMachineMemoryWindowBaseInternal::
603_reallocCollective()
604{
605 MPI_Info win_info;
606 MPI_Info_create(&win_info);
607 MPI_Info_set(win_info, "alloc_shared_noncontig", "true");
608
609 for (Integer i = 0; i < m_comm_machine_size; ++i) {
610 if (m_need_resize[i] == -1)
611 continue;
612
613 ARCCORE_ASSERT(m_need_resize[i] >= 0, ("New size must be >= 0"));
614 ARCCORE_ASSERT(m_need_resize[i] % m_sizeof_type == 0, ("New size must be % sizeof type"));
615
616 const Int64 size_seg = (m_comm_machine_rank == i ? (m_need_resize[i] == 0 ? m_sizeof_type : m_need_resize[i]) : 0);
617
618 MPI_Win old_win = m_all_mpi_win[i];
619
620 std::byte* ptr_seg = nullptr;
621
622 // Si size_seg == 0 alors ptr_seg == nullptr.
623 int error = MPI_Win_allocate_shared(size_seg, m_sizeof_type, win_info, m_comm_machine, &ptr_seg, &m_all_mpi_win[i]);
624 if (error != MPI_SUCCESS) {
625 MPI_Info_free(&win_info);
626 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
627 }
628
629 if (m_comm_machine_rank == i) {
630
631 MPI_Aint mpi_reserved_size_seg;
632 int size_type;
633
634 // Ici, ptr_seg n'est jamais == nullptr vu que l'on fait toujours un segment d'une taille d'au moins
635 // m_sizeof_type.
636 error = MPI_Win_shared_query(m_all_mpi_win[m_comm_machine_rank], m_comm_machine_rank, &mpi_reserved_size_seg, &size_type, &ptr_seg);
637 if (error != MPI_SUCCESS || ptr_seg == nullptr) {
638 MPI_Win_free(&old_win);
639 MPI_Info_free(&win_info);
640 ARCCORE_FATAL("Error with MPI_Win_shared_query() call");
641 }
642
643 const Int64 min_size = std::min(m_need_resize[i], m_sizeof_used_part[m_comm_machine_rank]);
644 memcpy(ptr_seg, m_reserved_part_span.data(), min_size);
645
646 m_reserved_part_span = Span<std::byte>{ ptr_seg, mpi_reserved_size_seg };
647 }
648 MPI_Win_free(&old_win);
649 }
650 MPI_Info_free(&win_info);
651}
652
653/*---------------------------------------------------------------------------*/
654/*---------------------------------------------------------------------------*/
655
656Int32 MpiDynamicMachineMemoryWindowBaseInternal::
657_worldToMachine(Int32 world) const
658{
659 for (Int32 i = 0; i < m_comm_machine_size; ++i) {
660 if (m_machine_ranks[i] == world) {
661 return i;
662 }
663 }
664 ARCCORE_FATAL("Rank is not in machine");
665}
666
667/*---------------------------------------------------------------------------*/
668/*---------------------------------------------------------------------------*/
669
670Int32 MpiDynamicMachineMemoryWindowBaseInternal::
671_machineToWorld(Int32 machine) const
672{
673 return m_machine_ranks[machine];
674}
675
676/*---------------------------------------------------------------------------*/
677/*---------------------------------------------------------------------------*/
678
679} // namespace Arcane::MessagePassing::Mpi
680
681/*---------------------------------------------------------------------------*/
682/*---------------------------------------------------------------------------*/
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.