-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathch-frb-simulate-l0.cpp
71 lines (53 loc) · 1.76 KB
/
ch-frb-simulate-l0.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
#include <cassert>
#include <thread>
#include <ch_frb_io.hpp>
#include <ch_frb_io_internals.hpp>
#include "ch_frb_l1.hpp"
#include "simulate-l0.hpp"
using namespace std;
using namespace ch_frb_l1;
using ch_frb_io::lexical_cast;
static void usage()
{
cerr << "Usage: ch-frb-simulate-l0 <l0_params.yaml> <num_seconds OR target_gbps if msgpack files given> [msgpack-chunk-files ...]\n";
exit(2);
}
void sim_thread_main(shared_ptr<l0_params> l0, int istream, double num_seconds) {
l0->send_noise(istream, num_seconds);
}
void chunk_files_thread_main(shared_ptr<l0_params> l0, int istream,
vector<string> datafiles) {
l0->send_chunk_files(istream, datafiles);
}
int main(int argc, char **argv)
{
if (argc < 3)
usage();
string filename = argv[1];
double num_seconds = lexical_cast<double> (argv[2]);
double gbps = 0.0;
vector<string> datafiles;
for (int a=3; a<argc; a++) {
datafiles.push_back(string(argv[a]));
}
if (datafiles.size())
gbps = num_seconds;
else
if (num_seconds <= 0.0)
usage();
shared_ptr<l0_params> p = make_shared<l0_params>(filename, gbps);
p->write(cout);
int nthreads = p->nthreads_tot;
vector<std::thread> threads(nthreads);
if (datafiles.size() == 0) {
for (int ithread = 0; ithread < p->nthreads_tot; ithread++)
threads[ithread] = std::thread(sim_thread_main, p, ithread, num_seconds);
} else {
for (int ithread = 0; ithread < p->nthreads_tot; ithread++)
threads[ithread] = std::thread(chunk_files_thread_main, p, ithread, datafiles);
}
for (int ithread = 0; ithread < p->nthreads_tot; ithread++)
threads[ithread].join();
p->end_streams();
return 0;
}