Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Communicator.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* Communicator.h (C) 2000-2020 */
9/* */
10/* Communicateur pour l'échange de message. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_MESSAGEPASSING_COMMUNICATOR_H
13#define ARCCORE_MESSAGEPASSING_COMMUNICATOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arccore/base/Ref.h"
19
20#include <cstddef>
21#include <iosfwd>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
27{
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
44class ARCCORE_MESSAGEPASSING_EXPORT Communicator
45{
47 {
48 int i;
49 long l;
50 std::size_t st;
51 void* v;
52 const void* cv;
53 };
54
55 enum Type
56 {
57 T_Int,
58 T_Long,
59 T_SizeT,
60 T_Ptr,
61 T_Null
62 };
63
64 public:
65
67 {
68 m_type = T_Null;
69 m_communicator = null_communicator;
70 }
71
72 public:
73
74 explicit Communicator(void* acommunicator)
75 {
76 m_type = T_Ptr;
77 m_communicator.v = acommunicator;
78 }
79
80 explicit Communicator(const void* acommunicator)
81 {
82 m_type = T_Ptr;
83 m_communicator.cv = acommunicator;
84 }
85
86 explicit Communicator(int acommunicator)
87 {
88 m_type = T_Int;
89 m_communicator.i = acommunicator;
90 }
91
92 explicit Communicator(long acommunicator)
93 {
94 m_type = T_Long;
95 m_communicator.l = acommunicator;
96 }
97
98 explicit Communicator(std::size_t acommunicator)
99 {
100 m_type = T_SizeT;
101 m_communicator.st = acommunicator;
102 }
103
104
105 public:
106
107 template<typename T>
108 operator const T*() const { return (const T*)m_communicator.cv; }
109 template<typename T>
110 operator T*() const { return (T*)m_communicator.v; }
111 operator int() const { return m_communicator.i; }
112 operator long() const { return m_communicator.l; }
113 operator size_t() const { return m_communicator.st; }
114 void* communicatorAddress() { return &m_communicator; }
115
116 public:
117
123 bool isValid() const
124 {
125 if (m_type==T_Null)
126 return false;
127 // Si le type de la requête est différent du type
128 // de la requête nulle, alors la requête est considérée
129 // comme valide.
130 if (m_type!=null_communicator_type)
131 return true;
132 if (m_type==T_Int)
133 return m_communicator.i!=null_communicator.i;
134 if (m_type==T_Long)
135 return m_communicator.l!=null_communicator.l;
136 if (m_type==T_SizeT)
137 return m_communicator.st!=null_communicator.st;
138 if (m_type==T_Ptr)
139 return m_communicator.cv!=null_communicator.cv;
140 return false;
141 }
142
143 static void setNullCommunicator(Communicator r)
144 {
145 null_communicator = r.m_communicator;
146 null_communicator_type = r.m_type;
147 }
148
149 void reset()
150 {
151 m_communicator = null_communicator;
152 m_type = T_Null;
153 }
154
155 void print(std::ostream& o) const;
156
157 friend inline std::ostream& operator<<(std::ostream& o,const Communicator& pcommunicator)
158 {
159 pcommunicator.print(o);
160 return o;
161 }
162
164 Int32 _type() const { return m_type; }
165
166 private:
167
168 int m_type = T_Null;
169 _Communicator m_communicator;
170 static _Communicator null_communicator;
171 static int null_communicator_type;
172};
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177} // End namespace Arccore::MessagePassing
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182#endif
183
Déclarations générales de la composante 'message_passing'.
Gestion des références à une classe C++.
Communicateur pour l'échange de message.
bool isValid() const
Indique si le communicateur est valide.
Espace de nommage contenant les types et déclarations qui gèrent le mécanisme de parallélisme par éch...
std::int32_t Int32
Type entier signé sur 32 bits.