Mercurial > hg > Members > innparusu > Gears
comparison src/parallel_execution/main.c @ 109:059b26a250cc
Change put_queue process
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 May 2016 20:02:09 +0900 |
parents | 64c98838a291 |
children | 556e203de999 |
comparison
equal
deleted
inserted
replaced
107:67f68f9c04b6 | 109:059b26a250cc |
---|---|
117 | 117 |
118 __code createTask1_stub(struct Context* context) { | 118 __code createTask1_stub(struct Context* context) { |
119 goto createTask1(context, &context->data[Allocate]->allocate); | 119 goto createTask1(context, &context->data[Allocate]->allocate); |
120 } | 120 } |
121 | 121 |
122 __code createTask2(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element) { | 122 __code meta_createTask2(struct Context* context, struct Queue* activeQueue, enum Code next) { |
123 int i = loopCounter->i; | 123 context->data[Queue] = (union Data *)activeQueue; |
124 | 124 goto (context->code[next])(context); |
125 } | |
126 | |
127 __code createTask2(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element, struct Queue* activeQueue) { | |
128 int i = loopCounter->i; | |
129 | |
125 task->code = Twice; | 130 task->code = Twice; |
126 task->key = i; | 131 task->key = i; |
127 | 132 |
128 element->task = task; | 133 element->task = task; |
129 | 134 |
130 context->next = CreateData1; | 135 context->next = CreateData1; |
131 loopCounter->i++; | 136 loopCounter->i++; |
132 | 137 |
133 goto meta(context, PutQueue1); | 138 goto meta_createTask2(context, activeQueue, PutQueue1); |
134 } | 139 } |
135 | 140 |
136 __code createTask2_stub(struct Context* context) { | 141 __code createTask2_stub(struct Context* context) { |
137 goto createTask2(context, | 142 goto createTask2(context, |
138 &context->data[LoopCounter]->loopCounter, | 143 &context->data[LoopCounter]->loopCounter, |
139 &context->data[context->dataNum]->task, | 144 &context->data[context->dataNum]->task, |
140 &context->data[Element]->element); | 145 &context->data[Element]->element, |
146 &context->data[ActiveQueue]->queue); | |
141 } | 147 } |
142 | 148 |
143 __code putQueue1(struct Context* context, struct Allocate* allocate) { | 149 __code putQueue1(struct Context* context, struct Allocate* allocate) { |
144 allocate->size = sizeof(struct Element); | 150 allocate->size = sizeof(struct Element); |
145 allocator(context); | 151 allocator(context); |
160 goto meta(context, PutQueue4); | 166 goto meta(context, PutQueue4); |
161 } | 167 } |
162 | 168 |
163 __code putQueue2_stub(struct Context* context) { | 169 __code putQueue2_stub(struct Context* context) { |
164 goto putQueue2(context, | 170 goto putQueue2(context, |
165 &context->data[context->dataNum]->element, | 171 &context->data[context->dataNum]->element, |
166 &context->data[Element]->element, | 172 &context->data[Element]->element, |
167 &context->data[ActiveQueue]->queue); | 173 &context->data[Queue]->queue); |
168 } | 174 } |
169 | 175 |
170 __code putQueue3(struct Context* context, struct Queue* queue, struct Element* new_element) { | 176 __code putQueue3(struct Context* context, struct Queue* queue, struct Element* new_element) { |
171 struct Element* last = queue->last; | 177 struct Element* last = queue->last; |
172 | 178 |
173 if (__sync_bool_compare_and_swap(&queue->last, last, new_element)) { | 179 if (__sync_bool_compare_and_swap(&queue->last, last, new_element)) { |
174 last->next = new_element; | 180 last->next = new_element; |
175 queue->count++; | 181 queue->count++; |
176 | 182 |
177 goto meta(context, context->next); | 183 goto meta(context, context->next); |
178 } else { | 184 } else { |
179 goto meta(context, PutQueue3); | 185 goto meta(context, PutQueue3); |
180 } | 186 } |
181 } | 187 } |
182 | 188 |
183 __code putQueue3_stub(struct Context* context) { | 189 __code putQueue3_stub(struct Context* context) { |
184 goto putQueue3(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); | 190 goto putQueue3(context, &context->data[Queue]->queue, &context->data[context->dataNum]->element); |
185 } | 191 } |
186 | 192 |
187 __code putQueue4(struct Context* context, struct Queue* queue, struct Element* new_element) { | 193 __code putQueue4(struct Context* context, struct Queue* queue, struct Element* new_element) { |
188 if (__sync_bool_compare_and_swap(&queue->first, 0, new_element)) { | 194 if (__sync_bool_compare_and_swap(&queue->first, 0, new_element)) { |
189 queue->last = new_element; | 195 queue->last = new_element; |
190 queue->count++; | 196 queue->count++; |
191 | 197 |
192 goto meta(context, context->next); | 198 goto meta(context, context->next); |
193 } else { | 199 } else { |
194 goto meta(context, PutQueue3); | 200 goto meta(context, PutQueue3); |
195 } | 201 } |
196 } | 202 } |
197 | 203 |
198 __code putQueue4_stub(struct Context* context) { | 204 __code putQueue4_stub(struct Context* context) { |
199 goto putQueue4(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); | 205 goto putQueue4(context, &context->data[Queue]->queue, &context->data[context->dataNum]->element); |
200 } | 206 } |
201 | 207 |
202 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { | 208 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { |
203 int i = loopCounter->i; | 209 int i = loopCounter->i; |
204 | 210 |
215 } | 221 } |
216 | 222 |
217 loopCounter->i = 0; | 223 loopCounter->i = 0; |
218 goto meta(context, TaskManager); | 224 goto meta(context, TaskManager); |
219 } | 225 } |
220 | 226 |
221 __code createWorker_stub(struct Context* context) { | 227 __code createWorker_stub(struct Context* context) { |
222 goto createWorker(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker); | 228 goto createWorker(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker); |
223 } | 229 } |
224 | 230 |
225 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { | 231 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { |
236 | 242 |
237 struct Time *t = &context->data[Time]->time; | 243 struct Time *t = &context->data[Time]->time; |
238 t->next = Code2; | 244 t->next = Code2; |
239 goto meta(context, EndTime); | 245 goto meta(context, EndTime); |
240 } | 246 } |
241 | 247 |
242 __code taskManager_stub(struct Context* context) { | 248 __code taskManager_stub(struct Context* context) { |
243 goto taskManager(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker); | 249 goto taskManager(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker); |
244 } | 250 } |
245 | 251 |
246 void init(int argc, char** argv) { | 252 void init(int argc, char** argv) { |
251 length = (int)atoi(argv[i+1]); | 257 length = (int)atoi(argv[i+1]); |
252 else if (strcmp(argv[i], "-s") == 0) | 258 else if (strcmp(argv[i], "-s") == 0) |
253 split = (int)atoi(argv[i+1]); | 259 split = (int)atoi(argv[i+1]); |
254 } | 260 } |
255 } | 261 } |
256 | 262 |
257 | 263 |
258 int main(int argc, char** argv) { | 264 int main(int argc, char** argv) { |
259 init(argc, argv); | 265 init(argc, argv); |
260 | 266 |
261 array_ptr = NEWN(length, int); | 267 array_ptr = NEWN(length, int); |
266 struct Context* main_context = NEW(struct Context); | 272 struct Context* main_context = NEW(struct Context); |
267 initContext(main_context); | 273 initContext(main_context); |
268 main_context->next = CreateData1; | 274 main_context->next = CreateData1; |
269 | 275 |
270 struct Context* worker_contexts = NEWN(cpu_num, struct Context); | 276 struct Context* worker_contexts = NEWN(cpu_num, struct Context); |
271 | 277 |
272 struct Worker* worker = &main_context->data[Worker]->worker; | 278 struct Worker* worker = &main_context->data[Worker]->worker; |
273 worker->num = cpu_num; | 279 worker->num = cpu_num; |
274 worker->contexts = worker_contexts; | 280 worker->contexts = worker_contexts; |
275 | 281 |
276 for (int i = 0;i<cpu_num;i++) | 282 for (int i = 0;i<cpu_num;i++) |
277 initContext(&worker_contexts[i]); | 283 initContext(&worker_contexts[i]); |
278 | 284 |
279 goto start_code(main_context); | 285 goto start_code(main_context); |
280 } | 286 } |