view src/parallel_execution/examples/swap.cbc @ 377:b4677965afa7

Fix
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 18 Jul 2017 17:52:22 +0900
parents ad44fdb11433
children 2744cb933ebc
line wrap: on
line source

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

__code swap(struct SortArray sortArray, struct Integer* block, struct Integer* first, struct Integer* i, __code next(struct SortArray* output, ...)) {
    int position = i->value/block->value;
    int index = i->value+block->value*position;

    block->value = (first->value == 1)? ((block->value<<1)*(position+1))-(index%block->value)-1 : index+block->value;

    if (sortArray->array[block] < sortArray->array[index]) {
        int Integer *tmp = sortArray->array[index];
        sortArray->array[index] = sortArray->array[block];
        sortArray->array[block] = tmp;
    }

    *O_output = output;
    goto meta(context, next);
}

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