Mercurial > hg > GearsTemplate
annotate src/parallel_execution/main.cbc @ 277:9d671e63df74
generate extern
author | mir3636 |
---|---|
date | Thu, 02 Feb 2017 18:29:50 +0900 |
parents | src/parallel_execution/main.c@cd3486e4ba70 |
children | 23767f714f4a |
rev | line source |
---|---|
86 | 1 #include <stdio.h> |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
2 #include <string.h> |
132 | 3 #include <stdlib.h> |
86 | 4 |
5 #include "context.h" | |
6 #include "origin_cs.h" | |
7 | |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
8 extern union Data* createRedBlackTree(struct Context* context); |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
9 extern union Data* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO); |
90 | 10 extern void allocator(struct Context* context); |
86 | 11 |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
12 int cpu_num = 1; |
116 | 13 int length = 102400; |
14 int split = 8; | |
90 | 15 int* array_ptr; |
16 | |
17 void print_queue(struct Element* element) { | |
18 while (element) { | |
185 | 19 printf("%p\n", ((struct Task *)(element->data))); |
90 | 20 element = element->next; |
21 } | |
22 } | |
23 | |
24 void print_tree(struct Node* node) { | |
25 if (node != 0) { | |
196 | 26 printf("%d\n", node->value->Array.index); |
90 | 27 print_tree(node->left); |
28 print_tree(node->right); | |
29 } | |
30 } | |
86 | 31 |
220 | 32 __code initDataGears(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) { |
33 loopCounter->tree = &createRedBlackTree(context)->Tree; | |
34 loopCounter->i = 0; | |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
35 taskManager->taskManager = (union Data*)&createTaskManager(context, cpu_num, 0, 0)->TaskManager; |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
36 goto meta(context, C_createTask1); |
220 | 37 } |
38 | |
39 __code initDataGears_stub(struct Context* context) { | |
40 goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); | |
41 } | |
42 | |
43 __code code1(struct Context* context, struct Time* time) { | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
44 printf("cpus:\t\t%d\n", cpu_num); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
45 printf("length:\t\t%d\n", length); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
46 printf("length/task:\t%d\n", length/split); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
47 /* puts("queue"); */ |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
48 /* print_queue(context->data[ActiveQueue]->queue.first); */ |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
49 /* puts("tree"); */ |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
50 /* print_tree(context->data[Tree]->tree.root); */ |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
51 /* puts("result"); */ |
90 | 52 |
232 | 53 time->next = C_code2; |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
54 goto meta(context, C_exit_code); |
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
55 //goto meta(context, C_start_time); |
86 | 56 } |
57 | |
58 __code code1_stub(struct Context* context) { | |
220 | 59 goto code1(context, Gearef(context, Time)); |
86 | 60 } |
61 | |
92 | 62 __code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) { |
63 int i = loopCounter->i; | |
111 | 64 |
92 | 65 if (i < length) { |
114 | 66 //printf("%d\n", array->array[i]); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
67 if (array->array[i] == (i*2)) { |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
68 loopCounter->i++; |
144 | 69 goto meta(context, C_code2); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
70 } else |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
71 puts("wrong result"); |
92 | 72 |
73 } | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
74 |
186 | 75 goto meta(context, C_code2); |
92 | 76 } |
77 | |
78 __code code2_stub(struct Context* context) { | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
211
diff
changeset
|
79 goto code2(context, &context->data[D_Node]->Node.value->Array, &context->data[D_LoopCounter]->LoopCounter); |
92 | 80 } |
81 | |
90 | 82 __code createData1(struct Context* context, struct Allocate* allocate, struct LoopCounter* loopCounter) { |
83 int i = loopCounter->i; | |
84 | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
85 if ((length/split*i) < length) { |
186 | 86 goto meta(context, C_createData2); |
90 | 87 } |
88 | |
92 | 89 loopCounter->i = 0; |
144 | 90 goto meta(context, C_code1); |
90 | 91 } |
111 | 92 |
90 | 93 __code createData1_stub(struct Context* context) { |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
94 goto createData1(context, Gearef(context, Allocate), Gearef(context, LoopCounter)); |
90 | 95 } |
96 | |
160 | 97 __code createData2(struct Context* context, struct LoopCounter* loopCounter, struct Array* array, struct Node* node, Tree* tree) { |
90 | 98 int i = loopCounter->i; |
99 | |
100 array->index = i; | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
101 array->prefix = length/split; |
90 | 102 array->array = array_ptr; |
103 | |
104 node->key = i; | |
105 node->value = (union Data*)array; | |
220 | 106 |
107 tree->tree = (union Data*)loopCounter->tree; | |
111 | 108 |
186 | 109 tree->next = C_createTask1; |
160 | 110 tree->node = node; |
90 | 111 |
160 | 112 goto meta(context, loopCounter->tree->put); |
90 | 113 } |
114 | |
115 __code createData2_stub(struct Context* context) { | |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
116 Array* array = &ALLOCATE(context, Array)->Array; |
90 | 117 goto createData2(context, |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
118 Gearef(context, LoopCounter), |
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
119 array, |
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
120 Gearef(context, Node), |
160 | 121 Gearef(context, Tree)); |
112 | 122 } |
123 | |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
124 __code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) { |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
125 int i = loopCounter->i; |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
126 |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
127 if ((length/split*i) < length) { |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
128 taskManager->next = C_createTask2; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
129 goto meta(context, taskManager->taskManager->TaskManager.createTask); |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
130 } |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
131 |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
132 loopCounter->i = 0; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
133 goto meta(context, C_code1); |
90 | 134 } |
135 | |
160 | 136 __code createTask1_stub(struct Context* context) { |
137 goto createTask1(context, | |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
138 Gearef(context, LoopCounter), |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
139 Gearef(context, TaskManager)); |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
140 } |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
141 |
257 | 142 __code createTask2(struct Context* context, LoopCounter* loopCounter, TaskManager* taskManager,struct Context* task, Array* array) { |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
143 int i = loopCounter->i; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
144 |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
145 if ((length/split*i) < length) { |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
146 array->index = i; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
147 array->prefix = length/split; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
148 array->array = array_ptr; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
149 task->idgCount = 0; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
150 task->next = C_twice; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
151 // task->data[task->idg] = (union Data*)array; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
152 taskManager->next = C_createTask1; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
153 loopCounter->i++; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
154 |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
155 goto meta(context, taskManager->taskManager->TaskManager.spawn); |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
156 } |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
157 loopCounter->i = 0; |
248
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
158 taskManager->next = C_code1; |
1ede5390cda2
Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
159 goto meta(context, taskManager->taskManager->TaskManager.shutdown); |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
160 } |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
161 |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
162 __code createTask2_stub(struct Context* context) { |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
163 Array* array = &ALLOCATE(context, Array)->Array; |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
164 goto createTask2(context, |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
165 Gearef(context, LoopCounter), |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
166 Gearef(context, TaskManager), |
247
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
167 Gearef(context, TaskManager)->context, |
ce262b2c1daf
Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
246
diff
changeset
|
168 array); |
90 | 169 } |
170 | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
171 void init(int argc, char** argv) { |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
172 for (int i = 1; argv[i]; ++i) { |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
173 if (strcmp(argv[i], "-cpu") == 0) |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
174 cpu_num = (int)atoi(argv[i+1]); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
175 else if (strcmp(argv[i], "-l") == 0) |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
176 length = (int)atoi(argv[i+1]); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
177 else if (strcmp(argv[i], "-s") == 0) |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
178 split = (int)atoi(argv[i+1]); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
179 } |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
180 } |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
181 |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
182 |
86 | 183 int main(int argc, char** argv) { |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
184 init(argc, argv); |
90 | 185 |
101 | 186 array_ptr = NEWN(length, int); |
90 | 187 |
188 for(int i=0; i<length; i++) | |
189 array_ptr[i]=i; | |
86 | 190 |
101 | 191 struct Context* main_context = NEW(struct Context); |
86 | 192 initContext(main_context); |
220 | 193 main_context->next = C_initDataGears; |
86 | 194 |
195 goto start_code(main_context); | |
196 } | |
186 | 197 |