view src/parallel_execution/context.h @ 123:4ff6f093b695

Fix segmentation fault
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 13 Sep 2016 11:54:25 +0900
parents a086857e1812
children acf0453b1c7a
line wrap: on
line source

/* Context definition for llrb example */
#include <pthread.h>
#ifdef USE_CUDA
#include <cuda.h>
#endif
#include "stack.h"

#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) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; })

#define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; })

enum Code {
    Code1,
    Code2,
    Code3,
    Code4,
    Code5,
    Find,
    Not_find,
    Code6,
    Allocator,
    PutTree,
    Replace,
    Insert,
    Compare,
    RotateL,
    RotateR,
    SetTree,
    InsertCase1,
    InsertCase2,
    InsertCase3,
    InsertCase4,
    InsertCase4_1,
    InsertCase4_2,
    InsertCase5,
    StackClear,
    Get,
    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,
    CreateTask5,
    Poll1,
    Poll2,
    PutQueue1,
    PutQueue2,
    PutQueue3,
    PutQueue4,
    InitWorker,
    GetQueue1,
    GetInputData1,
    GetInputData2,
    GetOutputData1,
    GetOutputData2,
    WaitFor,
    SpawnTask,
    CheckTaskFinish1,
    CheckTaskFinish2,
    Twice,
    Add,
    Mult,
    StartTime,
    EndTime,
    Exit,
};

enum Relational {
    EQ,
    GT,
    LT,
};

enum UniqueData {
    Worker,
    Allocate,
    Tree,
    Traverse,
    Node,
    LoopCounter,
    Time,
    Element,
    ActiveQueue,
    WaitQueue,
    Queue,
};

struct Context {
    enum Code next;
    int codeNum;
    __code (**code) (struct Context*);
    void* heapStart;
    void* heap;
    long heapLimit;
    pthread_t thread;
    int thread_num;
    stack_ptr code_stack;
    stack_ptr node_stack;
    int dataNum;
    int metaDataNum;
    union Data **data;
    union MetaData **mData;
};

union Data {
    struct Time {
        enum Code next;
        double time;
    } time;
    struct LoopCounter {
        int i;
    } 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 iKeys[2];
        int oKeys[1];
        int idsCount;
        union Data* iargs[2];
        union Data* oargs[1];
    } task;
    struct Queue {
        struct Element* first;
        struct Element* last;
        int count;
    } queue;
    struct Element {
        union Data* data;
        struct Element* next;
    } element;
    struct Array {
        int index;
        int prefix;
        int* array;
    } array;
    struct Tree {
        struct Node* root;
    } tree;
    struct Traverse {
        enum Code next;
        struct Node* current;
        int result;
    } traverse;
    struct Node {
        // need to tree
        enum Code next;
        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 Integer {
        int value;
        int mDataOffset;
    } integer;
};

union MetaData {
    struct Queue waitMeTasks;
};