Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 170:ee7134f3bef1
Fix
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Nov 2016 10:36:45 +0900 |
parents | ea7b11f3e717 |
children | 747067fe46bd |
rev | line source |
---|---|
86 | 1 /* Context definition for llrb example */ |
132 | 2 #ifndef CONTEXT_H |
3 #define CONTEXT_H | |
86 | 4 #include <pthread.h> |
101 | 5 #ifdef USE_CUDA |
98 | 6 #include <cuda.h> |
101 | 7 #endif |
86 | 8 |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
9 #define ALLOCATE_SIZE 20000000 |
101 | 10 #define NEW(type) (type*)(calloc(1, sizeof(type))) |
11 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | |
12 | |
133 | 13 #define ALLOC_DATA(context, dseg) ({\ |
14 struct Meta* meta = (struct Meta*)context->heap;\ | |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
15 meta->type = D_##dseg;\ |
133 | 16 context->heap += sizeof(struct Meta);\ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
17 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) |
101 | 18 |
133 | 19 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ |
20 struct Meta* meta = (struct Meta*)context->heap;\ | |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
21 meta->type = D_##t;\ |
133 | 22 context->heap += sizeof(struct Meta);\ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
23 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; }) |
86 | 24 |
132 | 25 #define ALLOCATE(context, t) ({ \ |
133 | 26 struct Meta* meta = (struct Meta*)context->heap;\ |
27 context->heap += sizeof(struct Meta);\ | |
28 union Data* data = context->heap; \ | |
29 context->heap += sizeof(struct t); \ | |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
30 meta->type = D_##t; \ |
133 | 31 data; }) |
132 | 32 |
133 | 33 #define GET_TYPE(dseg) ({ \ |
34 struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\ | |
35 meta->type; }) | |
132 | 36 |
149 | 37 #define Gearef(context, t) (&(context)->data[D_##t]->t) |
86 | 38 enum Code { |
144 | 39 C_code1, |
40 C_code2, | |
41 C_code3, | |
42 C_code4, | |
43 C_code5, | |
44 C_find, | |
86 | 45 Not_find, |
46 Code6, | |
47 Allocator, | |
144 | 48 C_put, |
49 C_replaceNode, | |
50 C_replaceNode1, | |
51 C_insertNode, | |
86 | 52 Compare, |
144 | 53 C_rotateLeft, |
54 C_rotateLeft1, | |
55 C_rotateRight, | |
56 C_rotateRight1, | |
86 | 57 SetTree, |
144 | 58 C_insertCase1, |
59 C_insertCase2, | |
60 C_insertCase3, | |
61 C_insertCase4, | |
62 C_insertCase5, | |
63 C_insertCase51, | |
64 C_stackClear, | |
65 C_get, | |
66 C_search, | |
86 | 67 Delete, |
68 Delete1, | |
69 Delete2, | |
70 Delete3, | |
71 Replace_d1, | |
72 Replace_d2, | |
73 FindMax1, | |
74 FindMax2, | |
75 DeleteCase1, | |
76 DeleteCase2, | |
77 DeleteCase3, | |
78 DeleteCase4, | |
79 DeleteCase5, | |
80 DeleteCase6, | |
81 CreateWorker, | |
82 TaskManager, | |
90 | 83 CreateData1, |
84 CreateData2, | |
85 CreateTask1, | |
86 CreateTask2, | |
112 | 87 CreateTask3, |
88 CreateTask4, | |
90 | 89 PutQueue1, |
90 PutQueue2, | |
91 PutQueue3, | |
92 PutQueue4, | |
170 | 93 C_getTask1, |
94 C_getTask2, | |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
95 C_clearSingleLinkedStack, |
144 | 96 C_pushSingleLinkedStack, |
97 C_popSingleLinkedStack, | |
98 C_pop2SingleLinkedStack, | |
99 C_getSingleLinkedStack, | |
100 C_get2SingleLinkedStack, | |
101 C_isEmptySingleLinkedStack, | |
168
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
102 C_takeSingleLinkedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
103 C_putSingleLinkedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
104 C_isEmptySingleLinkedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
105 C_clearSingleLinkedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
106 C_takeSynchronizedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
107 C_putSynchronizedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
108 C_isEmptySynchronizedQueue, |
fa7419e2c67c
Add synchornizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
109 C_clearSynchronizedQueue, |
170 | 110 C_putRedBlackTree, |
111 C_getRedBlackTree, | |
112 C_removeRedBlackTree, | |
113 C_clearRedBlackTree, | |
112 | 114 SpawnTask, |
92 | 115 Twice, |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
116 StartTime, |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
117 EndTime, |
86 | 118 Exit, |
119 }; | |
120 | |
121 enum Relational { | |
122 EQ, | |
123 GT, | |
124 LT, | |
125 }; | |
126 | |
130 | 127 enum DataType { |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
128 D_Worker, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
129 D_Allocate, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
130 D_SingleLinkedStack, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
131 D_Stack, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
132 D_Tree, |
170 | 133 D_Task, |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
134 D_Traverse, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
135 D_RotateTree, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
136 D_Node, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
137 D_LoopCounter, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
138 D_Time, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
139 D_Element, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
140 D_ActiveQueue, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
141 D_WaitQueue, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
142 D_Queue |
86 | 143 }; |
144 | |
145 struct Context { | |
146 enum Code next; | |
147 int codeNum; | |
148 __code (**code) (struct Context*); | |
149 void* heapStart; | |
150 void* heap; | |
151 long heapLimit; | |
152 pthread_t thread; | |
92 | 153 int thread_num; |
87 | 154 int dataNum; |
86 | 155 union Data **data; |
156 }; | |
157 | |
158 union Data { | |
133 | 159 struct Meta { |
160 enum DataType type; | |
161 } meta; | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
162 struct Time { |
102 | 163 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
164 double time; |
149 | 165 } Time; |
86 | 166 struct LoopCounter { |
167 int i; | |
166 | 168 struct Tree* tree; |
86 | 169 } loopCounter; |
170 struct Worker { | |
171 int num; | |
172 struct Context* contexts; | |
173 } worker; | |
101 | 174 #ifdef USE_CUDA |
98 | 175 struct CudaTask { |
176 CUdevice device; | |
177 CUcontext cuCtx; | |
178 CUfunction code; | |
179 CUdeviceptr* deviceptr; | |
180 CUstream stream; | |
181 } cudatask; | |
101 | 182 #endif |
90 | 183 struct Task { |
184 enum Code code; | |
185 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
186 struct Queue* waitMe; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
187 struct Queue* waitI; |
112 | 188 int idsCount; |
166 | 189 } Task; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
190 // Queue Interface |
90 | 191 struct Queue { |
136 | 192 union Data* queue; |
167 | 193 union Data* data; |
194 enum Code whenEmpty; | |
195 enum Code clear; | |
196 enum Code put; | |
197 enum Code take; | |
198 enum Code isEmpty; | |
130 | 199 enum Code next; |
166 | 200 } Queue; |
167 | 201 struct SingleLinkedQueue { |
202 struct Element* top; | |
203 struct Element* last; | |
204 enum Code next; | |
205 } SingleLinkedQueue; | |
132 | 206 // Stack Interface |
130 | 207 struct Stack { |
132 | 208 union Data* stack; |
130 | 209 union Data* data; |
133 | 210 union Data* data1; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
211 enum Code whenEmpty; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
212 enum Code clear; |
130 | 213 enum Code push; |
214 enum Code pop; | |
133 | 215 enum Code pop2; |
130 | 216 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
217 enum Code get; |
133 | 218 enum Code get2; |
130 | 219 enum Code next; |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
220 } stack; |
132 | 221 // Stack implementations |
222 struct SingleLinkedStack { | |
223 struct Element* top; | |
135 | 224 } singleLinkedStack; |
132 | 225 struct ArrayStack { |
226 int size; | |
227 int limit; | |
228 struct Element* array; | |
229 } arrayStack; | |
230 // Stack implementation end | |
90 | 231 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
232 union Data* data; |
90 | 233 struct Element* next; |
234 } element; | |
86 | 235 struct Array { |
90 | 236 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
237 int prefix; |
86 | 238 int* array; |
239 } array; | |
240 struct Tree { | |
166 | 241 union Data* tree; |
242 struct Node* node; | |
152 | 243 enum Code put; |
244 enum Code get; | |
245 enum Code remove; | |
246 enum Code next; | |
166 | 247 } Tree; |
91 | 248 struct Traverse { |
152 | 249 struct Node* root; |
122 | 250 struct Node* current; // reading node of original tree |
138 | 251 struct Node* previous; // parent of reading node of original tree |
124 | 252 struct Node* newNode; // writing node of new tree |
143
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
253 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
254 struct Node* grandparent; |
132 | 255 struct Stack* nodeStack; |
86 | 256 int result; |
149 | 257 } Traverse; |
147 | 258 struct RotateTree { |
259 enum Code next; | |
260 struct Traverse* traverse; | |
261 struct Tree* tree; | |
262 } rotateTree; | |
86 | 263 struct Node { |
264 int key; // comparable data segment | |
90 | 265 union Data* value; |
86 | 266 struct Node* left; |
267 struct Node* right; | |
268 // need to balancing | |
269 enum Color { | |
270 Red, | |
271 Black, | |
272 } color; | |
273 } node; | |
274 struct Allocate { | |
275 enum Code next; | |
276 long size; | |
277 } allocate; | |
112 | 278 struct OutPutDataSegments { |
279 union Data **data; | |
280 } ods; | |
86 | 281 }; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
282 |
147 | 283 // typedef struct RotateTree D_RotateTree; |
149 | 284 typedef struct Time Time; |
150
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
285 typedef struct LoopCounter LoopCounter; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
286 typedef struct Worker Worker; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
287 typedef struct CudaTask CudaTask; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
288 typedef struct Task Task; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
289 typedef struct Queue Queue; |
167 | 290 typedef struct SingleLinkedQueue SingleLinkedQueue; |
150
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
291 typedef struct Stack Stack; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
292 typedef struct SingleLinkedStack SingleLinkedStack; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
293 typedef struct ArrayStack ArrayStack; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
294 typedef struct Element Element; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
295 typedef struct Array Array; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
296 typedef struct Tree Tree; |
151 | 297 typedef struct Traverse Traverse; |
298 typedef struct RotateTree RotateTree; | |
299 typedef struct Node Node; | |
300 typedef struct Allocate Allocate; | |
150
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
301 typedef struct OutputDataSegments OutputDataSegments; |
147 | 302 |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
303 union MetaData { |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
304 struct Queue waitMeTasks; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
305 struct Queue waitI; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
306 }; |
132 | 307 #endif |