Mercurial > hg > GearsTemplate
view src/parallel_execution/context.h @ 217:c34e6aa10967
Fix DataGear access name
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Jan 2017 01:18:13 +0900 |
parents | 7470b8382672 |
children | d8a59b727f65 |
line wrap: on
line source
/* Context definition for llrb example */ #ifndef CONTEXT_H #define CONTEXT_H #include <stdlib.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) #include "c/enumCode.h" enum Relational { EQ, GT, LT, }; #include "c/enumData.h" 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; struct Queue* wait; // tasks waiting this dataGear } meta; struct Time { enum Code next; double time; } Time; struct LoopCounter { int i; struct Tree* tree; } LoopCounter; struct TaskManager { int numWorker; enum Code spawn; enum Code shutdown; enum Code deadLockDetected; enum Code next; struct Worker* workers; } TaskManager; struct TaskManagerImpl { struct Queue* activeQueue; struct Queue* taskQueue; } TaskManagerImpl; struct Worker { int id; struct Context* contexts; enum Code execute; enum Code taskSend; enum Code taskRecive; enum Code shutdown; struct Queue* tasks; } Worker; #ifdef USE_CUDA struct CudaTask { CUdevice device; CUcontext cuCtx; CUfunction code; CUdeviceptr* deviceptr; CUstream stream; } Cudatask; #else struct CudaTask { enum Code next; } Cudatask; #endif struct Main { enum Code code; enum Code next; struct Queue* args; } Main; struct Task { enum Code code; struct Queue* dataGears; 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; } 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; }; // union Data end #include "c/typedefData.h" #endif