Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 133:568730b1239e
call stack interface in rb_tree
author | mir3636 |
---|---|
date | Mon, 07 Nov 2016 21:12:19 +0900 |
parents | 7c309e1aea73 |
children | 2eccf4564efe |
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;\ | |
15 meta->type = dseg;\ | |
16 context->heap += sizeof(struct Meta);\ | |
17 context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; }) | |
101 | 18 |
133 | 19 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ |
20 struct Meta* meta = (struct Meta*)context->heap;\ | |
21 meta->type = t;\ | |
22 context->heap += sizeof(struct Meta);\ | |
23 context->data[dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[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); \ | |
30 meta->type = t; \ | |
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 |
86 | 37 enum Code { |
38 Code1, | |
39 Code2, | |
40 Code3, | |
41 Code4, | |
42 Code5, | |
43 Find, | |
44 Not_find, | |
45 Code6, | |
46 Allocator, | |
90 | 47 PutTree, |
86 | 48 Replace, |
124 | 49 Replace1, |
86 | 50 Insert, |
51 Compare, | |
52 RotateL, | |
53 RotateR, | |
54 SetTree, | |
55 InsertCase1, | |
56 InsertCase2, | |
57 InsertCase3, | |
124 | 58 InsertCase31, |
86 | 59 InsertCase4, |
124 | 60 InsertCase4_01, |
61 InsertCase4_02, | |
86 | 62 InsertCase4_1, |
63 InsertCase4_2, | |
64 InsertCase5, | |
65 StackClear, | |
66 Get, | |
67 Search, | |
68 Delete, | |
69 Delete1, | |
70 Delete2, | |
71 Delete3, | |
72 Replace_d1, | |
73 Replace_d2, | |
74 FindMax1, | |
75 FindMax2, | |
76 DeleteCase1, | |
77 DeleteCase2, | |
78 DeleteCase3, | |
79 DeleteCase4, | |
80 DeleteCase5, | |
81 DeleteCase6, | |
82 CreateWorker, | |
83 TaskManager, | |
90 | 84 CreateData1, |
85 CreateData2, | |
86 CreateTask1, | |
87 CreateTask2, | |
112 | 88 CreateTask3, |
89 CreateTask4, | |
90 | 90 PutQueue1, |
91 PutQueue2, | |
92 PutQueue3, | |
93 PutQueue4, | |
91 | 94 GetQueue, |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
95 PushSingleLinkedStack, |
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
96 PopSingleLinkedStack, |
112 | 97 SpawnTask, |
92 | 98 Twice, |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
99 StartTime, |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
100 EndTime, |
86 | 101 Exit, |
102 }; | |
103 | |
104 enum Relational { | |
105 EQ, | |
106 GT, | |
107 LT, | |
108 }; | |
109 | |
130 | 110 enum DataType { |
86 | 111 Worker, |
112 Allocate, | |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
113 SingleLinkedStack, |
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
114 Stack, |
86 | 115 Tree, |
91 | 116 Traverse, |
86 | 117 Node, |
118 LoopCounter, | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
119 Time, |
90 | 120 Element, |
87 | 121 ActiveQueue, |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
122 WaitQueue, |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
123 Queue |
86 | 124 }; |
125 | |
126 struct Context { | |
127 enum Code next; | |
128 int codeNum; | |
129 __code (**code) (struct Context*); | |
130 void* heapStart; | |
131 void* heap; | |
132 long heapLimit; | |
133 pthread_t thread; | |
92 | 134 int thread_num; |
87 | 135 int dataNum; |
86 | 136 union Data **data; |
137 }; | |
138 | |
130 | 139 struct QueueInterface { |
140 enum Code put; | |
141 enum Code get; | |
142 enum Code isEmpty; | |
143 }; | |
144 | |
145 struct StackInterface { | |
146 enum Code push; | |
147 enum Code pop; | |
148 enum Code isEmpty; | |
149 }; | |
150 | |
86 | 151 union Data { |
133 | 152 struct Meta { |
153 enum DataType type; | |
154 } meta; | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
155 struct Time { |
102 | 156 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
157 double time; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
158 } time; |
86 | 159 struct LoopCounter { |
160 int i; | |
161 } loopCounter; | |
162 struct Worker { | |
163 int num; | |
164 struct Context* contexts; | |
165 } worker; | |
101 | 166 #ifdef USE_CUDA |
98 | 167 struct CudaTask { |
168 CUdevice device; | |
169 CUcontext cuCtx; | |
170 CUfunction code; | |
171 CUdeviceptr* deviceptr; | |
172 CUstream stream; | |
173 } cudatask; | |
101 | 174 #endif |
90 | 175 struct Task { |
176 enum Code code; | |
177 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
178 struct Queue* waitMe; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
179 struct Queue* waitI; |
112 | 180 int idsCount; |
90 | 181 } task; |
182 struct Queue { | |
183 struct Element* first; | |
184 struct Element* last; | |
185 int count; | |
130 | 186 struct QueueInterface* i; |
187 enum Code next; | |
90 | 188 } queue; |
132 | 189 // Stack Interface |
130 | 190 struct Stack { |
132 | 191 union Data* stack; |
130 | 192 union Data* data; |
133 | 193 union Data* data1; |
130 | 194 enum Code push; |
195 enum Code pop; | |
133 | 196 enum Code pop2; |
130 | 197 enum Code isEmpty; |
133 | 198 enum Code whenEmpty; |
199 enum Code get2; | |
130 | 200 enum Code next; |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
201 } stack; |
132 | 202 // Stack implementations |
203 struct SingleLinkedStack { | |
204 struct Element* top; | |
205 } singleLinekedStack; | |
206 struct ArrayStack { | |
207 int size; | |
208 int limit; | |
209 struct Element* array; | |
210 } arrayStack; | |
211 // Stack implementation end | |
90 | 212 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
213 union Data* data; |
90 | 214 struct Element* next; |
215 } element; | |
86 | 216 struct Array { |
90 | 217 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
218 int prefix; |
86 | 219 int* array; |
220 } array; | |
221 struct Tree { | |
222 struct Node* root; | |
91 | 223 } tree; |
224 struct Traverse { | |
103 | 225 enum Code next; |
119 | 226 enum Code rotateNext; |
122 | 227 struct Node* current; // reading node of original tree |
124 | 228 struct Node* newNode; // writing node of new tree |
132 | 229 struct Stack* nodeStack; |
86 | 230 int result; |
91 | 231 } traverse; |
86 | 232 struct Node { |
233 int key; // comparable data segment | |
90 | 234 union Data* value; |
86 | 235 struct Node* left; |
236 struct Node* right; | |
237 // need to balancing | |
238 enum Color { | |
239 Red, | |
240 Black, | |
241 } color; | |
242 } node; | |
243 struct Allocate { | |
244 enum Code next; | |
245 long size; | |
246 } allocate; | |
112 | 247 struct OutPutDataSegments { |
248 union Data **data; | |
249 } ods; | |
86 | 250 }; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
251 |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
252 union MetaData { |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
253 struct Queue waitMeTasks; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
254 struct Queue waitI; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
255 }; |
132 | 256 #endif |