comparison src/parallel_execution/context.h @ 132:7c309e1aea73

Code Gears stack api
author one
date Thu, 27 Oct 2016 18:54:11 +0900
parents a4507906938c
children 568730b1239e
comparison
equal deleted inserted replaced
131:a4507906938c 132:7c309e1aea73
1 /* Context definition for llrb example */ 1 /* Context definition for llrb example */
2 #ifndef CONTEXT_H
3 #define CONTEXT_H
2 #include <pthread.h> 4 #include <pthread.h>
3 #ifdef USE_CUDA 5 #ifdef USE_CUDA
4 #include <cuda.h> 6 #include <cuda.h>
5 #endif 7 #endif
6 #include "stack.h"
7 8
8 #define ALLOCATE_SIZE 20000000 9 #define ALLOCATE_SIZE 20000000
9 #define NEW(type) (type*)(calloc(1, sizeof(type))) 10 #define NEW(type) (type*)(calloc(1, sizeof(type)))
10 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) 11 #define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
11 12
12 #define ALLOC_DATA(context, dseg) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; }) 13 #define ALLOC_DATA(context, dseg) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; })
13 14
14 #define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; }) 15 #define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; })
16
17 #define ALLOCATE(context, t) ({ \
18 union Data* data = context->heap; \
19 context->heap += sizeof(struct t) + ((void *)(&data->element) - (void *)data) ; \
20 data->type = t; \
21 data; })
22
23 #define GET_DATA(spesificData) ({ \
24 union Data dummy; \
25 void* ptr = (void *)spesificData; \
26 ptr -= (void *)(&dummy.element) - (void *)(&dummy); \
27 (union Data*)ptr; })
15 28
16 enum Code { 29 enum Code {
17 Code1, 30 Code1,
18 Code2, 31 Code2,
19 Code3, 32 Code3,
161 struct Element* last; 174 struct Element* last;
162 int count; 175 int count;
163 struct QueueInterface* i; 176 struct QueueInterface* i;
164 enum Code next; 177 enum Code next;
165 } queue; 178 } queue;
179 // Stack Interface
166 struct Stack { 180 struct Stack {
167 union StackSelf* stack; 181 union Data* stack;
168 union Data* data; 182 union Data* data;
169 enum Code push; 183 enum Code push;
170 enum Code pop; 184 enum Code pop;
171 enum Code isEmpty; 185 enum Code isEmpty;
172 enum Code next; 186 enum Code next;
173 } stack; 187 } stack;
174 union StackSelf { 188 // Stack implementations
175 struct SingleLinkedStack { 189 struct SingleLinkedStack {
176 struct Stack i; 190 struct Element* top;
177 struct Element* top; 191 } singleLinekedStack;
178 } singleLinekedStack; 192 struct ArrayStack {
179 struct ArrayStack { 193 int size;
180 int size; 194 int limit;
181 int limit; 195 struct Element* array;
182 struct Element* array; 196 } arrayStack;
183 } arrayStack; 197 // Stack implementation end
184 };
185 struct Element { 198 struct Element {
186 union Data* data; 199 union Data* data;
187 struct Element* next; 200 struct Element* next;
188 } element; 201 } element;
189 struct Array { 202 struct Array {
197 struct Traverse { 210 struct Traverse {
198 enum Code next; 211 enum Code next;
199 enum Code rotateNext; 212 enum Code rotateNext;
200 struct Node* current; // reading node of original tree 213 struct Node* current; // reading node of original tree
201 struct Node* newNode; // writing node of new tree 214 struct Node* newNode; // writing node of new tree
202 struct Element* nodeStack; 215 struct Stack* nodeStack;
203 int result; 216 int result;
204 } traverse; 217 } traverse;
205 struct Node { 218 struct Node {
206 int key; // comparable data segment 219 int key; // comparable data segment
207 union Data* value; 220 union Data* value;
224 237
225 union MetaData { 238 union MetaData {
226 struct Queue waitMeTasks; 239 struct Queue waitMeTasks;
227 struct Queue waitI; 240 struct Queue waitI;
228 }; 241 };
229 242 #endif