Mercurial > hg > Gears > GearsAgda
comparison 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 |
comparison
equal
deleted
inserted
replaced
403:83c9aeb1fe3e | 404:c5cd9888bf2a |
---|---|
1 #include "../../../context.h" | |
2 #include <stdio.h> | |
3 | |
4 __code bitonicSwap(struct SortArray* inputArray, struct MultiDim* multiDim, __code next(struct SortArray* output, ...), struct LoopCounter* loopCounter) { | |
5 struct SortArray* output = *O_output; | |
6 int block = inputArray->block; | |
7 int first = inputArray->first; | |
8 if (loopCounter->i < inputArray->prefix) { | |
9 int index = loopCounter->i + multiDim->x * inputArray->prefix; | |
10 int position = index/block; | |
11 int index1 = index+block*position; | |
12 int index2 = (first == 1)? ((block<<1)*(position+1))-(index1%block)-1 : index1+block; | |
13 struct Integer* array = inputArray->array; | |
14 if (array[index2].value < array[index1].value) { | |
15 struct Integer tmp = array[index1]; | |
16 array[index1] = array[index2]; | |
17 array[index2] = tmp; | |
18 } | |
19 loopCounter->i++; | |
20 goto meta(context, C_bitonicSwap); | |
21 } | |
22 loopCounter->i = 0; | |
23 output->array = inputArray->array; | |
24 *O_output = output; | |
25 goto meta(context, next); | |
26 } | |
27 | |
28 __code bitonicSwap_stub(struct Context* context) { | |
29 SortArray** O_output = (struct SortArray **)&context->data[context->odg]; | |
30 goto bitonicSwap(context, | |
31 &context->data[context->idg]->SortArray, | |
32 &context->data[context->idg+1]->MultiDim, | |
33 context->next, | |
34 O_output, | |
35 Gearef(context, LoopCounter)); | |
36 } |