-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuperstepTester2.cpp
More file actions
151 lines (106 loc) · 3.87 KB
/
Copy pathsuperstepTester2.cpp
File metadata and controls
151 lines (106 loc) · 3.87 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <superstep.hpp>
#include <bsp.hpp>
#include <random>
#include <mutex>
#define TISKIN_PRINT_V(lbl, vec, footer) {\
std::unique_lock<std::mutex> lock (outputMutex);\
std::cout << lbl << std::flush;\
for (auto el : vec)\
std::cout << el << " " << std::flush;\
std::cout << std::endl << footer;\
}
using IntVector = std::vector<int>;
using IntCommunicationProtocol = Superstep<int>::CommunicationProtocols;
std::mutex outputMutex;
void setupBsp (BSP<int> &sTester, IntVector &input, std::vector<IntVector> &bspInputs, std::vector<IntVector> &bspOutputs) {
std::random_device randomDevice;
{
UTimer randomVector ("Creating random vector");
int idx = 0;
std::iota (input.begin(), input.end(), idx++);
}
{
UTimer bspInputVectors ("Creating BSP input vectors");
bspInputs = std::vector<IntVector> (4);
bspOutputs = std::vector<IntVector> (4);
uint actInputLen = 5;
for (uint i=0; i<4; i++) {
bspInputs[i] = IntVector (actInputLen);
auto &vI = bspInputs[i];
for (uint j=0; j<actInputLen; j++) {
vI[j] = input[(actInputLen*i)+j];
}
}
}
UTimer superstepCreator ("Creating supersteps");
// ============================================================
// ============================================================
// Superstep 0
BSP<int>::SuperstepPointer s0 = BSP<int>::SuperstepPointer (new Superstep<int> ());
for (uint i= 0; i<4; i++) {
s0->addActivity (
[] (uint activityIndex, IntVector &actInput) {
TISKIN_PRINT_V ("Input vector of activity " << activityIndex << ": ", actInput, "");
},
[] (uint activityIndex, IntVector &elements) {
//TISKIN_PRINT_V ("Input vector of activity " << activityIndex << ": ", actInput, "");
IntCommunicationProtocol cp (5);
for (auto el: elements) {
cp[activityIndex].push_back (el);
cp[activityIndex+1].push_back (el);
}
TISKIN_PRINT_V ("Output vector from " << activityIndex << " to " << activityIndex << ": ", cp[activityIndex], "");
TISKIN_PRINT_V ("Output vector from " << activityIndex << " to " << activityIndex+1 << ": ", cp[activityIndex+1], "");
return cp;
}
);
}
sTester.addSuperstep (std::move(s0));
// ============================================================
// ============================================================
// Superstep 1
BSP<int>::SuperstepPointer s1 = BSP<int>::SuperstepPointer (new Superstep<int> ());
for (uint i= 0; i<5; i++) {
s1->addActivity (
[] (uint activityIndex, IntVector &actInput) {
TISKIN_PRINT_V ("Input vector of activity " << activityIndex << ": ", actInput, "");
},
([] (uint activityIndex, IntVector &elements) {
//TISKIN_PRINT_V ("Input vector of activity " << activityIndex << ": ", actInput, "");
std::vector<IntVector> cp (1);
for (auto el: elements) {
cp[0].push_back (el);
}
return cp;
})
);
}
sTester.addSuperstep (std::move(s1));
// ============================================================
// ============================================================
// Superstep 2
BSP<int>::SuperstepPointer s2 = BSP<int>::SuperstepPointer (new Superstep<int> ());
s2->addActivity (
[] (uint activityIndex, IntVector &actInput) {
TISKIN_PRINT_V ("Input vector of activity " << activityIndex << ": ", actInput, "");
std::cout << "Len: " << actInput.size() << std::endl;
},
([] (uint activityIndex, IntVector &elements) {
std::vector<IntVector> cp (1);
for (auto e : elements)
cp[0].push_back (e);
return cp;
})
);
sTester.addSuperstep (std::move(s2));
}
int main (int argn, char **argv) {
IntVector input (20);
std::vector<IntVector> bspInputs, bspOutputs;
BSP<int> bspPattern;
setupBsp (std::ref(bspPattern), input, bspInputs, bspOutputs);
bspPattern.runAndWait (bspInputs, bspOutputs, false);
std::cout << std::endl << std::endl << bspOutputs.size () << std::endl;
std::cout << "\nBye bye!\n";
return 0;
}