view src/parallel_execution/worker.c @ 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 77e60b6cdace
line wrap: on
line source

#include <libkern/OSAtomic.h>

#include "context.h"
#include "origin_cs.h"

__code initWorker(struct Context* context) {
    context->next = GetInputData1;
    goto meta(context, GetQueue1);
}

__code initWorker_stub(struct Context* context) {
    goto initWorker(context);
}

__code getQueue1(struct Context* context, struct Queue* queue, struct Element* element) {
    if (queue->first == 0)
        return;

    element->data = queue->first->data;
    if (__sync_bool_compare_and_swap(&queue->first, queue->first, queue->first->next)) {
        queue->count--;
        goto meta(context, context->next);
    } else {
        goto meta(context, GetQueue1);
    }
}

__code getQueue1_stub(struct Context* context) {
    goto getQueue1(context, &context->data[Queue]->queue, &context->data[Element]->element);
}

__code getInputData1(struct Context* context, struct Task* task, struct Node* node, struct LoopCounter* loopCounter) {
    int i = loopCounter->i;
    if(i < sizeof(task->iKeys) / sizeof(int)) {
        context->next = GetInputData2;
        node->key = task->iKeys[i];
        struct Traverse *t = &context->data[Traverse]->traverse;
        t->next = GetQueue1;
        goto meta(context, Get);
    }
    loopCounter->i = 0;
    goto meta(context, GetOutputData1);
}

__code getInputData1_stub(struct Context* context) {
    goto getInputData1(context,
            (struct Task*)(context->data[Element]->element.data),
            &context->data[Node]->node,
            &context->data[LoopCounter]->loopCounter);
}

__code getInputData2(struct Context* context, struct Task* task, union Data* data, struct LoopCounter* loopCounter) {
    int i = loopCounter->i;
    task->iargs[i] = data;
    loopCounter->i++;
    goto meta(context, GetInputData1);
}

__code getInputData2_stub(struct Context* context) {
    goto getInputData2(context,
            (struct Task*)(context->data[Element]->element.data),
            context->data[Node]->node.value,
            &context->data[LoopCounter]->loopCounter);
}

__code getOutputData1(struct Context* context, struct Task* task, struct Node* node, struct LoopCounter* loopCounter) {
    int i = loopCounter->i;
    if(i < sizeof(task->oKeys)/ sizeof(int)) {
        context->next = GetOutputData2;
        node->key = task->oKeys[i];
        struct Traverse *t = &context->data[Traverse]->traverse;
        t->next = GetQueue1;
        goto meta(context, Get);
    }
    context->next = CheckTaskFinish1;
    loopCounter->i = 0;
    goto meta(context, task->code);
}

__code getOutputData1_stub(struct Context* context) {
    goto getOutputData1(context,
            (struct Task*)(context->data[Element]->element.data),
            &context->data[Node]->node,
            &context->data[LoopCounter]->loopCounter);
}

__code getOutputData2(struct Context* context, struct Task* task, union Data* data, struct LoopCounter* loopCounter) {
    int i = loopCounter->i;
    task->oargs[i] = data;
    loopCounter->i++;
    goto meta(context, GetOutputData1);
}

__code getOutputData2_stub(struct Context* context) {
    goto getOutputData2(context,
            (struct Task*)(context->data[Element]->element.data),
            context->data[Node]->node.value,
            &context->data[LoopCounter]->loopCounter);
}

#ifdef USE_CUDA
__code twiceGpu(struct Context* context) {
    cuMemcpyHtoDAsync(context,context,context,context->stream);
    cuLaunchkanel();
    cuMemcpyDtoHAsync();
}
#endif