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