helpful progress reporting
[IRC.git] / Robust / src / Benchmarks / Scheduling / FilterBank / FilterBank.java
1 task t1(StartupObject s{initialstate}) {
2         //System.printString("task t1\n");
3
4         int N_sim=1200;
5         int N_samp=8;
6         int N_ch=16;
7         int N_col=256;
8         int i,j;
9
10         float r[] = new float[N_sim];
11         for (i=0;i<N_sim;i++) {
12                 r[i]=i+1;
13         }
14         
15         for(j = 0; j < N_ch; j++) {
16                 FilterBankAtom fba = new FilterBankAtom(j, N_ch, N_col, N_sim, N_samp, r/*, H, F*/){tosamp};
17         }
18         FilterBank fb = new FilterBank(N_sim, N_ch){!finish};
19
20         taskexit(s{!initialstate});
21 }
22
23 task t2(FilterBankAtom fba{tosamp}) {
24         //System.printString("task t2\n");
25         
26         fba.init();
27         fba.FBCore();
28
29         taskexit(fba{!tosamp, tomerge});
30 }
31
32 task t3(FilterBank fb{!finish}, FilterBankAtom fba{tomerge}) {
33         //System.printString("task t3\n");
34
35         boolean finish = fb.merge(fba.vF);
36
37         if(finish) {
38                 taskexit(fb{finish, print}, fba{!tomerge});
39         } else {
40                 taskexit(fba{!tomerge});
41         }
42 }
43
44 task t4(FilterBank fb{print}) {
45         //System.printString("task t4\n");
46
47         fb.print();
48
49         taskexit(fb{!print});
50 }
51
52 public class FilterBank {
53         flag finish;
54         flag print;
55         
56         int N_sim;
57         float[] y;
58         int counter;
59
60         public FilterBank(int snum, int cnum) {
61                 this.N_sim = snum;
62                 this.y = new float[N_sim];
63                 for(int i=0; i < N_sim; i++) {
64                         y[i]=0;
65                 }
66                 counter = cnum;
67         }
68
69         public boolean merge(float[] result) {
70                 for(int i = 0; i < this.N_sim; i++) {
71                         this.y[i] += result[i];
72                 }
73                 this.counter--;
74
75                 return this.counter == 0;
76         }
77
78         public void print() {
79                 /*for(int i = 0; i < this.N_sim; i++) {
80                         //System.printI((int)this.y[i]);
81                 }*/
82         }
83 }
84
85 public class FilterBankAtom {
86
87         flag tosamp;
88         flag tomerge;
89
90         int ch_index;
91         int N_ch;
92         int N_col;
93         int N_sim;
94         int N_samp;
95         float[] r;
96         float[] H;
97         float[] F;
98         float[] vH;
99         float[] vDn;
100         float[] vUp;
101         public float[] vF;
102
103         public FilterBankAtom(int cindex, int N_ch, int N_col, int N_sim, int N_samp, float[] r/*, float[] H, float[] F*/) {
104             this.ch_index = cindex;
105             this.N_ch = N_ch;
106             this.N_col = N_col;
107             this.N_sim = N_sim;
108             this.N_samp = N_samp;
109             this.r = r;
110             //this.H = null;
111             //this.F = null;
112             this.vH = new float[this.N_sim];
113             this.vDn = new float[(int) this.N_sim/this.N_samp];
114             this.vUp = new float[this.N_sim];
115             this.vF = new float[this.N_sim];
116             /*this.H[] = new float[N_col];
117             this.F[] = new float[N_col];
118             for(int i = 0; i < N_col; i++) {
119                 H[i]=i*N_col+j*N_ch+j+i+j+1;
120                 F[i]=i*j+j*j+j+i;
121             }*/
122         }
123         
124         public void init() {
125             int j = this.ch_index;
126             this.H = new float[this.N_col];
127             this.F = new float[this.N_col];
128             for(int i = 0; i < this.N_col; i++) {
129                 this.H[i]=i*this.N_col+j*this.N_ch+j+i+j+1;
130                 this.F[i]=i*j+j*j+j+i;
131             }
132         }
133
134         public void FBCore() {
135                 int j,k;
136
137                 //convolving H
138                 for (j=0; j< N_sim; j++) {
139                         this.vH[j]=0;
140                         for (k=0; ((k<this.N_col) && ((j-k)>=0)); k++) {
141                                 this.vH[j]+=this.H[k]*this.r[j-k];
142                         }
143                 }
144
145                 //Down Samplin
146                 for (j=0; j < this.N_sim/this.N_samp; j++) {
147                         this.vDn[j]=this.vH[j*this.N_samp];
148                 }
149
150                 //Up Sampling
151                 for (j=0; j < this.N_sim; j++) {
152                         this.vUp[j]=0;
153                 }
154                 for (j=0; j < this.N_sim/this.N_samp; j++) {
155                         this.vUp[j*this.N_samp]=this.vDn[j];
156                 }
157
158                 //convolving F
159                 for (j=0; j< this.N_sim; j++) {
160                         this.vF[j]=0;
161                         for (k=0; ((k<this.N_col) && ((j-k)>=0)); k++) {
162                                 this.vF[j]+=this.F[k]*this.vUp[j-k];
163                         }
164                 }
165         }
166 }