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