18 #include <type_traits>
29 #ifndef KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK
30 #define KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(Size1, Size2, CheckedFunction) \
31 KRATOS_DEBUG_ERROR_IF(Size1 != Size2) \
32 << "Input error in call to DataCommunicator::" << CheckedFunction \
33 << ": The sizes of the local and distributed buffers do not match." << std::endl;
36 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SYNC_SHAPE_INTERFACE_FOR_TYPE
37 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SYNC_SHAPE_INTERFACE_FOR_TYPE(...) \
38 virtual bool SynchronizeShape(__VA_ARGS__&) const { return false; } \
39 virtual bool SynchronizeShape( \
40 const __VA_ARGS__& rSendValue, const int SendDestination, const int SendTag, \
41 __VA_ARGS__& rRecvValue, const int RecvSource, const int RecvTag) const { return false; } \
49 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_REDUCE_INTERFACE_FOR_TYPE
50 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_REDUCE_INTERFACE_FOR_TYPE(...) \
51 virtual __VA_ARGS__ Sum(const __VA_ARGS__& rLocalValue, const int Root) const { return rLocalValue; } \
52 virtual std::vector<__VA_ARGS__> Sum(const std::vector<__VA_ARGS__>& rLocalValues, const int Root) const { \
53 return rLocalValues; \
55 virtual void Sum(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rGlobalValues, const int Root) const { \
56 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rGlobalValues.size(), "Sum"); \
57 rGlobalValues = Sum(rLocalValues, Root); \
59 virtual __VA_ARGS__ Min(const __VA_ARGS__& rLocalValue, const int Root) const { return rLocalValue; } \
60 virtual std::vector<__VA_ARGS__> Min(const std::vector<__VA_ARGS__>& rLocalValues, const int Root) const { \
61 return rLocalValues; \
63 virtual void Min(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rGlobalValues, const int Root) const { \
64 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rGlobalValues.size(), "Min"); \
65 rGlobalValues = Min(rLocalValues, Root); \
67 virtual __VA_ARGS__ Max(const __VA_ARGS__& rLocalValue, const int Root) const { return rLocalValue; } \
68 virtual std::vector<__VA_ARGS__> Max(const std::vector<__VA_ARGS__>& rLocalValues, const int Root) const { \
69 return rLocalValues; \
71 virtual void Max(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rGlobalValues, const int Root) const { \
72 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rGlobalValues.size(), "Max"); \
73 rGlobalValues = Max(rLocalValues, Root); \
82 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_INTERFACE_FOR_TYPE
83 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_INTERFACE_FOR_TYPE(...) \
84 virtual __VA_ARGS__ SumAll(const __VA_ARGS__& rLocalValue) const { return rLocalValue; } \
85 virtual std::vector<__VA_ARGS__> SumAll(const std::vector<__VA_ARGS__>& rLocalValues) const { \
86 return rLocalValues; \
88 virtual void SumAll(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rGlobalValues) const { \
89 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rGlobalValues.size(), "SumAll"); \
90 rGlobalValues = SumAll(rLocalValues); \
92 virtual __VA_ARGS__ MinAll(const __VA_ARGS__& rLocalValue) const { return rLocalValue; } \
93 virtual std::vector<__VA_ARGS__> MinAll(const std::vector<__VA_ARGS__>& rLocalValues) const { \
94 return rLocalValues; \
96 virtual void MinAll(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rGlobalValues) const { \
97 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rGlobalValues.size(), "MinAll"); \
98 rGlobalValues = MinAll(rLocalValues); \
100 virtual __VA_ARGS__ MaxAll(const __VA_ARGS__& rLocalValue) const { return rLocalValue; } \
101 virtual std::vector<__VA_ARGS__> MaxAll(const std::vector<__VA_ARGS__>& rLocalValues) const { \
102 return rLocalValues; \
104 virtual void MaxAll(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rGlobalValues) const { \
105 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rGlobalValues.size(), "MaxAll"); \
106 rGlobalValues = MaxAll(rLocalValues); \
110 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_LOC_INTERFACE_FOR_TYPE
111 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_LOC_INTERFACE_FOR_TYPE(...) \
112 virtual std::pair<__VA_ARGS__, int> MinLocAll(const __VA_ARGS__& rLocalValue) const { return std::pair<__VA_ARGS__, int>(rLocalValue, 0); } \
113 virtual std::pair<__VA_ARGS__, int> MaxLocAll(const __VA_ARGS__& rLocalValue) const { return std::pair<__VA_ARGS__, int>(rLocalValue, 0); }
121 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCANSUM_INTERFACE_FOR_TYPE
122 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCANSUM_INTERFACE_FOR_TYPE(...) \
123 virtual __VA_ARGS__ ScanSum(const __VA_ARGS__& rLocalValue) const { return rLocalValue; } \
124 virtual std::vector<__VA_ARGS__> ScanSum(const std::vector<__VA_ARGS__>& rLocalValues) const { \
125 return rLocalValues; \
127 virtual void ScanSum(const std::vector<__VA_ARGS__>& rLocalValues, std::vector<__VA_ARGS__>& rPartialSums) const { \
128 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rLocalValues.size(), rPartialSums.size(), "ScanSum"); \
129 rPartialSums = ScanSum(rLocalValues); \
140 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SENDRECV_INTERFACE_FOR_TYPE
141 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SENDRECV_INTERFACE_FOR_TYPE(...) \
142 virtual __VA_ARGS__ SendRecvImpl( \
143 const __VA_ARGS__& rSendValues, const int SendDestination, const int SendTag, \
144 const int RecvSource, const int RecvTag) const { \
145 KRATOS_ERROR_IF( (Rank() != SendDestination) || (Rank() != RecvSource)) \
146 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
147 return rSendValues; \
149 virtual std::vector<__VA_ARGS__> SendRecvImpl( \
150 const std::vector<__VA_ARGS__>& rSendValues, const int SendDestination, const int SendTag, \
151 const int RecvSource, const int RecvTag) const { \
152 KRATOS_ERROR_IF( (Rank() != SendDestination) || (Rank() != RecvSource)) \
153 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
154 return rSendValues; \
156 virtual void SendRecvImpl( \
157 const __VA_ARGS__& rSendValues, const int SendDestination, const int SendTag, \
158 __VA_ARGS__& rRecvValues, const int RecvSource, const int RecvTag) const { \
159 rRecvValues = SendRecvImpl(rSendValues, SendDestination, SendTag, RecvSource, RecvTag); \
161 virtual void SendRecvImpl( \
162 const std::vector<__VA_ARGS__>& rSendValues, const int SendDestination, const int SendTag, \
163 std::vector<__VA_ARGS__>& rRecvValues, const int RecvSource, const int RecvTag) const { \
164 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rSendValues.size(), rRecvValues.size(), "SendRecv"); \
165 rRecvValues = SendRecvImpl(rSendValues, SendDestination, SendTag, RecvSource, RecvTag); \
167 virtual void SendImpl( \
168 const __VA_ARGS__& rSendValues, const int SendDestination, const int SendTag = 0) const { \
169 KRATOS_ERROR_IF(Rank() != SendDestination) \
170 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
172 virtual void SendImpl( \
173 const std::vector<__VA_ARGS__>& rSendValues, const int SendDestination, const int SendTag = 0) const { \
174 KRATOS_ERROR_IF(Rank() != SendDestination) \
175 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
177 virtual void RecvImpl(__VA_ARGS__& rRecvValues, const int RecvSource, const int RecvTag = 0) const { \
178 KRATOS_ERROR << "Calling serial DataCommunicator::Recv, which has no meaningful return." << std::endl; \
180 virtual void RecvImpl(std::vector<__VA_ARGS__>& rRecvValues, const int RecvSource, const int RecvTag = 0) const { \
181 KRATOS_ERROR << "Calling serial DataCommunicator::Recv, which has no meaningful return." << std::endl; \
191 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_BROADCAST_INTERFACE_FOR_TYPE
192 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_BROADCAST_INTERFACE_FOR_TYPE(...) \
193 virtual void BroadcastImpl(__VA_ARGS__& rBuffer, const int SourceRank) const {} \
194 virtual void BroadcastImpl(std::vector<__VA_ARGS__>& rBuffer, const int SourceRank) const {} \
204 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCATTER_INTERFACE_FOR_TYPE
205 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCATTER_INTERFACE_FOR_TYPE(...) \
206 virtual std::vector<__VA_ARGS__> Scatter(const std::vector<__VA_ARGS__>& rSendValues, const int SourceRank) const { \
207 KRATOS_ERROR_IF( Rank() != SourceRank ) \
208 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
209 return rSendValues; \
211 virtual void Scatter( \
212 const std::vector<__VA_ARGS__>& rSendValues, std::vector<__VA_ARGS__>& rRecvValues, const int SourceRank) const { \
213 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rSendValues.size(),rRecvValues.size(),"Scatter"); \
214 rRecvValues = Scatter(rSendValues, SourceRank); \
216 virtual std::vector<__VA_ARGS__> Scatterv(const std::vector<std::vector<__VA_ARGS__>>& rSendValues, const int SourceRank) const { \
217 KRATOS_ERROR_IF( Rank() != SourceRank ) \
218 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
219 KRATOS_ERROR_IF( static_cast<unsigned int>(Size()) != rSendValues.size() ) \
220 << "Unexpected number of sends in DataCommuncatior::Scatterv (serial DataCommunicator always assumes a single process)." << std::endl; \
221 return rSendValues[0]; \
223 virtual void Scatterv( \
224 const std::vector<__VA_ARGS__>& rSendValues, const std::vector<int>& rSendCounts, const std::vector<int>& rSendOffsets, \
225 std::vector<__VA_ARGS__>& rRecvValues, const int SourceRank) const { \
226 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvValues.size(), rSendValues.size(), "Scatterv (values check)"); \
227 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rSendCounts.size(), 1, "Scatterv (counts check)"); \
228 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rSendOffsets.size(), 1, "Scatterv (offsets check)"); \
229 KRATOS_ERROR_IF( Rank() != SourceRank ) \
230 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
231 rRecvValues = rSendValues; \
242 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_GATHER_INTERFACE_FOR_TYPE
243 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_GATHER_INTERFACE_FOR_TYPE(...) \
244 virtual std::vector<__VA_ARGS__> Gather(const std::vector<__VA_ARGS__>& rSendValues, const int DestinationRank) const { \
245 KRATOS_ERROR_IF( Rank() != DestinationRank ) \
246 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
247 return rSendValues; \
249 virtual void Gather( \
250 const std::vector<__VA_ARGS__>& rSendValues, std::vector<__VA_ARGS__>& rRecvValues, const int DestinationRank) const { \
251 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rSendValues.size(),rRecvValues.size(),"Gather"); \
252 rRecvValues = Gather(rSendValues, DestinationRank); \
254 virtual std::vector<std::vector<__VA_ARGS__>> Gatherv( \
255 const std::vector<__VA_ARGS__>& rSendValues, const int DestinationRank) const { \
256 KRATOS_ERROR_IF( Rank() != DestinationRank ) \
257 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
258 return std::vector<std::vector<__VA_ARGS__>>{rSendValues}; \
260 virtual void Gatherv( \
261 const std::vector<__VA_ARGS__>& rSendValues, std::vector<__VA_ARGS__>& rRecvValues, \
262 const std::vector<int>& rRecvCounts, const std::vector<int>& rRecvOffsets, const int DestinationRank) const { \
263 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvValues.size(), rSendValues.size(), "Gatherv (values check)"); \
264 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvCounts.size(), 1, "Gatherv (counts check)"); \
265 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvOffsets.size(), 1, "Gatherv (offset check)"); \
266 KRATOS_ERROR_IF( Rank() != DestinationRank ) \
267 << "Communication between different ranks is not possible with a serial DataCommunicator." << std::endl; \
268 rRecvValues = rSendValues; \
270 virtual std::vector<__VA_ARGS__> AllGather(const std::vector<__VA_ARGS__>& rSendValues) const { return rSendValues; } \
271 virtual void AllGather(const std::vector<__VA_ARGS__>& rSendValues, std::vector<__VA_ARGS__>& rRecvValues) const { \
272 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rSendValues.size(),rRecvValues.size(),"AllGather"); \
273 rRecvValues = AllGather(rSendValues); \
275 virtual std::vector<std::vector<__VA_ARGS__>> AllGatherv(const std::vector<__VA_ARGS__>& rSendValues) const { \
276 return std::vector<std::vector<__VA_ARGS__>>{rSendValues}; \
278 virtual void AllGatherv(const std::vector<__VA_ARGS__>& rSendValues, std::vector<__VA_ARGS__>& rRecvValues, \
279 const std::vector<int>& rRecvCounts, const std::vector<int>& rRecvOffsets) const { \
280 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvValues.size(), rSendValues.size(), "AllGatherv (values check)"); \
281 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvCounts.size(), 1, "AllGatherv (counts check)"); \
282 KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(rRecvOffsets.size(), 1, "AllGatherv (offset check)"); \
283 rRecvValues = rSendValues; \
287 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_PUBLIC_INTERFACE_FOR_TYPE
288 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_PUBLIC_INTERFACE_FOR_TYPE(...) \
289 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_REDUCE_INTERFACE_FOR_TYPE(__VA_ARGS__) \
290 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_INTERFACE_FOR_TYPE(__VA_ARGS__) \
291 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCANSUM_INTERFACE_FOR_TYPE(__VA_ARGS__) \
292 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCATTER_INTERFACE_FOR_TYPE(__VA_ARGS__) \
293 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_GATHER_INTERFACE_FOR_TYPE(__VA_ARGS__) \
294 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SYNC_SHAPE_INTERFACE_FOR_TYPE(__VA_ARGS__) \
298 #ifndef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_IMPLEMENTATION_FOR_TYPE
299 #define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_IMPLEMENTATION_FOR_TYPE(...) \
300 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SENDRECV_INTERFACE_FOR_TYPE(__VA_ARGS__) \
301 KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_BROADCAST_INTERFACE_FOR_TYPE(__VA_ARGS__) \
321 template<
typename T>
class serialization_is_required {
324 template<
typename U>
struct serialization_traits {
325 constexpr
static bool is_std_vector =
false;
326 constexpr
static bool value_type_is_compound =
false;
327 constexpr
static bool value_type_is_bool =
false;
330 template<
typename U>
struct serialization_traits<
std::vector<U>> {
331 constexpr
static bool is_std_vector =
true;
332 constexpr
static bool value_type_is_compound = std::is_compound<U>::value;
333 constexpr
static bool value_type_is_bool = std::is_same<U, bool>::value;
336 constexpr
static bool is_vector_of_simple_types = serialization_traits<T>::is_std_vector && !serialization_traits<T>::value_type_is_compound;
337 constexpr
static bool is_vector_of_bools = serialization_traits<T>::is_std_vector && serialization_traits<T>::value_type_is_bool;
339 constexpr
static bool is_vector_of_directly_communicable_type = is_vector_of_simple_types && !is_vector_of_bools;
342 constexpr
static bool value = std::is_compound<T>::value && !is_vector_of_directly_communicable_type;
345 template<
bool value>
struct TypeFromBool {};
347 template<
typename T>
void CheckSerializationForSimpleType(
const T& rSerializedType, TypeFromBool<true>)
const {}
350 KRATOS_DEPRECATED_MESSAGE(
"Calling serialization-based communication for a simple type. Please implement direct communication support for this type.")
351 void CheckSerializationForSimpleType(
const T& rSerializedType, TypeFromBool<false>)
const {}
379 static DataCommunicator::UniquePointer
Create()
381 return Kratos::make_unique<DataCommunicator>();
411 virtual
bool AndReduce(
413 const int Root)
const
421 const int Root)
const
428 const int Root)
const
436 const int Root)
const
472 template<
typename TObject>
473 void Broadcast(TObject& rBroadcastObject,
const int SourceRank)
const
475 this->BroadcastImpl(rBroadcastObject, SourceRank);
491 template<
typename TObject>
493 const TObject& rSendObject,
const int SendDestination,
const int SendTag,
494 const int RecvSource,
const int RecvTag)
const
496 return this->SendRecvImpl(rSendObject, SendDestination, SendTag, RecvSource, RecvTag);
508 template<
class TObject>
510 const TObject& rSendObject,
const int SendDestination,
const int RecvSource)
const
512 return this->SendRecvImpl(rSendObject, SendDestination, 0, RecvSource, 0);
526 template<
class TObject>
528 const TObject& rSendObject,
const int SendDestination,
const int SendTag,
529 TObject& rRecvObject,
const int RecvSource,
const int RecvTag)
const
531 this->SendRecvImpl(rSendObject, SendDestination, SendTag, rRecvObject, RecvSource, RecvTag);
543 template<
class TObject>
545 const TObject& rSendObject,
const int SendDestination, TObject& rRecvObject,
const int RecvSource)
const
547 this->SendRecvImpl(rSendObject, SendDestination, 0, rRecvObject, RecvSource, 0);
558 template<
typename TObject>
559 void Send(
const TObject& rSendValues,
const int SendDestination,
const int SendTag = 0)
const
561 this->SendImpl(rSendValues, SendDestination, SendTag);
572 template<
typename TObject>
573 void Recv(TObject& rRecvObject,
const int RecvSource,
const int RecvTag = 0)
const
575 this->RecvImpl(rRecvObject, RecvSource, RecvTag);
639 const std::vector<int>& rRanks,
640 const std::string& rNewCommunicatorName
653 KRATOS_DEPRECATED_MESSAGE(
"This function is deprecated, please retrieve the DataCommunicator through the ModelPart (or by name in special cases)")
763 virtual std::string
Info()
const
765 std::stringstream buffer;
773 rOStream <<
"DataCommunicator";
780 <<
"Serial do-nothing version of the Kratos wrapper for MPI communication.\n"
781 <<
"Rank 0 of 1 assumed." << std::endl;
808 virtual
void BroadcastImpl(
std::
string& rBuffer,
const int SourceRank)
const {};
815 template<
class TObject>
818 CheckSerializationForSimpleType(rBroadcastObject, TypeFromBool<serialization_is_required<TObject>::value>());
819 if (this->IsDistributed())
821 unsigned int message_size;
822 std::string broadcast_message;
823 int rank = this->Rank();
824 if (rank == SourceRank)
827 send_serializer.
save(
"data", rBroadcastObject);
830 message_size = broadcast_message.size();
833 this->Broadcast(message_size, SourceRank);
835 if (rank != SourceRank)
837 broadcast_message.resize(message_size);
840 this->Broadcast(broadcast_message, SourceRank);
842 if (rank != SourceRank)
845 recv_serializer.
load(
"data", rBroadcastObject);
860 const std::string& rSendValues,
const int SendDestination,
const int SendTag,
861 std::string& rRecvValues,
const int RecvSource,
const int RecvTag)
const
864 rRecvValues = SendRecvImpl(rSendValues, SendDestination, SendTag, RecvSource, RecvTag);
877 const std::string& rSendValues,
const int SendDestination,
const int SendTag,
878 const int RecvSource,
const int RecvTag)
const
880 KRATOS_ERROR_IF( (Rank() != SendDestination) || (Rank() != RecvSource))
881 <<
"Communication between different ranks is not possible with a serial DataCommunicator." << std::endl;
896 const TObject& rSendObject,
897 const int SendDestination,
const int SendTag,
898 const int RecvSource,
const int RecvTag)
const
900 CheckSerializationForSimpleType(rSendObject, TypeFromBool<serialization_is_required<TObject>::value>());
901 if (this->IsDistributed())
904 send_serializer.
save(
"data", rSendObject);
907 std::string recv_message = this->SendRecv(send_message, SendDestination, RecvSource);
911 recv_serializer.
load(
"data", recv_object);
916 KRATOS_ERROR_IF( (Rank() != SendDestination) || (Rank() != RecvSource))
917 <<
"Communication between different ranks is not possible with a serial DataCommunicator." << std::endl;
929 virtual void SendImpl(
const std::string& rSendValues,
const int SendDestination,
const int SendTag)
const
932 <<
"Communication between different ranks is not possible with a serial DataCommunicator." << std::endl;
943 const TObject& rSendObject,
const int SendDestination,
const int SendTag)
const
945 CheckSerializationForSimpleType(rSendObject, TypeFromBool<serialization_is_required<TObject>::value>());
946 if (this->IsDistributed())
949 send_serializer.
save(
"data", rSendObject);
952 this->SendImpl(send_message, SendDestination, SendTag);
957 <<
"Communication between different ranks is not possible with a serial DataCommunicator." << std::endl;
967 virtual void RecvImpl(std::string& rRecvValues,
const int RecvSource,
const int RecvTag = 0)
const
969 KRATOS_ERROR <<
"Calling serial DataCommunicator::Recv, which has no meaningful return." << std::endl;
980 TObject& rRecvObject,
const int RecvSource,
const int RecvTag = 0)
const
982 CheckSerializationForSimpleType(rRecvObject, TypeFromBool<serialization_is_required<TObject>::value>());
983 if (this->IsDistributed())
985 std::string recv_message;
987 this->Recv(recv_message, RecvSource, RecvTag);
990 recv_serializer.
load(
"data", rRecvObject);
995 <<
"Communication between different ranks is not possible with a serial DataCommunicator." << std::endl;
1037 rOStream << std::endl;
1048 #undef KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK
1050 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SYNC_SHAPE_INTERFACE_FOR_TYPE
1051 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_REDUCE_INTERFACE_FOR_TYPE
1052 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_INTERFACE_FOR_TYPE
1053 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCANSUM_INTERFACE_FOR_TYPE
1054 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SENDRECV_INTERFACE_FOR_TYPE
1055 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_BROADCAST_INTERFACE_FOR_TYPE
1056 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_SCATTER_INTERFACE_FOR_TYPE
1057 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_GATHER_INTERFACE_FOR_TYPE
1058 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_PUBLIC_INTERFACE_FOR_TYPE
1059 #undef KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_IMPLEMENTATION_FOR_TYPE
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Base class for all Conditions.
Definition: condition.h:59
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
static DataCommunicator::UniquePointer Create()
Create a new DataCommunicator as a copy of this one.
Definition: data_communicator.h:379
virtual Kratos::Flags AndReduceAll(const Kratos::Flags Values, const Kratos::Flags Mask) const
Definition: data_communicator.h:448
virtual bool AndReduceAll(const bool Value) const
Definition: data_communicator.h:443
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: data_communicator.h:777
virtual bool OrReduceAll(const bool Value) const
Definition: data_communicator.h:453
virtual void RecvImpl(std::string &rRecvValues, const int RecvSource, const int RecvTag=0) const
Receive data from other ranks (string version).
Definition: data_communicator.h:967
virtual bool ErrorIfTrueOnAnyRank(bool Condition) const
This function throws an error on ranks where Condition evaluates to false, if it evaluated to true on...
Definition: data_communicator.h:729
TObject SendRecvImpl(const TObject &rSendObject, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const
Exchange data with other ranks (generic version).
Definition: data_communicator.h:895
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: data_communicator.h:771
virtual bool IsDefinedOnThisRank() const
Check whether this DataCommunicator involves the current rank.
Definition: data_communicator.h:616
virtual void Barrier() const
Pause program execution until all threads reach this call.
Definition: data_communicator.h:386
virtual bool OrReduce(const bool Value, const int Root) const
Definition: data_communicator.h:426
void SendRecv(const TObject &rSendObject, const int SendDestination, TObject &rRecvObject, const int RecvSource) const
Exchange data with other ranks.
Definition: data_communicator.h:544
virtual Kratos::Flags OrReduce(const Kratos::Flags Values, const Kratos::Flags Mask, const int Root) const
Definition: data_communicator.h:433
virtual Kratos::Flags OrReduceAll(const Kratos::Flags Values, const Kratos::Flags Mask) const
Definition: data_communicator.h:458
void RecvImpl(TObject &rRecvObject, const int RecvSource, const int RecvTag=0) const
Exchange data with other ranks (generic version).
Definition: data_communicator.h:979
void SendImpl(const TObject &rSendObject, const int SendDestination, const int SendTag) const
Exchange data with other ranks (generic version).
Definition: data_communicator.h:942
virtual void SendRecvImpl(const std::string &rSendValues, const int SendDestination, const int SendTag, std::string &rRecvValues, const int RecvSource, const int RecvTag) const
Exchange data with other ranks (string version).
Definition: data_communicator.h:859
virtual std::string Info() const
Turn back information as a string.
Definition: data_communicator.h:763
virtual const DataCommunicator & GetSubDataCommunicator(const std::vector< int > &rRanks, const std::string &rNewCommunicatorName) const
Get a sub-data communicator.
Definition: data_communicator.h:638
virtual bool IsNullOnThisRank() const
Check whether this DataCommunicator is MPI_COMM_NULL for the current rank.
Definition: data_communicator.h:626
void Recv(TObject &rRecvObject, const int RecvSource, const int RecvTag=0) const
Exchange data with other ranks.
Definition: data_communicator.h:573
virtual int Size() const
Get the parallel size of this DataCommunicator.
Definition: data_communicator.h:597
DataCommunicator()
Default constructor.
Definition: data_communicator.h:365
void SendRecv(const TObject &rSendObject, const int SendDestination, const int SendTag, TObject &rRecvObject, const int RecvSource, const int RecvTag) const
Exchange data with other ranks.
Definition: data_communicator.h:527
virtual bool BroadcastErrorIfFalse(bool Condition, const int SourceRank) const
This function throws an error on ranks != Sourcerank if Condition evaluates to false.
Definition: data_communicator.h:705
virtual Kratos::Flags AndReduce(const Kratos::Flags Values, const Kratos::Flags Mask, const int Root) const
Definition: data_communicator.h:418
TObject SendRecv(const TObject &rSendObject, const int SendDestination, const int RecvSource) const
Exchange data with other ranks.
Definition: data_communicator.h:509
KRATOS_CLASS_POINTER_DEFINITION(DataCommunicator)
Pointer definition of DataCommunicator.
TObject SendRecv(const TObject &rSendObject, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const
Exchange data with other ranks.
Definition: data_communicator.h:492
virtual void SendImpl(const std::string &rSendValues, const int SendDestination, const int SendTag) const
Send data to other ranks (string version).
Definition: data_communicator.h:929
virtual bool ErrorIfFalseOnAnyRank(bool Condition) const
This function throws an error on ranks where Condition evaluates to true, if it evaluated to false on...
Definition: data_communicator.h:753
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
void Broadcast(TObject &rBroadcastObject, const int SourceRank) const
Synchronize a buffer to the value held by the broadcasting rank.
Definition: data_communicator.h:473
virtual std::string SendRecvImpl(const std::string &rSendValues, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const
Exchange data with other ranks (string version).
Definition: data_communicator.h:876
virtual ~DataCommunicator()
Destructor.
Definition: data_communicator.h:368
void BroadcastImpl(TObject &rBroadcastObject, const int SourceRank) const
Synchronize a buffer to the value held by the broadcasting rank (generic version).
Definition: data_communicator.h:816
void Send(const TObject &rSendValues, const int SendDestination, const int SendTag=0) const
Exchange data with other ranks.
Definition: data_communicator.h:559
virtual bool IsDistributed() const
Check whether this DataCommunicator is aware of parallelism.
Definition: data_communicator.h:606
Definition: mpi_serializer.h:33
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
std::string GetStringRepresentation()
Definition: stream_serializer.h:53
#define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_IMPLEMENTATION_FOR_TYPE(...)
Definition: data_communicator.h:299
#define KRATOS_DATA_COMMUNICATOR_DEBUG_SIZE_CHECK(Size1, Size2, CheckedFunction)
Definition: data_communicator.h:30
#define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_PUBLIC_INTERFACE_FOR_TYPE(...)
Definition: data_communicator.h:288
#define KRATOS_BASE_DATA_COMMUNICATOR_DECLARE_ALLREDUCE_LOC_INTERFACE_FOR_TYPE(...)
Definition: data_communicator.h:111
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
tuple const
Definition: ode_solve.py:403
namespace
Definition: array_1d.h:793