Arcane  v3.16.6.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
MpiAllInOneMachineMemoryWindowBase.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/* MpiAllInOneMachineMemoryWindowBase.cc (C) 2000-2025 */
9/* */
10/* Classe permettant de créer une fenêtre mémoire pour un noeud */
11/* de calcul avec MPI. Chaque section de processus contiendra le MPI_Win. */
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/message_passing_mpi/internal/MpiAllInOneMachineMemoryWindowBase.h"
15
16#include "arccore/base/FatalErrorException.h"
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane::MessagePassing::Mpi
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27MpiAllInOneMachineMemoryWindowBase::
28MpiAllInOneMachineMemoryWindowBase(void* node_window, MPI_Aint offset, const MPI_Comm& comm, Int32 my_node_rank)
29: m_node_window(node_window)
30, m_nb_elem_local(0)
31, m_offset(offset)
32, m_comm(comm)
33, m_my_rank(my_node_rank)
34, m_size_type(0)
35{
36 m_win = reinterpret_cast<MPI_Win*>(static_cast<char*>(m_node_window) - offset);
37 void* ptr_win = nullptr;
38 int error = MPI_Win_shared_query(*m_win, m_my_rank, &m_nb_elem_local, &m_size_type, &ptr_win);
39
40 if (error != MPI_SUCCESS) {
41 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
42 }
43}
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48MpiAllInOneMachineMemoryWindowBase::
49~MpiAllInOneMachineMemoryWindowBase() = default;
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54Integer MpiAllInOneMachineMemoryWindowBase::
55sizeofOneElem() const
56{
57 return m_size_type;
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63Integer MpiAllInOneMachineMemoryWindowBase::
64sizeSegment() const
65{
66 return static_cast<Integer>(m_nb_elem_local);
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72Integer MpiAllInOneMachineMemoryWindowBase::
73sizeSegment(Int32 rank) const
74{
75 MPI_Aint size_win;
76 int size_type;
77 void* ptr_win = nullptr;
78
79 int error = MPI_Win_shared_query(*m_win, rank, &size_win, &size_type, &ptr_win);
80
81 if (error != MPI_SUCCESS) {
82 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
83 }
84
85 return static_cast<Integer>((size_win - m_offset) / size_type);
86}
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91void* MpiAllInOneMachineMemoryWindowBase::
92data() const
93{
94 return m_node_window;
95}
96
97/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
100void* MpiAllInOneMachineMemoryWindowBase::
101data(Int32 rank) const
102{
103 MPI_Aint size_win;
104 int size_type;
105 void* ptr_win = nullptr;
106
107 int error = MPI_Win_shared_query(*m_win, rank, &size_win, &size_type, &ptr_win);
108
109 if (error != MPI_SUCCESS) {
110 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
111 }
112
113 return (static_cast<char*>(ptr_win) + m_offset);
114}
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119std::pair<Integer, void*> MpiAllInOneMachineMemoryWindowBase::
120sizeAndDataSegment() const
121{
122 return sizeAndDataSegment(m_my_rank);
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128std::pair<Integer, void*> MpiAllInOneMachineMemoryWindowBase::
129sizeAndDataSegment(Int32 rank) const
130{
131 MPI_Aint size_win;
132 int size_type;
133 void* ptr_win = nullptr;
134
135 int error = MPI_Win_shared_query(*m_win, rank, &size_win, &size_type, &ptr_win);
136
137 if (error != MPI_SUCCESS) {
138 ARCCORE_FATAL("Error with MPI_Win_allocate_shared() call");
139 }
140
141 return { static_cast<Integer>((size_win - m_offset) / size_type), (static_cast<char*>(ptr_win) + m_offset) };
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147} // End namespace Arcane::MessagePassing::Mpi
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
Int32 Integer
Type représentant un entier.
std::int32_t Int32
Type entier signé sur 32 bits.