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