Mercurial > hg > GearsTemplate
view src/parallel_execution/context.h @ 234:47588c28f189
TaskManager
author | mir3636 |
---|---|
date | Sun, 22 Jan 2017 20:17:11 +0900 |
parents | 06133afb3b5b |
children | 865179a0a56d |
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 ALLOC(context, t) (&ALLOCATE(context, t)->t) #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) // (struct SingleLinkedStack *)context->data[D_Stack]->Stack.stack->Stack.stack #define GearImpl(context, intf, name) (Gearef(context, intf)->name->intf.name) #include "c/enumCode.h" enum Relational { EQ, GT, LT, }; #include "c/enumData.h" struct Context { enum Code next; struct Worker* worker; struct TaskManager* taskManager; int codeNum; __code (**code) (struct Context*); void* heapStart; void* heap; long heapLimit; int thread_num; int dataNum; union Data **data; }; union Data { struct Meta { enum DataType type; struct Queue* wait; // tasks waiting this dataGear } meta; struct Context context; struct Time { enum Code next; double time; } Time; struct LoopCounter { int i; struct Tree* tree; } LoopCounter; struct TaskManager { union Data* taskManager; enum Code createTask; // create NEW contexts for execution & argument enum Code spawn; // start NEW context on the worker enum Code shutdown; enum Code next; enum Code task; struct Context* context; int worker; int cpu; int gpu; int io; } TaskManager; struct TaskManagerImpl { int numWorker; struct Queue* activeQueue; struct Queue* taskQueue; struct Worker* workers; } TaskManagerImpl; struct Worker { union Data* worker; enum Code taskReceive; enum Code shutdown; enum Code next; } Worker; struct CPUWorker { pthread_t thread; struct Context* context; int id; struct Queue* tasks; int runFlag; enum Code next; } CPUWorker; #ifdef USE_CUDA struct CudaWorker { pthread_t thread; struct Context* context; int id; struct Queue* tasks; int runFlag; enum Code next; CUdevice device; CUcontext cuCtx; CUfunction code; CUdeviceptr* deviceptr; CUstream stream; } CudaWorker; #else struct CudaWorker { } CudaWorker; #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