Repository navigation
Expand file tree
/
Copy pathtest_pingpong.cpp
More file actions
103 lines (102 loc) · 3.97 KB
/
Copy pathtest_pingpong.cpp
File metadata and controls
103 lines (102 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <cstdlib>
#include <array>
#include "redev.h"
int main(int argc, char** argv) {
int rank, nproc;
MPI_Init(&argc, &argv);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <1=isRendezvousApp,0=isParticipant>\n";
exit(EXIT_FAILURE);
}
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
auto isRdv = atoi(argv[1]);
fprintf(stderr, "rank %d isRdv %d\n", rank, isRdv);
if(nproc != 1) {
std::cerr << "There must be exactly 1 rendezvous and 1 non-rendezvous processes for this test.\n";
exit(EXIT_FAILURE);
}
{
//dummy partition vector data
const auto dim = 1;
auto ranks = isRdv ? redev::LOs({0}) : redev::LOs(1);
auto cuts = isRdv ? redev::Reals({0}) : redev::Reals(1);
auto ptn = redev::RCBPtn(dim,ranks,cuts);
redev::Redev rdv(MPI_COMM_WORLD,redev::Partition{std::move(ptn)},static_cast<redev::ProcessType>(isRdv));
std::string name = "foo";
adios2::Params params{ {"Streaming", "On"}, {"OpenTimeoutSecs", "2"}};
auto channel = rdv.CreateAdiosChannel(name, params,
redev::TransportType::BP4);
auto commPair = channel.CreateComm<redev::LO>(name, MPI_COMM_WORLD);
auto secondField = channel.CreateComm<redev::LO>("bar", MPI_COMM_WORLD);
redev::LOs receiveBuffer;
std::array<redev::LO, 2> secondBuffer{};
const redev::LO* receiveStorage = nullptr;
for(int iter=0; iter<3; iter++) {
// the non-rendezvous app sends to the rendezvous app
if(!isRdv) {
if(iter==0) {
redev::LOs dest = redev::LOs{0};
redev::LOs offsets = redev::LOs{0,1};
commPair.SetOutMessageLayout(dest, offsets);
redev::LOs secondOffsets{0, 2};
secondField.SetOutMessageLayout(dest, secondOffsets);
}
redev::LOs msgs(1, 42 + iter);
redev::LOs secondMsgs{100 + iter, 200 + iter};
channel.SendPhase([&]() {
commPair.Send(msgs.data());
secondField.Send(secondMsgs.data());
});
} else {
// Resolve both layouts before queuing either deferred payload read.
channel.ReceivePhase([&]() {
receiveBuffer.resize(commPair.GetReceiveCount());
REDEV_ALWAYS_ASSERT(secondField.GetReceiveCount() == secondBuffer.size());
commPair.Recv(receiveBuffer.data(), receiveBuffer.size(), redev::Mode::Deferred);
secondField.Recv(secondBuffer.data(), secondBuffer.size(), redev::Mode::Deferred);
});
if(iter == 0) {
auto inMsg = commPair.GetInMessageLayout();
REDEV_ALWAYS_ASSERT(inMsg.offset == redev::GOs({0,1}));
REDEV_ALWAYS_ASSERT(inMsg.srcRanks == redev::GOs({0}));
REDEV_ALWAYS_ASSERT(inMsg.start == 0);
REDEV_ALWAYS_ASSERT(inMsg.count == 1);
receiveStorage = receiveBuffer.data();
}
REDEV_ALWAYS_ASSERT(receiveBuffer.size() == 1);
REDEV_ALWAYS_ASSERT(receiveBuffer.data() == receiveStorage);
REDEV_ALWAYS_ASSERT(receiveBuffer[0] == 42 + iter);
REDEV_ALWAYS_ASSERT(secondBuffer[0] == 100 + iter);
REDEV_ALWAYS_ASSERT(secondBuffer[1] == 200 + iter);
}
// the rendezvous app sends to the non-rendezvous app
if(isRdv) {
if(iter==0) {
redev::LOs dest = redev::LOs{0};
redev::LOs offsets = redev::LOs{0,1};
commPair.SetOutMessageLayout(dest, offsets);
}
redev::LOs msgs = redev::LOs(1,1337);
channel.BeginSendCommunicationPhase();
commPair.Send(msgs.data());
channel.EndSendCommunicationPhase();
} else {
channel.BeginReceiveCommunicationPhase();
auto msgs = commPair.Recv();
channel.EndReceiveCommunicationPhase();
if(iter==0) {
auto inMsg = commPair.GetInMessageLayout();
REDEV_ALWAYS_ASSERT(inMsg.offset == redev::GOs({0,1}));
REDEV_ALWAYS_ASSERT(inMsg.srcRanks == redev::GOs({0}));
REDEV_ALWAYS_ASSERT(inMsg.start == 0);
REDEV_ALWAYS_ASSERT(inMsg.count == 1);
}
REDEV_ALWAYS_ASSERT(msgs[0] == 1337);
}
}
}
MPI_Finalize();
return 0;
}