Arcane  v3.16.7.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, std::byte* window, Int64* sizeof_segments, Int64* sum_sizeof_segments, Int64 sizeof_window, IThreadBarrier* barrier)
31: m_my_rank(my_rank)
32, m_nb_rank(nb_rank)
33, m_ranks(ranks)
34, m_sizeof_type(sizeof_type)
35, m_actual_sizeof_win(sizeof_window)
36, m_max_sizeof_win(sizeof_window)
37, m_window_span(window, sizeof_window)
38, m_sizeof_segments_span(sizeof_segments, nb_rank)
39, m_sum_sizeof_segments_span(sum_sizeof_segments, nb_rank)
40, m_window(window)
41, m_sizeof_segments(sizeof_segments)
42, m_sum_sizeof_segments(sum_sizeof_segments)
43, m_barrier(barrier)
44{}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49SharedMemoryMachineMemoryWindowBaseInternal::
50~SharedMemoryMachineMemoryWindowBaseInternal()
51{
52 if (m_my_rank == 0) {
53 delete[] m_window;
54 delete[] m_sizeof_segments;
55 delete[] m_sum_sizeof_segments;
56 }
57}
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
62Int32 SharedMemoryMachineMemoryWindowBaseInternal::
63sizeofOneElem() const
64{
65 return m_sizeof_type;
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71Span<std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
72segment() const
73{
74 const Int64 begin_segment = m_sum_sizeof_segments_span[m_my_rank];
75 const Int64 size_segment = m_sizeof_segments_span[m_my_rank];
76
77 return m_window_span.subSpan(begin_segment, size_segment);
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83Span<std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
84segment(Int32 rank) const
85{
86 const Int64 begin_segment = m_sum_sizeof_segments_span[rank];
87 const Int64 size_segment = m_sizeof_segments_span[rank];
88
89 return m_window_span.subSpan(begin_segment, size_segment);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95Span<std::byte> SharedMemoryMachineMemoryWindowBaseInternal::
96window() const
97{
98 return m_window_span;
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104void SharedMemoryMachineMemoryWindowBaseInternal::
105resizeSegment(Int64 new_sizeof_segment)
106{
107 m_sizeof_segments_span[m_my_rank] = new_sizeof_segment;
108
109 m_barrier->wait();
110
111 if (m_my_rank == 0) {
112 Int64 sum = 0;
113 for (Int32 i = 0; i < m_nb_rank; ++i) {
114 m_sum_sizeof_segments_span[i] = sum;
115 sum += m_sizeof_segments_span[i];
116 }
117 if (sum > m_max_sizeof_win) {
118 ARCANE_FATAL("New size of window (sum of size of all segments) is superior than the old size");
119 }
120 m_actual_sizeof_win = sum;
121 }
122 else {
123 Int64 sum = 0;
124 for (Int32 i = 0; i < m_nb_rank; ++i) {
125 sum += m_sizeof_segments_span[i];
126 }
127 if (sum > m_max_sizeof_win) {
128 ARCANE_FATAL("New size of window (sum of size of all segments) is superior than the old size");
129 }
130 m_actual_sizeof_win = sum;
131 }
132
133 m_window_span = Span<std::byte>{ m_window_span.data(), m_actual_sizeof_win };
134
135 m_barrier->wait();
136}
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
141ConstArrayView<Int32> SharedMemoryMachineMemoryWindowBaseInternal::
142machineRanks() const
143{
144 return m_ranks;
145}
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
150void SharedMemoryMachineMemoryWindowBaseInternal::
151barrier() const
152{
153 m_barrier->wait();
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159} // namespace Arcane::MessagePassing
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
#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.