Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 169:ea7b11f3e717
Using Queue Interface
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Nov 2016 09:48:37 +0900 |
parents | fa7419e2c67c |
children | ee7134f3bef1 |
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, | |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
93 C_GetTask1, |
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
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, |
112 | 110 SpawnTask, |
92 | 111 Twice, |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
112 StartTime, |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
113 EndTime, |
86 | 114 Exit, |
115 }; | |
116 | |
117 enum Relational { | |
118 EQ, | |
119 GT, | |
120 LT, | |
121 }; | |
122 | |
130 | 123 enum DataType { |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
124 D_Worker, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
125 D_Allocate, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
126 D_SingleLinkedStack, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
127 D_Stack, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
128 D_Tree, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
129 D_Traverse, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
130 D_RotateTree, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
131 D_Node, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
132 D_LoopCounter, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
133 D_Time, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
134 D_Element, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
135 D_ActiveQueue, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
136 D_WaitQueue, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
137 D_Queue |
86 | 138 }; |
139 | |
140 struct Context { | |
141 enum Code next; | |
142 int codeNum; | |
143 __code (**code) (struct Context*); | |
144 void* heapStart; | |
145 void* heap; | |
146 long heapLimit; | |
147 pthread_t thread; | |
92 | 148 int thread_num; |
87 | 149 int dataNum; |
86 | 150 union Data **data; |
151 }; | |
152 | |
153 union Data { | |
133 | 154 struct Meta { |
155 enum DataType type; | |
156 } meta; | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
157 struct Time { |
102 | 158 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
159 double time; |
149 | 160 } Time; |
86 | 161 struct LoopCounter { |
162 int i; | |
166 | 163 struct Tree* tree; |
86 | 164 } loopCounter; |
165 struct Worker { | |
166 int num; | |
167 struct Context* contexts; | |
168 } worker; | |
101 | 169 #ifdef USE_CUDA |
98 | 170 struct CudaTask { |
171 CUdevice device; | |
172 CUcontext cuCtx; | |
173 CUfunction code; | |
174 CUdeviceptr* deviceptr; | |
175 CUstream stream; | |
176 } cudatask; | |
101 | 177 #endif |
90 | 178 struct Task { |
179 enum Code code; | |
180 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
181 struct Queue* waitMe; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
182 struct Queue* waitI; |
112 | 183 int idsCount; |
166 | 184 } Task; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
185 // Queue Interface |
90 | 186 struct Queue { |
136 | 187 union Data* queue; |
167 | 188 union Data* data; |
189 enum Code whenEmpty; | |
190 enum Code clear; | |
191 enum Code put; | |
192 enum Code take; | |
193 enum Code isEmpty; | |
130 | 194 enum Code next; |
166 | 195 } Queue; |
167 | 196 struct SingleLinkedQueue { |
197 struct Element* top; | |
198 struct Element* last; | |
199 enum Code next; | |
200 } SingleLinkedQueue; | |
132 | 201 // Stack Interface |
130 | 202 struct Stack { |
132 | 203 union Data* stack; |
130 | 204 union Data* data; |
133 | 205 union Data* data1; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
206 enum Code whenEmpty; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
207 enum Code clear; |
130 | 208 enum Code push; |
209 enum Code pop; | |
133 | 210 enum Code pop2; |
130 | 211 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
212 enum Code get; |
133 | 213 enum Code get2; |
130 | 214 enum Code next; |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
215 } stack; |
132 | 216 // Stack implementations |
217 struct SingleLinkedStack { | |
218 struct Element* top; | |
135 | 219 } singleLinkedStack; |
132 | 220 struct ArrayStack { |
221 int size; | |
222 int limit; | |
223 struct Element* array; | |
224 } arrayStack; | |
225 // Stack implementation end | |
90 | 226 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
227 union Data* data; |
90 | 228 struct Element* next; |
229 } element; | |
86 | 230 struct Array { |
90 | 231 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
232 int prefix; |
86 | 233 int* array; |
234 } array; | |
235 struct Tree { | |
166 | 236 union Data* tree; |
237 struct Node* node; | |
152 | 238 enum Code put; |
239 enum Code get; | |
240 enum Code remove; | |
241 enum Code next; | |
166 | 242 } Tree; |
91 | 243 struct Traverse { |
152 | 244 struct Node* root; |
122 | 245 struct Node* current; // reading node of original tree |
138 | 246 struct Node* previous; // parent of reading node of original tree |
124 | 247 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
|
248 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
249 struct Node* grandparent; |
132 | 250 struct Stack* nodeStack; |
86 | 251 int result; |
149 | 252 } Traverse; |
147 | 253 struct RotateTree { |
254 enum Code next; | |
255 struct Traverse* traverse; | |
256 struct Tree* tree; | |
257 } rotateTree; | |
86 | 258 struct Node { |
259 int key; // comparable data segment | |
90 | 260 union Data* value; |
86 | 261 struct Node* left; |
262 struct Node* right; | |
263 // need to balancing | |
264 enum Color { | |
265 Red, | |
266 Black, | |
267 } color; | |
268 } node; | |
269 struct Allocate { | |
270 enum Code next; | |
271 long size; | |
272 } allocate; | |
112 | 273 struct OutPutDataSegments { |
274 union Data **data; | |
275 } ods; | |
86 | 276 }; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
277 |
147 | 278 // typedef struct RotateTree D_RotateTree; |
149 | 279 typedef struct Time Time; |
150
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
280 typedef struct LoopCounter LoopCounter; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
281 typedef struct Worker Worker; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
282 typedef struct CudaTask CudaTask; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
283 typedef struct Task Task; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
284 typedef struct Queue Queue; |
167 | 285 typedef struct SingleLinkedQueue SingleLinkedQueue; |
150
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
286 typedef struct Stack Stack; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
287 typedef struct SingleLinkedStack SingleLinkedStack; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
288 typedef struct ArrayStack ArrayStack; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
289 typedef struct Element Element; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
290 typedef struct Array Array; |
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
291 typedef struct Tree Tree; |
151 | 292 typedef struct Traverse Traverse; |
293 typedef struct RotateTree RotateTree; | |
294 typedef struct Node Node; | |
295 typedef struct Allocate Allocate; | |
150
8c687b8fabf2
Add typedef to define Code Gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
296 typedef struct OutputDataSegments OutputDataSegments; |
147 | 297 |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
298 union MetaData { |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
299 struct Queue waitMeTasks; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
300 struct Queue waitI; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
301 }; |
132 | 302 #endif |