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