Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 222:77faa28128b4
Add taskSend for TaskManager
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 11 Jan 2017 16:52:27 +0900 |
parents | d8a59b727f65 |
children | a1fb3f2d1a36 |
rev | line source |
---|---|
86 | 1 /* Context definition for llrb example */ |
132 | 2 #ifndef CONTEXT_H |
3 #define CONTEXT_H | |
207
7470b8382672
Fix compile error to stack_test
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
194
diff
changeset
|
4 #include <stdlib.h> |
86 | 5 #include <pthread.h> |
101 | 6 #ifdef USE_CUDA |
98 | 7 #include <cuda.h> |
101 | 8 #endif |
86 | 9 |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
10 #define ALLOCATE_SIZE 20000000 |
101 | 11 #define NEW(type) (type*)(calloc(1, sizeof(type))) |
12 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | |
13 | |
133 | 14 #define ALLOC_DATA(context, dseg) ({\ |
15 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
|
16 meta->type = D_##dseg;\ |
133 | 17 context->heap += sizeof(struct Meta);\ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
18 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) |
101 | 19 |
133 | 20 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ |
21 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
|
22 meta->type = D_##t;\ |
133 | 23 context->heap += sizeof(struct Meta);\ |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
24 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; }) |
86 | 25 |
132 | 26 #define ALLOCATE(context, t) ({ \ |
133 | 27 struct Meta* meta = (struct Meta*)context->heap;\ |
28 context->heap += sizeof(struct Meta);\ | |
29 union Data* data = context->heap; \ | |
30 context->heap += sizeof(struct t); \ | |
148
473b7d990a1f
fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
31 meta->type = D_##t; \ |
133 | 32 data; }) |
132 | 33 |
133 | 34 #define GET_TYPE(dseg) ({ \ |
35 struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\ | |
36 meta->type; }) | |
132 | 37 |
149 | 38 #define Gearef(context, t) (&(context)->data[D_##t]->t) |
186 | 39 |
40 #include "c/enumCode.h" | |
86 | 41 |
42 enum Relational { | |
43 EQ, | |
44 GT, | |
45 LT, | |
46 }; | |
47 | |
186 | 48 #include "c/enumData.h" |
86 | 49 |
50 struct Context { | |
51 enum Code next; | |
52 int codeNum; | |
53 __code (**code) (struct Context*); | |
54 void* heapStart; | |
55 void* heap; | |
56 long heapLimit; | |
57 pthread_t thread; | |
92 | 58 int thread_num; |
87 | 59 int dataNum; |
86 | 60 union Data **data; |
61 }; | |
62 | |
63 union Data { | |
133 | 64 struct Meta { |
65 enum DataType type; | |
176 | 66 struct Queue* wait; // tasks waiting this dataGear |
133 | 67 } meta; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
68 struct Time { |
102 | 69 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
70 double time; |
149 | 71 } Time; |
86 | 72 struct LoopCounter { |
73 int i; | |
166 | 74 struct Tree* tree; |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
75 } LoopCounter; |
176 | 76 struct TaskManager { |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
77 union Data* taskManager; |
176 | 78 int numWorker; |
79 enum Code spawn; | |
80 enum Code shutdown; | |
184 | 81 enum Code deadLockDetected; |
82 enum Code next; | |
218
d8a59b727f65
Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
83 struct Task* task; |
176 | 84 struct Worker* workers; |
184 | 85 } TaskManager; |
182 | 86 struct TaskManagerImpl { |
184 | 87 struct Queue* activeQueue; |
88 struct Queue* taskQueue; | |
89 } TaskManagerImpl; | |
86 | 90 struct Worker { |
176 | 91 int id; |
86 | 92 struct Context* contexts; |
176 | 93 enum Code execute; |
94 enum Code taskSend; | |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
218
diff
changeset
|
95 enum Code taskReceive; |
176 | 96 enum Code shutdown; |
97 struct Queue* tasks; | |
184 | 98 } Worker; |
101 | 99 #ifdef USE_CUDA |
98 | 100 struct CudaTask { |
101 CUdevice device; | |
102 CUcontext cuCtx; | |
103 CUfunction code; | |
104 CUdeviceptr* deviceptr; | |
105 CUstream stream; | |
185 | 106 } Cudatask; |
187 | 107 #else |
108 struct CudaTask { | |
109 enum Code next; | |
110 } Cudatask; | |
101 | 111 #endif |
177 | 112 struct Main { |
113 enum Code code; | |
114 enum Code next; | |
115 struct Queue* args; | |
185 | 116 } Main; |
90 | 117 struct Task { |
118 enum Code code; | |
176 | 119 struct Queue* dataGears; |
112 | 120 int idsCount; |
166 | 121 } Task; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
122 // Queue Interface |
90 | 123 struct Queue { |
136 | 124 union Data* queue; |
167 | 125 union Data* data; |
126 enum Code whenEmpty; | |
127 enum Code clear; | |
128 enum Code put; | |
129 enum Code take; | |
130 enum Code isEmpty; | |
130 | 131 enum Code next; |
184 | 132 } Queue; |
167 | 133 struct SingleLinkedQueue { |
134 struct Element* top; | |
135 struct Element* last; | |
184 | 136 } SingleLinkedQueue; |
132 | 137 // Stack Interface |
130 | 138 struct Stack { |
132 | 139 union Data* stack; |
130 | 140 union Data* data; |
133 | 141 union Data* data1; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
142 enum Code whenEmpty; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
143 enum Code clear; |
130 | 144 enum Code push; |
145 enum Code pop; | |
133 | 146 enum Code pop2; |
130 | 147 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
148 enum Code get; |
133 | 149 enum Code get2; |
130 | 150 enum Code next; |
194 | 151 } Stack; |
132 | 152 // Stack implementations |
153 struct SingleLinkedStack { | |
154 struct Element* top; | |
194 | 155 } SingleLinkedStack; |
132 | 156 struct ArrayStack { |
157 int size; | |
158 int limit; | |
159 struct Element* array; | |
194 | 160 } ArrayStack; |
132 | 161 // Stack implementation end |
90 | 162 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
163 union Data* data; |
90 | 164 struct Element* next; |
194 | 165 } Element; |
86 | 166 struct Array { |
90 | 167 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
168 int prefix; |
86 | 169 int* array; |
194 | 170 } Array; |
86 | 171 struct Tree { |
166 | 172 union Data* tree; |
173 struct Node* node; | |
152 | 174 enum Code put; |
175 enum Code get; | |
176 enum Code remove; | |
171 | 177 enum Code clear; |
152 | 178 enum Code next; |
166 | 179 } Tree; |
172 | 180 struct RedBlackTree { |
152 | 181 struct Node* root; |
122 | 182 struct Node* current; // reading node of original tree |
138 | 183 struct Node* previous; // parent of reading node of original tree |
124 | 184 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
|
185 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
186 struct Node* grandparent; |
132 | 187 struct Stack* nodeStack; |
86 | 188 int result; |
172 | 189 } RedBlackTree; |
147 | 190 struct RotateTree { |
191 enum Code next; | |
172 | 192 struct RedBlackTree* traverse; |
147 | 193 struct Tree* tree; |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
194 } RotateTree; |
86 | 195 struct Node { |
196 int key; // comparable data segment | |
90 | 197 union Data* value; |
86 | 198 struct Node* left; |
199 struct Node* right; | |
200 // need to balancing | |
201 enum Color { | |
202 Red, | |
203 Black, | |
204 } color; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
205 } Node; |
86 | 206 struct Allocate { |
207 enum Code next; | |
208 long size; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
209 } Allocate; |
112 | 210 struct OutPutDataSegments { |
211 union Data **data; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
212 } Ods; |
186 | 213 }; // union Data end |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
214 |
186 | 215 #include "c/typedefData.h" |
132 | 216 #endif |