Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 217:c34e6aa10967
Fix DataGear access name
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Jan 2017 01:18:13 +0900 (2017-01-08) |
parents | 7470b8382672 |
children | d8a59b727f65 |
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 { |
77 int numWorker; | |
78 enum Code spawn; | |
79 enum Code shutdown; | |
184 | 80 enum Code deadLockDetected; |
81 enum Code next; | |
176 | 82 struct Worker* workers; |
184 | 83 } TaskManager; |
182 | 84 struct TaskManagerImpl { |
184 | 85 struct Queue* activeQueue; |
86 struct Queue* taskQueue; | |
87 } TaskManagerImpl; | |
86 | 88 struct Worker { |
176 | 89 int id; |
86 | 90 struct Context* contexts; |
176 | 91 enum Code execute; |
92 enum Code taskSend; | |
93 enum Code taskRecive; | |
94 enum Code shutdown; | |
95 struct Queue* tasks; | |
184 | 96 } Worker; |
101 | 97 #ifdef USE_CUDA |
98 | 98 struct CudaTask { |
99 CUdevice device; | |
100 CUcontext cuCtx; | |
101 CUfunction code; | |
102 CUdeviceptr* deviceptr; | |
103 CUstream stream; | |
185 | 104 } Cudatask; |
187 | 105 #else |
106 struct CudaTask { | |
107 enum Code next; | |
108 } Cudatask; | |
101 | 109 #endif |
177 | 110 struct Main { |
111 enum Code code; | |
112 enum Code next; | |
113 struct Queue* args; | |
185 | 114 } Main; |
90 | 115 struct Task { |
116 enum Code code; | |
176 | 117 struct Queue* dataGears; |
112 | 118 int idsCount; |
166 | 119 } Task; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
120 // Queue Interface |
90 | 121 struct Queue { |
136 | 122 union Data* queue; |
167 | 123 union Data* data; |
124 enum Code whenEmpty; | |
125 enum Code clear; | |
126 enum Code put; | |
127 enum Code take; | |
128 enum Code isEmpty; | |
130 | 129 enum Code next; |
184 | 130 } Queue; |
167 | 131 struct SingleLinkedQueue { |
132 struct Element* top; | |
133 struct Element* last; | |
184 | 134 } SingleLinkedQueue; |
132 | 135 // Stack Interface |
130 | 136 struct Stack { |
132 | 137 union Data* stack; |
130 | 138 union Data* data; |
133 | 139 union Data* data1; |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
140 enum Code whenEmpty; |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
141 enum Code clear; |
130 | 142 enum Code push; |
143 enum Code pop; | |
133 | 144 enum Code pop2; |
130 | 145 enum Code isEmpty; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
146 enum Code get; |
133 | 147 enum Code get2; |
130 | 148 enum Code next; |
194 | 149 } Stack; |
132 | 150 // Stack implementations |
151 struct SingleLinkedStack { | |
152 struct Element* top; | |
194 | 153 } SingleLinkedStack; |
132 | 154 struct ArrayStack { |
155 int size; | |
156 int limit; | |
157 struct Element* array; | |
194 | 158 } ArrayStack; |
132 | 159 // Stack implementation end |
90 | 160 struct Element { |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
161 union Data* data; |
90 | 162 struct Element* next; |
194 | 163 } Element; |
86 | 164 struct Array { |
90 | 165 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
166 int prefix; |
86 | 167 int* array; |
194 | 168 } Array; |
86 | 169 struct Tree { |
166 | 170 union Data* tree; |
171 struct Node* node; | |
152 | 172 enum Code put; |
173 enum Code get; | |
174 enum Code remove; | |
171 | 175 enum Code clear; |
152 | 176 enum Code next; |
166 | 177 } Tree; |
172 | 178 struct RedBlackTree { |
152 | 179 struct Node* root; |
122 | 180 struct Node* current; // reading node of original tree |
138 | 181 struct Node* previous; // parent of reading node of original tree |
124 | 182 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
|
183 struct Node* parent; |
34a7a21edc36
recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
184 struct Node* grandparent; |
132 | 185 struct Stack* nodeStack; |
86 | 186 int result; |
172 | 187 } RedBlackTree; |
147 | 188 struct RotateTree { |
189 enum Code next; | |
172 | 190 struct RedBlackTree* traverse; |
147 | 191 struct Tree* tree; |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
192 } RotateTree; |
86 | 193 struct Node { |
194 int key; // comparable data segment | |
90 | 195 union Data* value; |
86 | 196 struct Node* left; |
197 struct Node* right; | |
198 // need to balancing | |
199 enum Color { | |
200 Red, | |
201 Black, | |
202 } color; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
203 } Node; |
86 | 204 struct Allocate { |
205 enum Code next; | |
206 long size; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
207 } Allocate; |
112 | 208 struct OutPutDataSegments { |
209 union Data **data; | |
217
c34e6aa10967
Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
207
diff
changeset
|
210 } Ods; |
186 | 211 }; // union Data end |
113
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
212 |
186 | 213 #include "c/typedefData.h" |
132 | 214 #endif |