view src/parallel_execution/examples/bitonicSort/swap.cbc @ 383:300c18700ca5

Add split to bitonicSort
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 25 Jul 2017 04:52:18 +0900
parents b81492c74d2b
children
line wrap: on
line source

#include "../../../context.h"
#include <stdio.h>

__code bitonicSwap(struct SortArray* inputArray, struct Integer* block, struct Integer* first, struct Integer* i, struct LoopCounter* loopCounter, __code next(struct SortArray* output, ...)) {
    struct SortArray* output = *O_output;
    if (loopCounter->i < inputArray->prefix) {
        int index = loopCounter->i + i->value * inputArray->prefix;
        int position = index/block->value;
        int index1 = index+block->value*position;
        int index2 = (first->value == 1)? ((block->value<<1)*(position+1))-(index1%block->value)-1 : index1+block->value;
        struct Integer** array = inputArray->array;
        if (array[index2]->value < array[index1]->value) {
            struct Integer *tmp = array[index1];
            array[index1] = array[index2];
            array[index2] = tmp;
        }
        loopCounter->i++;
        goto meta(context, C_bitonicSwap);
    }
    loopCounter->i = 0;
    output->array = inputArray->array;
    *O_output = output;
    goto meta(context, next);
}

__code bitonicSwap_stub(struct Context* context) {
    SortArray** O_output = (struct SortArray **)&context->data[context->odg];
    goto bitonicSwap(context,
                     &context->data[context->idg]->SortArray,
                     &context->data[context->idg+1]->Integer,
                     &context->data[context->idg+2]->Integer,
                     &context->data[context->idg+3]->Integer,
                     Gearef(context, LoopCounter),
                     context->next,
                     O_output);
}