Mercurial > hg > Gears > Gears
comparison src/parallel_execution/examples/bitonicSort/bitonicSort.cbc @ 382:f1d111e293c4
Enable Timer for bitonicSort
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 Jul 2017 20:05:08 +0900 |
parents | b81492c74d2b |
children | 300c18700ca5 |
comparison
equal
deleted
inserted
replaced
381:b81492c74d2b | 382:f1d111e293c4 |
---|---|
63 /* print_queue(context->data[ActiveQueue]->queue.first); */ | 63 /* print_queue(context->data[ActiveQueue]->queue.first); */ |
64 /* puts("tree"); */ | 64 /* puts("tree"); */ |
65 /* print_tree(context->data[Tree]->tree.root); */ | 65 /* print_tree(context->data[Tree]->tree.root); */ |
66 /* puts("result"); */ | 66 /* puts("result"); */ |
67 | 67 |
68 time->time = (union Data*)createTimeImpl(context); | 68 goto meta(context, C_createTask1); |
69 time->next = C_createTask1; | |
70 goto meta(context, time->time->Time.start); | |
71 } | 69 } |
72 | 70 |
73 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { | 71 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { |
74 int logN = (int)log2((float)length); | 72 int logN = (int)log2((float)length); |
75 struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, logN*(1+logN)/2 + 2); | 73 struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, logN*(1+logN)/2 + 2); |
76 int taskCount = 0; | 74 int taskCount = 0; |
77 | 75 |
78 struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, SortArray)->SortArray; | 76 struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, SortArray)->SortArray; |
79 struct SortArray* inputSortArray = outputSortArray; | 77 struct SortArray* inputSortArray = outputSortArray; |
80 | 78 struct Time* time = createTimeImpl(context); |
81 // par goto makeArray(outputSortArray, _exit); | 79 |
80 // par goto makeArray(outputSortArray, time, _exit); | |
81 // par goto makeArray(outputSortArray, time, time->start); ? | |
82 struct Context* task = NEW(struct Context); | 82 struct Context* task = NEW(struct Context); |
83 initContext(task); | 83 initContext(task); |
84 task->next = C_makeArray; | 84 task->next = C_makeArray; |
85 task->idgCount = 0; | 85 task->idgCount = 0; |
86 task->idg = task->dataNum; | 86 task->idg = task->dataNum; |
87 task->maxIdg = task->idg; | 87 task->maxIdg = task->idg; |
88 task->odg = task->maxIdg; | 88 task->odg = task->maxIdg; |
89 task->data[task->odg] = (union Data*)outputSortArray; | 89 task->data[task->odg] = (union Data*)outputSortArray; |
90 task->maxOdg = task->odg + 1; | 90 task->data[task->odg+1] = (union Data*)time; |
91 task->maxOdg = task->odg + 2; | |
91 tasks[taskCount] = task; | 92 tasks[taskCount] = task; |
92 | 93 |
93 taskCount++; | 94 taskCount++; |
94 for (int i=2; i <= length; i=2*i) { | 95 for (int i=2; i <= length; i=2*i) { |
95 int first = 1; | 96 int first = 1; |
118 first = 0; | 119 first = 0; |
119 inputSortArray = outputSortArray; | 120 inputSortArray = outputSortArray; |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 // par goto printArray(inputSortArray, __exit) | 124 // par goto printArray(inputSortArray, time, __exit) |
125 // par goto printArray(inputSortArray, time, time->exit)? | |
124 task = NEW(struct Context); | 126 task = NEW(struct Context); |
125 initContext(task); | 127 initContext(task); |
126 task->next = C_printArray; | 128 task->next = C_printArray; |
127 task->idgCount = 1; | 129 task->idgCount = 2; |
128 task->idg = task->dataNum; | 130 task->idg = task->dataNum; |
129 task->data[task->idg] = (union Data*)inputSortArray; | 131 task->data[task->idg] = (union Data*)inputSortArray; |
130 task->maxIdg = task->idg + 1; | 132 task->data[task->idg+1] = (union Data*)time; |
133 task->maxIdg = task->idg + 2; | |
131 task->odg = task->maxIdg; | 134 task->odg = task->maxIdg; |
132 task->maxOdg = task->odg; | 135 task->maxOdg = task->odg; |
133 tasks[taskCount] = task; | 136 tasks[taskCount] = task; |
134 | 137 |
135 taskManager->contexts = tasks; | 138 taskManager->contexts = tasks; |
138 goto meta(context, taskManager->taskManager->TaskManager.spawnTasks); | 141 goto meta(context, taskManager->taskManager->TaskManager.spawnTasks); |
139 //goto meta(context, taskManager->taskManager->TaskManager.shutdown); | 142 //goto meta(context, taskManager->taskManager->TaskManager.shutdown); |
140 } | 143 } |
141 | 144 |
142 __code code2(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { | 145 __code code2(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { |
143 sleep(2); | 146 sleep(30); |
144 taskManager->next = C_exit_code; | 147 taskManager->next = C_exit_code; |
145 goto meta(context, taskManager->taskManager->TaskManager.shutdown); | 148 goto meta(context, taskManager->taskManager->TaskManager.shutdown); |
146 } | 149 } |
147 | 150 |
148 void init(int argc, char** argv) { | 151 void init(int argc, char** argv) { |
165 main_context->next = C_initDataGears; | 168 main_context->next = C_initDataGears; |
166 | 169 |
167 goto start_code(main_context); | 170 goto start_code(main_context); |
168 } | 171 } |
169 | 172 |
170 __code makeArray(__code next(struct SortArray* output, ...)){ | 173 __code makeArray(struct Time* timeInterface, __code next(struct SortArray* output, struct Time* output1, ...)){ |
171 struct SortArray* output = *O_output; | 174 struct SortArray* output = *O_output; |
175 struct Time* output1 = *O_output1; | |
172 if (output->loopCounter == 0){ | 176 if (output->loopCounter == 0){ |
173 output->array = (Integer**)ALLOC_ARRAY(context, Integer, length); | 177 output->array = (Integer**)ALLOC_ARRAY(context, Integer, length); |
174 srand((unsigned) time(NULL)); | 178 srand((unsigned) time(NULL)); |
175 } | 179 } |
176 if (output->loopCounter == GET_SIZE(output->array)){ | 180 if (output->loopCounter == GET_SIZE(output->array)){ |
177 printf("created Array\n"); | 181 printf("created Array\n"); |
178 output->loopCounter = 0; | 182 output->loopCounter = 0; |
179 goto meta(context, next); | 183 timeInterface->time = (union Data*)output1; |
184 timeInterface->next = context->next; | |
185 *O_output = output; | |
186 *O_output1 = output1; | |
187 goto meta(context, output1->start); | |
180 } | 188 } |
181 struct Integer* integer = new Integer(); | 189 struct Integer* integer = new Integer(); |
182 integer->value = rand() % 1000; | 190 integer->value = rand() % 1000; |
183 output->array[output->loopCounter] = integer; | 191 output->array[output->loopCounter] = integer; |
184 printf("%d\n", output->array[output->loopCounter]->value); | 192 //printf("%d\n", output->array[output->loopCounter]->value); |
185 output->loopCounter++; | 193 output->loopCounter++; |
186 *O_output = output; | 194 *O_output = output; |
195 *O_output1 = output1; | |
187 goto meta(context, C_makeArray); | 196 goto meta(context, C_makeArray); |
188 } | 197 } |
189 | 198 |
190 __code makeArray_stub(struct Context* context) { | 199 __code makeArray_stub(struct Context* context) { |
191 SortArray** O_output = (struct SortArray **)&context->data[context->odg]; | 200 SortArray** O_output = (struct SortArray**)&context->data[context->odg]; |
201 Time** O_output1 = (struct Time**)&context->data[context->odg+1]; | |
192 goto makeArray(context, | 202 goto makeArray(context, |
203 Gearef(context, Time), | |
193 context->next, | 204 context->next, |
194 O_output); | 205 O_output, |
195 } | 206 O_output1); |
196 | 207 } |
197 __code printArray(struct SortArray* inputArray, __code next(...)){ | 208 |
209 __code printArray(struct Time* timeInterface, struct SortArray* inputArray, struct Time* inputTime, __code next(...)){ | |
210 timeInterface->time = (union Data*)inputTime; | |
211 timeInterface->next = C_printArray1; | |
212 goto meta(context, inputTime->end); | |
213 } | |
214 | |
215 __code printArray_stub(struct Context* context) { | |
216 goto printArray(context, | |
217 Gearef(context, Time), | |
218 &context->data[context->idg]->SortArray, | |
219 &context->data[context->idg+1]->Time, | |
220 context->next); | |
221 } | |
222 | |
223 __code printArray1(struct SortArray* inputArray, __code next(...)){ | |
198 if (inputArray->loopCounter == GET_SIZE(inputArray->array)){ | 224 if (inputArray->loopCounter == GET_SIZE(inputArray->array)){ |
199 inputArray->loopCounter = 0; | 225 inputArray->loopCounter = 0; |
200 goto meta(context, next); | 226 goto meta(context, next); |
201 } | 227 } |
202 printf("%d\n", inputArray->array[inputArray->loopCounter]->value); | 228 //printf("%d\n", inputArray->array[inputArray->loopCounter]->value); |
203 inputArray->loopCounter++; | 229 inputArray->loopCounter++; |
204 goto meta(context, C_printArray); | 230 goto meta(context, C_printArray1); |
205 } | 231 } |
206 | 232 |
207 __code printArray_stub(struct Context* context) { | 233 __code printArray1_stub(struct Context* context) { |
208 goto printArray(context, | 234 goto printArray1(context, |
209 &context->data[context->idg]->SortArray, | 235 &context->data[context->idg]->SortArray, |
210 context->next); | 236 context->next); |
211 } | 237 } |