forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadMaster.hpp
113 lines (85 loc) · 2.16 KB
/
ThreadMaster.hpp
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
/*
* ThreadMaster.cpp
*
*/
#ifndef GC_THREADMASTER_HPP_
#define GC_THREADMASTER_HPP_
#include "ThreadMaster.h"
#include "Program.h"
#include "instructions.h"
#include "Tools/benchmarking.h"
#include "Machine.hpp"
namespace GC
{
template<class T>
ThreadMaster<T>* ThreadMaster<T>::singleton = 0;
template<class T>
ThreadMaster<T>& ThreadMaster<T>::s()
{
if (singleton)
return *singleton;
else
throw no_singleton("no singleton, maybe threads not supported");
}
template<class T>
ThreadMaster<T>::ThreadMaster(OnlineOptions& opts) :
P(0), opts(opts)
{
if (singleton)
throw runtime_error("there can only be one");
singleton = this;
}
template<class T>
void ThreadMaster<T>::run_tape(int thread_number, int tape_number, int arg)
{
threads.at(thread_number)->tape_schedule.push({tape_number, arg});
}
template<class T>
void ThreadMaster<T>::join_tape(int thread_number)
{
threads.at(thread_number)->join_tape();
}
template<class T>
Thread<T>* ThreadMaster<T>::new_thread(int i)
{
return new Thread<T>(i, *this);
}
template<class T>
void ThreadMaster<T>::run()
{
if (not opts.live_prep)
{
insecure("preprocessing from file in binary virtual machines");
}
P = new PlainPlayer(N, "main");
machine.load_schedule(progname);
for (int i = 0; i < machine.nthreads; i++)
threads.push_back(new_thread(i));
for (auto thread : threads)
thread->join_tape();
Timer timer;
timer.start();
threads[0]->tape_schedule.push(0);
for (auto thread : threads)
thread->finish();
// synchronize
vector<octetStream> os(P->num_players());
P->Broadcast_Receive(os);
post_run();
NamedCommStats stats = P->total_comm();
ExecutionStats exe_stats;
for (auto thread : threads)
{
stats += thread->P->total_comm();
exe_stats += thread->processor.stats;
delete thread;
}
exe_stats.print();
stats.print();
cerr << "Time = " << timer.elapsed() << " seconds" << endl;
cerr << "Data sent = " << stats.sent * 1e-6 << " MB" << endl;
machine.print_global_comm(*P, stats);
delete P;
}
} /* namespace GC */
#endif