7#include <gtest/gtest.h>
9#include "arccore/message_passing_mpi/StandaloneMpiMessagePassingMng.h"
11#include "arccore/base/BFloat16.h"
12#include "arccore/base/Float16.h"
13#include "arccore/common/Array.h"
14#include "arccore/trace/ITraceMng.h"
16#include "arccore/message_passing/Communicator.h"
17#include "arccore/serialize/ISerializer.h"
25using namespace Arccore::MessagePassing::Mpi;
30TEST(MessagePassingMpi, Simple)
34 tm->
info() <<
"Rank=" << pm->commRank() <<
"\n";
35 if (pm->commSize() == 2) {
37 if (pm->commRank() == 0)
38 mpSend(pm.get(), send_buf, 1);
42 ASSERT_EQ(receive_buf.size(), 3);
43 ASSERT_EQ(receive_buf[0], 1);
44 ASSERT_EQ(receive_buf[1], 7);
45 ASSERT_EQ(receive_buf[2], -4);
51 std::cout <<
"Communicator=" << comm <<
"\n";
57TEST(MessagePassingMpi, SerializeGather)
62 ASSERT_EQ(pm->commSize(), 3);
63 Int32 my_rank = pm->commRank();
71 send_serializer->setMode(ISerializer::ModeReserve);
72 send_serializer->reserveArray(send_buf[my_rank]);
73 send_serializer->allocateBuffer();
75 send_serializer->putArray(send_buf[my_rank]);
78 mpAllGather(pm.get(), send_serializer.get(), receive_serializer.get());
81 receive_serializer->getArray(receive_buf[0]);
82 receive_serializer->getArray(receive_buf[1]);
83 receive_serializer->getArray(receive_buf[2]);
87 ASSERT_EQ(send_buf[0], receive_buf[0]);
88 ASSERT_EQ(send_buf[1], receive_buf[1]);
89 ASSERT_EQ(send_buf[2], receive_buf[2]);
98template <
typename DataType>
112 ASSERT_EQ(send_buf, receive_buf);
118 DataType expected_sum(0.0f);
119 for (Int32 i = 0; i < nb_rank; ++i) {
120 values[i] = (
static_cast<float>(i) - 1.2f) * 3.4f;
121 expected_sum = expected_sum + values[i];
123 DataType expected_min = values[0];
124 DataType expected_max = values[nb_rank - 1];
125 DataType my_value(values[my_rank]);
127 tm->
info() <<
"Sum=" << sum_result;
128 ASSERT_EQ(expected_sum, sum_result);
131 tm->
info() <<
"Max=" << max_result;
132 ASSERT_EQ(expected_max, max_result);
135 tm->
info() <<
"Min=" << min_result;
136 ASSERT_EQ(expected_min, min_result);
142TEST(MessagePassingMpi,
Float16)
147 _doTestFloat16<Float16>(pm.get());
148 _doTestFloat16<BFloat16>(pm.get());
#define ASSERT_TRUE(condition)
Checks that condition is true.
Brief list of message exchange functions.
Management of references to a C++ class.
Integer size() const
Number of elements in the vector.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual TraceMessage info()=0
Stream for an information message.
Communicator for message exchange.
Interface of the message passing manager.
virtual ITraceMng * traceMng() const =0
Trace manager associated to this instance.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual Int32 commSize() const =0
Number of instances in the communicator.
Reference to an instance.
1D data vector with value semantics (STL style).
@ ReduceSum
Sum of values.
@ ReduceMin
Minimum of values.
@ ReduceMax
Maximum of values.
Namespace containing the types and declarations that manage the message-passing parallelism mechanism...
C char mpAllReduce(IMessagePassingMng *pm, eReduceType rt, char v)
void mpAllGather(IMessagePassingMng *pm, const ISerializer *send_serializer, ISerializer *recv_serializer)
allGather() message for serialization
Request mpReceive(IMessagePassingMng *pm, ISerializer *values, const PointToPointMessageInfo &message)
Receive message using an ISerializer.
Request mpSend(IMessagePassingMng *pm, const ISerializer *values, const PointToPointMessageInfo &message)
Send message using an ISerializer.
Arcane::Float16 Float16
Type 'Float16' (binary16).
ARCCORE_SERIALIZE_EXPORT Ref< ISerializer > createSerializer()
Creates an instance of ISerializer.