-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
184 lines (154 loc) · 4.66 KB
/
main.cpp
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <cryptoTools/Network/IOService.h>
#include "SimpleIndex.h"
#include <iomanip>
#include <libOTe/Tools/LDPC/Util.h>
#include <libOTe_Tests/Common.h>
#include "Paxos.h"
#include "PaxosImpl.h"
#include <libdivide.h>
using namespace oc;
using namespace volePSI;;
using namespace osuCrypto;
using namespace std;
void perfBaxos(oc::CLP& cmd)
{
auto n = cmd.getOr("n", 1ull << cmd.getOr("nn", 10));
auto t = cmd.getOr("t", 1ull);
//auto rand = cmd.isSet("rand");
auto v = cmd.getOr("v", cmd.isSet("v") ? 1 : 0);
auto w = cmd.getOr("w", 3);
auto ssp = cmd.getOr("ssp", 40);
auto dt = cmd.isSet("binary") ? PaxosParam::Binary : PaxosParam::GF128;
auto nt = cmd.getOr("nt", 0);
//PaxosParam pp(n, w, ssp, dt);
auto binSize = 1 << cmd.getOr("lbs", 15);
u64 baxosSize;
{
Baxos paxos;
paxos.init(n, binSize, w, ssp, dt, oc::ZeroBlock);
baxosSize = paxos.size();
}
std::vector<block> key(n), val(n), pax(baxosSize);
PRNG prng(ZeroBlock);
prng.get<block>(key);
prng.get<block>(val);
Timer timer;
auto start = timer.setTimePoint("start");
auto end = start;
for (u64 i = 0; i < t; ++i)
{
Baxos paxos;
paxos.init(n, binSize, w, ssp, dt, block(i, i));
//if (v > 1)
// paxos.setTimer(timer);
paxos.solve<block>(key, val, pax, nullptr, nt);
timer.setTimePoint("s" + std::to_string(i));
paxos.decode<block>(key, val, pax, nt);
end = timer.setTimePoint("d" + std::to_string(i));
}
if (v)
std::cout << timer << std::endl;
auto tt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / double(1000);
std::cout << "total " << tt << "ms, e=" << double(baxosSize) / n << std::endl;
}
void testGen(oc::CLP& cmd)
{
auto n = cmd.getOr("n", 1ull << cmd.getOr("nn", 10));
auto t = cmd.getOr("t", 1ull);
std::vector<block> key(n);
PRNG prng(ZeroBlock);
Timer timer;
auto start = timer.setTimePoint("start");
auto end = start;
for (u64 i = 0; i < t; ++i){
prng.get<block>(key);
end = timer.setTimePoint("d" + std::to_string(i));
}
//std::cout << timer << std::endl;
auto tt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / double(1000);
std::cout << "total " << tt << "ms"<< std::endl;
}
void testAdd(oc::CLP& cmd)
{
auto n = cmd.getOr("n", 1ull << cmd.getOr("nn", 10));
auto t = cmd.getOr("t", 1ull);
std::vector<block> key(n),key1(n);
std::cout << "Size of int: " << sizeof(block) << " bytes" << std::endl;
PRNG prng(ZeroBlock);
prng.get<block>(key);
prng.get<block>(key1);
Timer timer;
auto start = timer.setTimePoint("start");
auto end = start;
for (u64 i = 0; i < t; ++i){
for (u64 j = 0; i < n; ++i){
key[j] = key[j]+key1[j];
}
end = timer.setTimePoint("d" + std::to_string(i));
}
//std::cout << timer << std::endl;
auto tt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / double(1000);
std::cout << "total " << tt << "ms"<< std::endl;
}
template<typename T>
void perfPaxosImpl(oc::CLP& cmd)
{
auto n = cmd.getOr("n", 1ull << cmd.getOr("nn", 10));
u64 maxN = std::numeric_limits<T>::max() - 1;
auto t = cmd.getOr("t", 1ull);
//auto rand = cmd.isSet("rand");
auto v = cmd.getOr("v", cmd.isSet("v") ? 1 : 0);
auto w = cmd.getOr("w", 3);
auto ssp = cmd.getOr("ssp", 40);
auto dt = cmd.isSet("binary") ? PaxosParam::Binary : PaxosParam::GF128;
auto cols = cmd.getOr("cols", 0);
PaxosParam pp(n, w, ssp, dt);
//std::cout << "e=" << pp.size() / double(n) << std::endl;
if (maxN < pp.size())
{
std::cout << "n must be smaller than the index type max value. " LOCATION << std::endl;
throw RTE_LOC;
}
auto m = cols ? cols : 1;
std::vector<block> key(n);
oc::Matrix<block> val(n, m), pax(pp.size(), m);
PRNG prng(ZeroBlock);
prng.get<block>(key);
prng.get<block>(val);
Timer timer;
auto start = timer.setTimePoint("start");
auto end = start;
for (u64 i = 0; i < t; ++i)
{
Paxos<T> paxos;
paxos.init(n, pp, block(i, i));
if (v > 1)
paxos.setTimer(timer);
if (cols)
{
paxos.setInput(key);
paxos.template encode<block>(val, pax);
timer.setTimePoint("s" + std::to_string(i));
paxos.template decode<block>(key, val, pax);
}
else
{
paxos.template solve<block>(key, oc::span<block>(val), oc::span<block>(pax));
timer.setTimePoint("s" + std::to_string(i));
paxos.template decode<block>(key, oc::span<block>(val), oc::span<block>(pax));
}
end = timer.setTimePoint("d" + std::to_string(i));
}
if (v)
std::cout << timer << std::endl;
auto tt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / double(1000);
std::cout << "total " << tt << "ms" << std::endl;
}
int main(int argc, char** argv){
CLP cmd;
cmd.parse(argc, argv);
//perfBaxos(cmd);
//testGen(cmd);
testAdd(cmd);
return 0;
}