Mercurial > hg > GearsTemplate
annotate src/parallel_execution/context.h @ 109:059b26a250cc
Change put_queue process
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 May 2016 20:02:09 +0900 |
parents | 828ab677c8ef |
children | e3cba827d489 |
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, | |
63 PutQueue1, | |
64 PutQueue2, | |
65 PutQueue3, | |
66 PutQueue4, | |
91 | 67 GetQueue, |
92 | 68 Twice, |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
69 StartTime, |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
70 EndTime, |
86 | 71 Exit, |
72 }; | |
73 | |
74 enum Relational { | |
75 EQ, | |
76 GT, | |
77 LT, | |
78 }; | |
79 | |
80 enum UniqueData { | |
81 Worker, | |
82 Allocate, | |
83 Tree, | |
91 | 84 Traverse, |
86 | 85 Node, |
86 LoopCounter, | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
87 Time, |
90 | 88 Element, |
87 | 89 ActiveQueue, |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
90 WaitQueue, |
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
91 Queue, |
86 | 92 }; |
93 | |
94 struct Context { | |
95 enum Code next; | |
96 int codeNum; | |
97 __code (**code) (struct Context*); | |
98 void* heapStart; | |
99 void* heap; | |
100 long heapLimit; | |
101 pthread_t thread; | |
92 | 102 int thread_num; |
86 | 103 stack_ptr code_stack; |
104 stack_ptr node_stack; | |
87 | 105 int dataNum; |
86 | 106 union Data **data; |
107 }; | |
108 | |
109 union Data { | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
110 struct Time { |
102 | 111 enum Code next; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
112 double time; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
113 } time; |
86 | 114 struct LoopCounter { |
115 int i; | |
116 } loopCounter; | |
117 struct Worker { | |
118 int num; | |
119 struct Context* contexts; | |
120 } worker; | |
101 | 121 #ifdef USE_CUDA |
98 | 122 struct CudaTask { |
123 CUdevice device; | |
124 CUcontext cuCtx; | |
125 CUfunction code; | |
126 CUdeviceptr* deviceptr; | |
127 CUstream stream; | |
128 } cudatask; | |
101 | 129 #endif |
90 | 130 struct Task { |
131 enum Code code; | |
132 int key; | |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
133 struct Queue* waitMe; |
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
106
diff
changeset
|
134 struct Queue* waitI; |
90 | 135 } task; |
136 struct Queue { | |
137 struct Element* first; | |
138 struct Element* last; | |
139 int count; | |
140 } queue; | |
141 struct Element { | |
142 struct Task* task; | |
143 struct Element* next; | |
144 } element; | |
86 | 145 struct Array { |
90 | 146 int index; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
147 int prefix; |
86 | 148 int* array; |
149 } array; | |
150 struct Tree { | |
151 struct Node* root; | |
91 | 152 } tree; |
153 struct Traverse { | |
103 | 154 enum Code next; |
86 | 155 struct Node* current; |
156 int result; | |
91 | 157 } traverse; |
86 | 158 struct Node { |
159 // need to tree | |
160 enum Code next; | |
161 int key; // comparable data segment | |
90 | 162 union Data* value; |
86 | 163 struct Node* left; |
164 struct Node* right; | |
165 // need to balancing | |
166 enum Color { | |
167 Red, | |
168 Black, | |
169 } color; | |
170 } node; | |
171 struct Allocate { | |
172 enum Code next; | |
173 long size; | |
174 } allocate; | |
175 }; |