Mercurial > hg > Members > Moririn
annotate src/parallel_execution/context.h @ 122:73a679a85c04
node stack rewrite
author | ikkun |
---|---|
date | Wed, 28 Sep 2016 18:47:16 +0900 |
parents | b224aa7b80a0 |
children | 36ac17d37be4 |
rev | line source |
---|---|
86 | 1 /* Context definition for llrb example */ |
2 #include <pthread.h> | |
101 | 3 #ifdef USE_CUDA |
98 | 4 #include <cuda.h> |
101 | 5 #endif |
86 | 6 #include "stack.h" |
7 | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
8 #define ALLOCATE_SIZE 20000000 |
101 | 9 #define NEW(type) (type*)(calloc(1, sizeof(type))) |
10 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | |
11 | |
12 #define ALLOC_DATA(context, dseg) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; }) | |
13 | |
14 #define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; }) | |
86 | 15 |
16 enum Code { | |
17 Code1, | |
18 Code2, | |
19 Code3, | |
20 Code4, | |
21 Code5, | |
22 Find, | |
23 Not_find, | |
24 Code6, | |
25 Allocator, | |
90 | 26 PutTree, |
86 | 27 Replace, |
28 Insert, | |
29 Compare, | |
30 RotateL, | |
31 RotateR, | |
32 SetTree, | |
33 InsertCase1, | |
34 InsertCase2, | |
35 InsertCase3, | |
36 InsertCase4, | |
37 InsertCase4_1, | |
38 InsertCase4_2, | |
39 InsertCase5, | |
40 StackClear, | |
41 Get, | |
42 Search, | |
43 Delete, | |
44 Delete1, | |
45 Delete2, | |
46 Delete3, | |
47 Replace_d1, | |
48 Replace_d2, | |
49 FindMax1, | |
50 FindMax2, | |
51 DeleteCase1, | |
52 DeleteCase2, | |
53 DeleteCase3, | |
54 DeleteCase4, | |
55 DeleteCase5, | |
56 DeleteCase6, | |
57 CreateWorker, | |
58 TaskManager, | |
90 | 59 CreateData1, |
60 CreateData2, | |
61 CreateTask1, | |
62 CreateTask2, | |
112 | 63 CreateTask3, |
64 CreateTask4, | |
90 | 65 PutQueue1, |
66 PutQueue2, | |
67 PutQueue3, | |
68 PutQueue4, | |
91 | 69 GetQueue, |
112 | 70 SpawnTask, |
92 | 71 Twice, |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
72 StartTime, |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
73 EndTime, |
86 | 74 Exit, |
75 }; | |
76 | |
77 enum Relational { | |
78 EQ, | |
79 GT, | |
80 LT, | |
81 }; | |
82 | |
83 enum UniqueData { | |
84 Worker, | |
85 Allocate, | |
86 Tree, | |
91 | 87 Traverse, |
86 | 88 Node, |
89 LoopCounter, | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
90 Time, |
90 | 91 Element, |
87 | 92 ActiveQueue, |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
93 WaitQueue, |
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
94 Queue, |
86 | 95 }; |
96 | |
97 struct Context { | |
98 enum Code next; | |
99 int codeNum; | |
100 __code (**code) (struct Context*); | |
101 void* heapStart; | |
102 void* heap; | |
103 long heapLimit; | |
104 pthread_t thread; | |
92 | 105 int thread_num; |
86 | 106 stack_ptr code_stack; |
107 stack_ptr node_stack; | |
87 | 108 int dataNum; |
86 | 109 union Data **data; |
110 }; | |
111 | |
112 union Data { | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
113 struct Time { |
102 | 114 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
115 double time; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
116 } time; |
86 | 117 struct LoopCounter { |
118 int i; | |
119 } loopCounter; | |
120 struct Worker { | |
121 int num; | |
122 struct Context* contexts; | |
123 } worker; | |
101 | 124 #ifdef USE_CUDA |
98 | 125 struct CudaTask { |
126 CUdevice device; | |
127 CUcontext cuCtx; | |
128 CUfunction code; | |
129 CUdeviceptr* deviceptr; | |
130 CUstream stream; | |
131 } cudatask; | |
101 | 132 #endif |
90 | 133 struct Task { |
134 enum Code code; | |
135 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
136 struct Queue* waitMe; |
114
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
137 struct Queue* waitI; |
112 | 138 int idsCount; |
90 | 139 } task; |
140 struct Queue { | |
141 struct Element* first; | |
142 struct Element* last; | |
143 int count; | |
144 } queue; | |
145 struct Element { | |
114
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
146 union Data* data; |
90 | 147 struct Element* next; |
148 } element; | |
86 | 149 struct Array { |
90 | 150 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
151 int prefix; |
86 | 152 int* array; |
153 } array; | |
154 struct Tree { | |
155 struct Node* root; | |
91 | 156 } tree; |
157 struct Traverse { | |
103 | 158 enum Code next; |
119 | 159 enum Code rotateNext; |
122 | 160 struct Node* current; // reading node of original tree |
161 struct Node* newNode; // wrting node of new tree | |
86 | 162 int result; |
91 | 163 } traverse; |
86 | 164 struct Node { |
165 // need to tree | |
166 enum Code next; | |
167 int key; // comparable data segment | |
90 | 168 union Data* value; |
86 | 169 struct Node* left; |
170 struct Node* right; | |
171 // need to balancing | |
172 enum Color { | |
173 Red, | |
174 Black, | |
175 } color; | |
176 } node; | |
177 struct Allocate { | |
178 enum Code next; | |
179 long size; | |
180 } allocate; | |
112 | 181 struct OutPutDataSegments { |
182 union Data **data; | |
183 } ods; | |
86 | 184 }; |
114
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
185 |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
186 union MetaData { |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
187 struct Queue waitMeTasks; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
188 struct Queue waitI; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
189 }; |
d05b9937aa95
Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
190 |