Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 148:473b7d990a1f
fix data gears type enum
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 10 Nov 2016 12:07:53 +0900 |
parents | f2275f5777f4 |
children | 63ab65b28466 |
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 |
86 | 37 enum Code { |
144 | 38 C_code1, |
39 C_code2, | |
40 C_code3, | |
41 C_code4, | |
42 C_code5, | |
43 C_find, | |
86 | 44 Not_find, |
45 Code6, | |
46 Allocator, | |
144 | 47 C_put, |
48 C_replaceNode, | |
49 C_replaceNode1, | |
50 C_insertNode, | |
86 | 51 Compare, |
144 | 52 C_rotateLeft, |
53 C_rotateLeft1, | |
54 C_rotateRight, | |
55 C_rotateRight1, | |
86 | 56 SetTree, |
144 | 57 C_insertCase1, |
58 C_insertCase2, | |
59 C_insertCase3, | |
60 C_insertCase4, | |
61 C_insertCase5, | |
62 C_insertCase51, | |
63 C_stackClear, | |
64 C_get, | |
65 C_search, | |
86 | 66 Delete, |
67 Delete1, | |
68 Delete2, | |
69 Delete3, | |
70 Replace_d1, | |
71 Replace_d2, | |
72 FindMax1, | |
73 FindMax2, | |
74 DeleteCase1, | |
75 DeleteCase2, | |
76 DeleteCase3, | |
77 DeleteCase4, | |
78 DeleteCase5, | |
79 DeleteCase6, | |
80 CreateWorker, | |
81 TaskManager, | |
90 | 82 CreateData1, |
83 CreateData2, | |
84 CreateTask1, | |
85 CreateTask2, | |
112 | 86 CreateTask3, |
87 CreateTask4, | |
90 | 88 PutQueue1, |
89 PutQueue2, | |
90 PutQueue3, | |
91 PutQueue4, | |
91 | 92 GetQueue, |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
93 C_clearSingleLinkedStack, |
144 | 94 C_pushSingleLinkedStack, |
95 C_popSingleLinkedStack, | |
96 C_pop2SingleLinkedStack, | |
97 C_getSingleLinkedStack, | |
98 C_get2SingleLinkedStack, | |
99 C_isEmptySingleLinkedStack, | |
112 | 100 SpawnTask, |
92 | 101 Twice, |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
102 StartTime, |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
103 EndTime, |
86 | 104 Exit, |
105 }; | |
106 | |
107 enum Relational { | |
108 EQ, | |
109 GT, | |
110 LT, | |
111 }; | |
112 | |
130 | 113 enum DataType { |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
114 D_Worker, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
115 D_Allocate, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
116 D_SingleLinkedStack, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
117 D_Stack, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
118 D_Tree, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
119 D_Traverse, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
120 D_RotateTree, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
121 D_Node, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
122 D_LoopCounter, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
123 D_Time, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
124 D_Element, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
125 D_ActiveQueue, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
126 D_WaitQueue, |
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
127 D_Queue |
86 | 128 }; |
129 | |
130 struct Context { | |
131 enum Code next; | |
132 int codeNum; | |
133 __code (**code) (struct Context*); | |
134 void* heapStart; | |
135 void* heap; | |
136 long heapLimit; | |
137 pthread_t thread; | |
92 | 138 int thread_num; |
87 | 139 int dataNum; |
86 | 140 union Data **data; |
141 }; | |
142 | |
143 union Data { | |
133 | 144 struct Meta { |
145 enum DataType type; | |
146 } meta; | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
147 struct Time { |
102 | 148 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
149 double time; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
150 } time; |
86 | 151 struct LoopCounter { |
152 int i; | |
153 } loopCounter; | |
154 struct Worker { | |
155 int num; | |
156 struct Context* contexts; | |
157 } worker; | |
101 | 158 #ifdef USE_CUDA |
98 | 159 struct CudaTask { |
160 CUdevice device; | |
161 CUcontext cuCtx; | |
162 CUfunction code; | |
163 CUdeviceptr* deviceptr; | |
164 CUstream stream; | |
165 } cudatask; | |
101 | 166 #endif |
90 | 167 struct Task { |
168 enum Code code; | |
169 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
170 struct Queue* waitMe; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
171 struct Queue* waitI; |
112 | 172 int idsCount; |
90 | 173 } task; |
174 struct Queue { | |
175 struct Element* first; | |
176 struct Element* last; | |
177 int count; | |
136 | 178 union Data* queue; |
130 | 179 enum Code next; |
90 | 180 } queue; |
132 | 181 // Stack Interface |
130 | 182 struct Stack { |
132 | 183 union Data* stack; |
130 | 184 union Data* data; |
133 | 185 union Data* data1; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
186 enum Code whenEmpty; |
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
187 |
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
188 enum Code clear; |
130 | 189 enum Code push; |
190 enum Code pop; | |
133 | 191 enum Code pop2; |
130 | 192 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
193 enum Code get; |
133 | 194 enum Code get2; |
130 | 195 enum Code next; |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
196 } stack; |
132 | 197 // Stack implementations |
198 struct SingleLinkedStack { | |
199 struct Element* top; | |
135 | 200 } singleLinkedStack; |
132 | 201 struct ArrayStack { |
202 int size; | |
203 int limit; | |
204 struct Element* array; | |
205 } arrayStack; | |
206 // Stack implementation end | |
90 | 207 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
208 union Data* data; |
90 | 209 struct Element* next; |
210 } element; | |
86 | 211 struct Array { |
90 | 212 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
213 int prefix; |
86 | 214 int* array; |
215 } array; | |
216 struct Tree { | |
217 struct Node* root; | |
91 | 218 } tree; |
219 struct Traverse { | |
103 | 220 enum Code next; |
122 | 221 struct Node* current; // reading node of original tree |
138 | 222 struct Node* previous; // parent of reading node of original tree |
124 | 223 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
|
224 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
225 struct Node* grandparent; |
132 | 226 struct Stack* nodeStack; |
86 | 227 int result; |
91 | 228 } traverse; |
147 | 229 struct RotateTree { |
230 enum Code next; | |
231 struct Traverse* traverse; | |
232 struct Tree* tree; | |
233 } rotateTree; | |
86 | 234 struct Node { |
235 int key; // comparable data segment | |
90 | 236 union Data* value; |
86 | 237 struct Node* left; |
238 struct Node* right; | |
239 // need to balancing | |
240 enum Color { | |
241 Red, | |
242 Black, | |
243 } color; | |
244 } node; | |
245 struct Allocate { | |
246 enum Code next; | |
247 long size; | |
248 } allocate; | |
112 | 249 struct OutPutDataSegments { |
250 union Data **data; | |
251 } ods; | |
86 | 252 }; |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
253 |
147 | 254 // typedef struct RotateTree D_RotateTree; |
255 | |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
256 union MetaData { |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
257 struct Queue waitMeTasks; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
258 struct Queue waitI; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
259 }; |
132 | 260 #endif |