Mercurial > hg > Gears > GearsAgda
annotate src/parallel_execution/context.h @ 112:e3cba827d489
Add spawnTask CS
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 03 May 2016 17:29:21 +0900 |
parents | 059b26a250cc |
children | d05b9937aa95 |
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; |
112 | 137 struct OdsQueue* waitI; |
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 { | |
146 struct Task* task; | |
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; |
86 | 159 struct Node* current; |
160 int result; | |
91 | 161 } traverse; |
86 | 162 struct Node { |
163 // need to tree | |
164 enum Code next; | |
165 int key; // comparable data segment | |
90 | 166 union Data* value; |
86 | 167 struct Node* left; |
168 struct Node* right; | |
169 // need to balancing | |
170 enum Color { | |
171 Red, | |
172 Black, | |
173 } color; | |
174 } node; | |
175 struct Allocate { | |
176 enum Code next; | |
177 long size; | |
178 } allocate; | |
112 | 179 struct OutPutDataSegments { |
180 union Data **data; | |
181 } ods; | |
182 struct OdsQueue { | |
183 struct OdsElement* first; | |
184 struct OdsElement* last; | |
185 int count; | |
186 } odsQueue; | |
187 struct OdsElement { | |
188 struct OutPutDataSegments* ods; | |
189 struct OdsElement* next; | |
190 } odsElement; | |
86 | 191 }; |