Mercurial > hg > GearsTemplate
comparison src/parallel_execution/main.c @ 232:123b0d277b84
worker interface
author | mir3636 |
---|---|
date | Sun, 22 Jan 2017 19:02:12 +0900 |
parents | 6c0692c9bfed |
children | 865179a0a56d |
comparison
equal
deleted
inserted
replaced
231:24da4f217447 | 232:123b0d277b84 |
---|---|
49 /* print_queue(context->data[ActiveQueue]->queue.first); */ | 49 /* print_queue(context->data[ActiveQueue]->queue.first); */ |
50 /* puts("tree"); */ | 50 /* puts("tree"); */ |
51 /* print_tree(context->data[Tree]->tree.root); */ | 51 /* print_tree(context->data[Tree]->tree.root); */ |
52 /* puts("result"); */ | 52 /* puts("result"); */ |
53 | 53 |
54 time->next = C_createWorker1; | 54 time->next = C_code2; |
55 goto meta(context, C_start_time); | 55 goto meta(context, C_start_time); |
56 } | 56 } |
57 | 57 |
58 __code code1_stub(struct Context* context) { | 58 __code code1_stub(struct Context* context) { |
59 goto code1(context, Gearef(context, Time)); | 59 goto code1(context, Gearef(context, Time)); |
138 Gearef(context, LoopCounter), | 138 Gearef(context, LoopCounter), |
139 Gearef(context, TaskManager), | 139 Gearef(context, TaskManager), |
140 task); | 140 task); |
141 } | 141 } |
142 | 142 |
143 __code createWorker1(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { | |
144 int i = loopCounter->i; | |
145 | |
146 if (i < worker->id) { | |
147 struct Context* worker_context = &worker->contexts[i]; | |
148 worker_context->next = C_getTask1; | |
149 worker_context->data[D_Tree] = context->data[D_Tree]; | |
150 // worker_context->data[D_ActiveQueue] = context->data[D_ActiveQueue]; | |
151 pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); | |
152 worker_context->thread_num = i; | |
153 loopCounter->i++; | |
154 | |
155 goto meta(context, C_createWorker1); | |
156 } | |
157 | |
158 loopCounter->i = 0; | |
159 goto meta(context, C_taskManager); | |
160 } | |
161 | |
162 __code createWorker1_stub(struct Context* context) { | |
163 goto createWorker1(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker); | |
164 } | |
165 | |
166 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { | 143 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { |
167 int i = loopCounter->i; | |
168 | |
169 if (i < worker->id) { | |
170 pthread_join(worker->contexts[i].thread, NULL); | |
171 loopCounter->i++; | |
172 | |
173 goto meta(context, C_taskManager); | |
174 } | |
175 | |
176 loopCounter->i = 0; | 144 loopCounter->i = 0; |
177 | 145 |
178 Time *t = &context->data[D_Time]->Time; | 146 Time *t = &context->data[D_Time]->Time; |
179 t->next = C_code2; | 147 t->next = C_code2; |
180 goto meta(context, C_end_time); | 148 goto meta(context, C_end_time); |
208 initContext(main_context); | 176 initContext(main_context); |
209 main_context->next = C_initDataGears; | 177 main_context->next = C_initDataGears; |
210 | 178 |
211 struct Context* worker_contexts = NEWN(cpu_num, struct Context); | 179 struct Context* worker_contexts = NEWN(cpu_num, struct Context); |
212 | 180 |
213 struct Worker* worker = &main_context->data[D_Worker]->Worker; | |
214 worker->id = cpu_num; | |
215 worker->contexts = worker_contexts; | |
216 | |
217 for (int i = 0;i<cpu_num;i++) | 181 for (int i = 0;i<cpu_num;i++) |
218 initContext(&worker_contexts[i]); | 182 initContext(&worker_contexts[i]); |
219 | 183 |
220 goto start_code(main_context); | 184 goto start_code(main_context); |
221 } | 185 } |