Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MpiDirectSendrecvVariableSynchronizeDispatcher.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* MpiDirectSendrecvVariableSynchronizeDispatcher.cc (C) 2000-2025 */
9/* */
10/* Specific MPI management of variable synchronizations. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/MemoryView.h"
15
16#include "arcane/parallel/mpi/MpiParallelMng.h"
17#include "arcane/parallel/mpi/MpiDatatypeList.h"
18#include "arcane/parallel/mpi/MpiDatatype.h"
19#include "arcane/parallel/mpi/MpiTimeInterval.h"
20#include "arcane/parallel/IStat.h"
21
22#include "arcane/impl/IDataSynchronizeBuffer.h"
23#include "arcane/impl/IDataSynchronizeImplementation.h"
24
25#include "arccore/message_passing_mpi/internal/MpiAdapter.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
39class MpiDirectSendrecvVariableSynchronizerDispatcher
41{
42 public:
43
44 class Factory;
45 explicit MpiDirectSendrecvVariableSynchronizerDispatcher(Factory* f);
46
47 protected:
48
49 void compute() override {}
50 void beginSynchronize(IDataSynchronizeBuffer* vs_buf) override;
51 void endSynchronize(IDataSynchronizeBuffer*) override
52 {
53 // With this implementation, we do not need this function.
54 }
55
56 private:
57
58 MpiParallelMng* m_mpi_parallel_mng;
59};
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
66{
67 public:
68
69 Factory(MpiParallelMng* mpi_pm)
70 : m_mpi_parallel_mng(mpi_pm)
71 {}
72
73 Ref<IDataSynchronizeImplementation> createInstance() override
74 {
75 auto* x = new MpiDirectSendrecvVariableSynchronizerDispatcher(this);
77 }
78
79 public:
80
81 MpiParallelMng* m_mpi_parallel_mng = nullptr;
82};
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
88arcaneCreateMpiDirectSendrecvVariableSynchronizerFactory(MpiParallelMng* mpi_pm)
89{
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97MpiDirectSendrecvVariableSynchronizerDispatcher::
98MpiDirectSendrecvVariableSynchronizerDispatcher(Factory* f)
99: m_mpi_parallel_mng(f->m_mpi_parallel_mng)
100{
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106void MpiDirectSendrecvVariableSynchronizerDispatcher::
107beginSynchronize(IDataSynchronizeBuffer* vs_buf)
108{
109 Int32 nb_message = vs_buf->nbRank();
110
111 constexpr int serialize_tag = 523;
112
113 MpiParallelMng* pm = m_mpi_parallel_mng;
114 MpiDatatypeList* dtlist = pm->datatypes();
115 const MPI_Datatype mpi_dt = dtlist->datatype(Byte())->datatype();
116
117 double sync_copy_send_time = 0.0;
118 double sync_copy_recv_time = 0.0;
119 double sync_wait_time = 0.0;
120
121 {
122 MpiTimeInterval tit(&sync_copy_send_time);
123 vs_buf->copyAllSend();
124 }
125
126 {
127 MpiTimeInterval tit(&sync_wait_time);
128 for (Integer i = 0; i < nb_message; ++i) {
129 Int32 target_rank = vs_buf->targetRank(i);
130 auto rbuf = vs_buf->receiveBuffer(i).bytes().smallView();
131 auto sbuf = vs_buf->sendBuffer(i).bytes().smallView();
132
133 MPI_Sendrecv(sbuf.data(), sbuf.size(), mpi_dt, target_rank, serialize_tag,
134 rbuf.data(), rbuf.size(), mpi_dt, target_rank, serialize_tag,
135 pm->communicator(), MPI_STATUS_IGNORE);
136 }
137 }
138
139 {
140 MpiTimeInterval tit(&sync_copy_recv_time);
141 vs_buf->copyAllReceive();
142 }
143
144 pm->stat()->add("SyncCopySend", sync_copy_send_time, 1);
145 pm->stat()->add("SyncWait", sync_wait_time, 1);
146 pm->stat()->add("SyncCopyRecv", sync_copy_recv_time, 1);
147}
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
151
152} // End namespace Arcane
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
Generic buffer for data synchronization.
Interface for a generic dispatcher factory.
Parallelism manager using MPI.
Reference to an instance.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.