Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
SharedMemoryMachineMemoryWindowBaseInternal.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/* SharedMemoryMachineMemoryWindowBaseInternal.cc (C) 2000-2025 */
9/* */
10/* Classe permettant de créer une fenêtre mémoire pour l'ensemble des */
11/* sous-domaines en mémoire partagée. */
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/parallel/thread/internal/SharedMemoryMachineMemoryWindowBaseInternal.h"
15
16#include "arcane/utils/FatalErrorException.h"
17
18#include "arccore/concurrency/IThreadBarrier.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29SharedMemoryMachineMemoryWindowBaseInternal::
30SharedMemoryMachineMemoryWindowBaseInternal(Int32 my_rank, Int32 nb_rank, ConstArrayView<Int32> ranks, Int32 sizeof_type, Ref<UniqueArray<std::byte>> window, Ref<UniqueArray<Int64>> sizeof_segments, Ref<UniqueArray<Int64>> sum_sizeof_segments, Int64 sizeof_window, IThreadBarrier* barrier)
31: m_my_rank(my_rank)
32, m_nb_rank(nb_rank)
33, m_sizeof_type(sizeof_type)
34, m_actual_sizeof_win(sizeof_window)
35, m_max_sizeof_win(sizeof_window)
36, m_ranks(ranks)
37, m_window_span(window->span())
38, m_window(window)
39, m_sizeof_segments(sizeof_segments)
40, m_sizeof_segments_span(sizeof_segments->smallSpan())
41, m_sum_sizeof_segments(sum_sizeof_segments)
42, m_sum_sizeof_segments_span(sum_sizeof_segments->smallSpan())
43, m_barrier(barrier)
44{}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49Int32 SharedMemoryMachineMemoryWindowBaseInternal::
50sizeofOneElem() const
51{
52 return m_sizeof_type;
53}
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58Span<std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
59segmentView()
60{
61 const Int64 begin_segment = m_sum_sizeof_segments_span[m_my_rank];
62 const Int64 size_segment = m_sizeof_segments_span[m_my_rank];
63
64 return m_window_span.subSpan(begin_segment, size_segment);
65}
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70Span<std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
71segmentView(Int32 rank)
72{
73 const Int64 begin_segment = m_sum_sizeof_segments_span[rank];
74 const Int64 size_segment = m_sizeof_segments_span[rank];
75
76 return m_window_span.subSpan(begin_segment, size_segment);
77}
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82Span<std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
83windowView()
84{
85 return m_window_span;
86}
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91Span<const std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
92segmentConstView() const
93{
94 const Int64 begin_segment = m_sum_sizeof_segments_span[m_my_rank];
95 const Int64 size_segment = m_sizeof_segments_span[m_my_rank];
96
97 return m_window_span.subSpan(begin_segment, size_segment);
98}
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103Span<const std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
104segmentConstView(Int32 rank) const
105{
106 const Int64 begin_segment = m_sum_sizeof_segments_span[rank];
107 const Int64 size_segment = m_sizeof_segments_span[rank];
108
109 return m_window_span.subSpan(begin_segment, size_segment);
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115Span<const std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
116windowConstView() const
117{
118 return m_window_span;
119}
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
123
124void SharedMemoryMachineMemoryWindowBaseInternal::
125resizeSegment(Int64 new_sizeof_segment)
126{
127 m_sizeof_segments_span[m_my_rank] = new_sizeof_segment;
128
129 m_barrier->wait();
130
131 if (m_my_rank == 0) {
132 Int64 sum = 0;
133 for (Int32 i = 0; i < m_nb_rank; ++i) {
134 m_sum_sizeof_segments_span[i] = sum;
135 sum += m_sizeof_segments_span[i];
136 }
137 if (sum > m_max_sizeof_win) {
138 ARCANE_FATAL("New size of window (sum of size of all segments) is superior than the old size");
139 }
140 m_actual_sizeof_win = sum;
141 }
142 else {
143 Int64 sum = 0;
144 for (Int32 i = 0; i < m_nb_rank; ++i) {
145 sum += m_sizeof_segments_span[i];
146 }
147 if (sum > m_max_sizeof_win) {
148 ARCANE_FATAL("New size of window (sum of size of all segments) is superior than the old size");
149 }
150 m_actual_sizeof_win = sum;
151 }
152
153 m_window_span = Span<std::byte>{ m_window_span.data(), m_actual_sizeof_win };
154
155 m_barrier->wait();
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161ConstArrayView<Int32> SharedMemoryMachineMemoryWindowBaseInternal::
162machineRanks() const
163{
164 return m_ranks;
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170void SharedMemoryMachineMemoryWindowBaseInternal::
171barrier() const
172{
173 m_barrier->wait();
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179} // namespace Arcane::MessagePassing
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue constante d'un tableau de type T.
Vue d'un tableau d'éléments de type T.
Definition Span.h:513
Déclarations des types et méthodes utilisés par les mécanismes d'échange de messages.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.