-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvoLTSim.cpp
196 lines (159 loc) · 4.38 KB
/
ConvoLTSim.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
185
186
187
188
189
190
191
192
193
194
195
196
/*
* ConvoLTSim.cpp
* new_LT
*
* Created by 刁培倫 on 2011/5/25.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include "ConvoCode.h"
#include "LTCode.h"
#include "randomc.h"
#include <ctime>
#include <cmath>
#include <map>
//#define L 100000
#define MAX_BIT 1000000000ULL
#define BASE 1.08
#define STEPS 1
#define Delta 0.01
#include <omp.h>
using namespace CodeSim;
using namespace std;
int main(int argn, char **args){
if (argn < 4) {
cerr << "Usage: ConvoLTSim.out convo_code_file LT_file interleaver_file" << endl;
exit(-1);
}
int start_time = time(0);
// string puncher_table = "1";
//
//
// if (argn > 3) {
// puncher_table = args[3];
// }
CRandomMersenne r(time(0));
ConvoCode cc( args[1] );
int Layer = cc.getK();
unsigned long L = 80000*6/7/Layer;
unsigned long Run = MAX_BIT / L;
ifstream ifsLT(args[2]);
if(ifsLT.fail()){
cerr << "Error: file \""+string(args[2])+"\" does not exist." << endl;
exit(-1);
}
int K, MaxN, Dsize, *Tags;
double *Distribution;
ifsLT >> K >> Dsize;
Tags = new int[Dsize];
Distribution = new double[Dsize];
for (int i=0; i<Dsize; i++) {
ifsLT >> Tags[i];
}
for (int i=0; i<Dsize; i++) {
ifsLT >> Distribution[i];
}
Permutator<Bit> inter(args[3], true);
cout << "ConvoCode file: \"" << args[1] <<"\" LT file: " << args[2] << "\" interleaver file: " << args[3] << '"' << endl;
cout << "Epsilon";
for (int i=0; i<Layer; i++) {
cout << "\tLayer" << i+1;
}
cout << "\tTotalBits\tLT\tLT_total\tRun\n";
for (int s=0; s<STEPS; s++) {
vector<unsigned long> total_err(Layer, 0);
unsigned long total=0, LT_total = 0, LT_total_err = 0;
double Epsilon = (BASE+s*Delta) -1;
vector<vector<bool> > histo_mask(Layer, vector<bool>(L+1,0)), LT_histo_mask(1, vector<bool>(L+1,0));
vector<map<unsigned long, unsigned long> > histo(Layer, map<unsigned long, unsigned long>()), LT_histo(1, map<unsigned long, unsigned long>());
// for (int i=0; i<Layer; i++) {
// err[i]=0;
// }
//while (1)
{
#pragma omp parallel for schedule(dynamic) num_threads(6)
for (int i=0; i<Run; i++) {
vector<unsigned long> err(Layer, 0);
unsigned long LT_err = 0;
Codeword<Bit> a;
a.reserve(Layer*L);
for (int t=0; t<Layer*L; t++) {
a.push_back(r.IRandomX(0, 1));
}
Codeword<Bit> b = cc.encode(a);
b = inter.permutate(b);
Codeword<Byte> b1 = BitToByteCoverter::convert(b);
if(s == 0 && i==0)
cout << "LT block:" << b1.size() << endl;
LT_sim<Byte> lt(b1.size(), b1.size()*(1+Epsilon), Dsize, Tags, Distribution, r.BRandom());
Codeword<Byte> c1 = lt.encode(b1);
c1 = lt.decode(c1);
for (int i=0; i<c1.size(); i++) {
if(c1[i].isErased()) {
LT_err++;
}
}
#pragma omp atomic
LT_total_err+= LT_err;
#pragma omp atomic
LT_total += c1.size();
#pragma omp critical
{
if(LT_histo_mask[0][LT_err]){
LT_histo[0][LT_err] ++;
}
else {
LT_histo[0][LT_err] = 1;
LT_histo_mask[0][LT_err] =1;
}
}
if (LT_err > 0)
{
Codeword<Bit> c2 = BitToByteCoverter::revert(c1);
c2 = inter.depermutate(c2);
Codeword<Bit> c = cc.decode(c2);
for (int i=0; i<c.size(); i++) {
if (!(a[i] == c[i])) {
//#pragma omp atomic
err[i%Layer]++;
}
}
}
#pragma omp atomic
total += L;
for (int i=0; i<Layer; i++) {
#pragma omp atomic
total_err[i]+=err[i];
}
#pragma omp critical
for (int i=0; i<Layer; i++) {
if(histo_mask[i][err[i]]){
histo[i][err[i]] ++;
}
else {
histo[i][err[i]] = 1;
histo_mask[i][err[i]] =1;
}
}
}
}
// enough # of errors
cout << Epsilon;
for (int i=0; i<Layer; i++) {
cout << '\t' << total_err[i];
}
cout << '\t' << total << '\t' << LT_total_err << '\t' << LT_total << '\t' << Run << endl;
for (int i=0; i<Layer; i++) {
cout << "Layer " << i +1 << " histogram:\n";
for (map<unsigned long, unsigned long>::iterator it = histo[i].begin(); it!=histo[i].end(); it++) {
cout << it->first << '\t' << it->second << '\n';
}
}
cout << endl;
cout << "Lt histogram:\n";
for (map<unsigned long, unsigned long>::iterator it = LT_histo[0].begin(); it!=LT_histo[0].end(); it++) {
cout << it->first << '\t' << it->second << '\n';
}
}
cout << "Time: " << time(0)-start_time << endl;
}