Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 152:7164f59660d4
create .cbc
author | mir3636 |
---|---|
date | Tue, 15 Nov 2016 17:46:29 +0900 |
parents | 63ab65b28466 |
children | 1115367f03a4 |
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; | |
154 } loopCounter; | |
155 struct Worker { | |
156 int num; | |
157 struct Context* contexts; | |
158 } worker; | |
101 | 159 #ifdef USE_CUDA |
98 | 160 struct CudaTask { |
161 CUdevice device; | |
162 CUcontext cuCtx; | |
163 CUfunction code; | |
164 CUdeviceptr* deviceptr; | |
165 CUstream stream; | |
166 } cudatask; | |
101 | 167 #endif |
90 | 168 struct Task { |
169 enum Code code; | |
170 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
171 struct Queue* waitMe; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
172 struct Queue* waitI; |
112 | 173 int idsCount; |
90 | 174 } task; |
175 struct Queue { | |
176 struct Element* first; | |
177 struct Element* last; | |
178 int count; | |
136 | 179 union Data* queue; |
130 | 180 enum Code next; |
90 | 181 } queue; |
132 | 182 // Stack Interface |
130 | 183 struct Stack { |
132 | 184 union Data* stack; |
130 | 185 union Data* data; |
133 | 186 union Data* data1; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
187 enum Code whenEmpty; |
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
188 |
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
189 enum Code clear; |
130 | 190 enum Code push; |
191 enum Code pop; | |
133 | 192 enum Code pop2; |
130 | 193 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
194 enum Code get; |
133 | 195 enum Code get2; |
130 | 196 enum Code next; |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
197 } stack; |
132 | 198 // Stack implementations |
199 struct SingleLinkedStack { | |
200 struct Element* top; | |
135 | 201 } singleLinkedStack; |
132 | 202 struct ArrayStack { |
203 int size; | |
204 int limit; | |
205 struct Element* array; | |
206 } arrayStack; | |
207 // Stack implementation end | |
90 | 208 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
209 union Data* data; |
90 | 210 struct Element* next; |
211 } element; | |
86 | 212 struct Array { |
90 | 213 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
214 int prefix; |
86 | 215 int* array; |
216 } array; | |
217 struct Tree { | |
152 | 218 union Data* tree |
219 enum Code put; | |
220 enum Code get; | |
221 enum Code remove; | |
222 enum Code next; | |
91 | 223 } tree; |
224 struct Traverse { | |
152 | 225 struct Node* root; |
122 | 226 struct Node* current; // reading node of original tree |
138 | 227 struct Node* previous; // parent of reading node of original tree |
124 | 228 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
|
229 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
230 struct Node* grandparent; |
132 | 231 struct Stack* nodeStack; |
86 | 232 int result; |
149 | 233 } Traverse; |
147 | 234 struct RotateTree { |
235 enum Code next; | |
236 struct Traverse* traverse; | |
237 struct Tree* tree; | |
238 } rotateTree; | |
86 | 239 struct Node { |
240 int key; // comparable data segment | |
90 | 241 union Data* value; |
86 | 242 struct Node* left; |
243 struct Node* right; | |
244 // need to balancing | |
245 enum Color { | |
246 Red, | |
247 Black, | |
248 } color; | |
249 } node; | |
250 struct Allocate { | |
251 enum Code next; | |
252 long size; | |
253 } allocate; | |
112 | 254 struct OutPutDataSegments { |
255 union Data **data; | |
256 } ods; | |
86 | 257 }; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
258 |
147 | 259 // typedef struct RotateTree D_RotateTree; |
149 | 260 typedef struct Time Time; |
147 | 261 |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
262 union MetaData { |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
263 struct Queue waitMeTasks; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
264 struct Queue waitI; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
265 }; |
132 | 266 #endif |