view src/parallel_execution/examples/bitonicSort/bitonicSwap.cbc @ 404:c5cd9888bf2a

Fix bitonicSort
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Sun, 03 Sep 2017 00:21:16 +0900
parents src/parallel_execution/examples/bitonicSort/swap.cbc@300c18700ca5
children 49159fbdd1fb
line wrap: on
line source

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

__code bitonicSwap(struct SortArray* inputArray, struct MultiDim* multiDim, __code next(struct SortArray* output, ...), struct LoopCounter* loopCounter) {
    struct SortArray* output = *O_output;
    int block = inputArray->block;
    int first = inputArray->first;
    if (loopCounter->i < inputArray->prefix) {
        int index = loopCounter->i + multiDim->x * inputArray->prefix;
        int position = index/block;
        int index1 = index+block*position;
        int index2 = (first == 1)? ((block<<1)*(position+1))-(index1%block)-1 : index1+block;
        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]->MultiDim,
                     context->next,
                     O_output,
                     Gearef(context, LoopCounter));
}