Mercurial > hg > GearsTemplate
view src/parallel_execution/context.h @ 172:661b0b0d0399
replace Tree to RedBlackTree
author | ikkun |
---|---|
date | Thu, 24 Nov 2016 20:22:17 +0900 |
parents | 747067fe46bd |
children | f0427e27dd7b |
line wrap: on
line source
/* Context definition for llrb example */ #ifndef CONTEXT_H #define CONTEXT_H #include <pthread.h> #ifdef USE_CUDA #include <cuda.h> #endif #define ALLOCATE_SIZE 20000000 #define NEW(type) (type*)(calloc(1, sizeof(type))) #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) #define ALLOC_DATA(context, dseg) ({\ struct Meta* meta = (struct Meta*)context->heap;\ meta->type = D_##dseg;\ context->heap += sizeof(struct Meta);\ context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) #define ALLOC_DATA_TYPE(context, dseg, t) ({\ struct Meta* meta = (struct Meta*)context->heap;\ meta->type = D_##t;\ context->heap += sizeof(struct Meta);\ context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; }) #define ALLOCATE(context, t) ({ \ struct Meta* meta = (struct Meta*)context->heap;\ context->heap += sizeof(struct Meta);\ union Data* data = context->heap; \ context->heap += sizeof(struct t); \ meta->type = D_##t; \ data; }) #define GET_TYPE(dseg) ({ \ struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\ meta->type; }) #define Gearef(context, t) (&(context)->data[D_##t]->t) enum Code { C_code1, C_code2, C_code3, C_code4, C_code5, C_find, Not_find, Code6, Allocator, C_put, C_replaceNode, C_replaceNode1, C_insertNode, Compare, C_rotateLeft, C_rotateLeft1, C_rotateRight, C_rotateRight1, SetTree, C_insertCase1, C_insertCase2, C_insertCase3, C_insertCase4, C_insertCase5, C_insertCase51, C_stackClear, C_get, C_search, Delete, Delete1, Delete2, Delete3, Replace_d1, Replace_d2, FindMax1, FindMax2, DeleteCase1, DeleteCase2, DeleteCase3, DeleteCase4, DeleteCase5, DeleteCase6, CreateWorker, TaskManager, CreateData1, CreateData2, CreateTask1, CreateTask2, CreateTask3, CreateTask4, PutQueue1, PutQueue2, PutQueue3, PutQueue4, C_getTask1, C_getTask2, C_clearSingleLinkedStack, C_pushSingleLinkedStack, C_popSingleLinkedStack, C_pop2SingleLinkedStack, C_getSingleLinkedStack, C_get2SingleLinkedStack, C_isEmptySingleLinkedStack, C_takeSingleLinkedQueue, C_putSingleLinkedQueue, C_isEmptySingleLinkedQueue, C_clearSingleLinkedQueue, C_takeSynchronizedQueue, C_putSynchronizedQueue, C_isEmptySynchronizedQueue, C_clearSynchronizedQueue, C_putRedBlackTree, C_getRedBlackTree, C_removeRedBlackTree, C_clearRedBlackTree, SpawnTask, Twice, StartTime, EndTime, Exit, }; enum Relational { EQ, GT, LT, }; enum DataType { D_Worker, D_Allocate, D_SingleLinkedStack, D_Stack, D_RedBlackTree, D_Tree, D_Task, D_Traverse, D_RotateTree, D_Node, D_LoopCounter, D_Time, D_Element, D_ActiveQueue, D_WaitQueue, D_SingleLinkedQueue, D_SynchronizedQueue, D_Queue }; struct Context { enum Code next; int codeNum; __code (**code) (struct Context*); void* heapStart; void* heap; long heapLimit; pthread_t thread; int thread_num; int dataNum; union Data **data; }; union Data { struct Meta { enum DataType type; } meta; struct Time { enum Code next; double time; } Time; struct LoopCounter { int i; struct Tree* tree; } loopCounter; struct Worker { int num; struct Context* contexts; } worker; #ifdef USE_CUDA struct CudaTask { CUdevice device; CUcontext cuCtx; CUfunction code; CUdeviceptr* deviceptr; CUstream stream; } cudatask; #endif struct Task { enum Code code; int key; struct Queue* waitMe; struct Queue* waitI; int idsCount; } Task; // Queue Interface struct Queue { union Data* queue; union Data* data; enum Code whenEmpty; enum Code clear; enum Code put; enum Code take; enum Code isEmpty; enum Code next; } Queue; struct SingleLinkedQueue { struct Element* top; struct Element* last; enum Code next; } SingleLinkedQueue; // Stack Interface struct Stack { union Data* stack; union Data* data; union Data* data1; enum Code whenEmpty; enum Code clear; enum Code push; enum Code pop; enum Code pop2; enum Code isEmpty; enum Code get; enum Code get2; enum Code next; } stack; // Stack implementations struct SingleLinkedStack { struct Element* top; } singleLinkedStack; struct ArrayStack { int size; int limit; struct Element* array; } arrayStack; // Stack implementation end struct Element { union Data* data; struct Element* next; } element; struct Array { int index; int prefix; int* array; } array; struct Tree { union Data* tree; struct Node* node; enum Code put; enum Code get; enum Code remove; enum Code clear; enum Code next; } Tree; struct RedBlackTree { struct Node* root; struct Node* current; // reading node of original tree struct Node* previous; // parent of reading node of original tree struct Node* newNode; // writing node of new tree struct Node* parent; struct Node* grandparent; struct Stack* nodeStack; int result; } RedBlackTree; struct RotateTree { enum Code next; struct RedBlackTree* traverse; struct Tree* tree; } rotateTree; struct Node { int key; // comparable data segment union Data* value; struct Node* left; struct Node* right; // need to balancing enum Color { Red, Black, } color; } node; struct Allocate { enum Code next; long size; } allocate; struct OutPutDataSegments { union Data **data; } ods; }; // typedef struct RotateTree D_RotateTree; typedef struct Time Time; typedef struct LoopCounter LoopCounter; typedef struct Worker Worker; typedef struct CudaTask CudaTask; typedef struct Task Task; typedef struct Queue Queue; typedef struct SingleLinkedQueue SingleLinkedQueue; typedef struct SynchronizedQueue SynchronizedQueue; typedef struct Stack Stack; typedef struct SingleLinkedStack SingleLinkedStack; typedef struct ArrayStack ArrayStack; typedef struct Element Element; typedef struct Array Array; typedef struct RedBlackTree RedBlackTree; typedef struct Tree Tree; typedef struct RotateTree RotateTree; typedef struct Node Node; typedef struct Allocate Allocate; typedef struct OutputDataSegments OutputDataSegments; union MetaData { struct Queue waitMeTasks; struct Queue waitI; }; #endif