annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
381
b81492c74d2b Create examples directory
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 380
diff changeset
1 #include "../../../context.h"
371
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdio.h>
377
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 375
diff changeset
3
404
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
4 __code bitonicSwap(struct SortArray* inputArray, struct MultiDim* multiDim, __code next(struct SortArray* output, ...), struct LoopCounter* loopCounter) {
379
2744cb933ebc Fix compile error for bitonicSort but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 377
diff changeset
5 struct SortArray* output = *O_output;
404
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
6 int block = inputArray->block;
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
7 int first = inputArray->first;
383
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
8 if (loopCounter->i < inputArray->prefix) {
404
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
9 int index = loopCounter->i + multiDim->x * inputArray->prefix;
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
10 int position = index/block;
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
11 int index1 = index+block*position;
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
12 int index2 = (first == 1)? ((block<<1)*(position+1))-(index1%block)-1 : index1+block;
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
13 struct Integer* array = inputArray->array;
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
14 if (array[index2].value < array[index1].value) {
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
15 struct Integer tmp = array[index1];
383
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
16 array[index1] = array[index2];
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
17 array[index2] = tmp;
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
18 }
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
19 loopCounter->i++;
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
20 goto meta(context, C_bitonicSwap);
377
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 375
diff changeset
21 }
383
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
22 loopCounter->i = 0;
300c18700ca5 Add split to bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 381
diff changeset
23 output->array = inputArray->array;
377
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 375
diff changeset
24 *O_output = output;
374
fb50cf8aa615 Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 371
diff changeset
25 goto meta(context, next);
fb50cf8aa615 Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 371
diff changeset
26 }
375
ad44fdb11433 Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 374
diff changeset
27
379
2744cb933ebc Fix compile error for bitonicSort but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 377
diff changeset
28 __code bitonicSwap_stub(struct Context* context) {
377
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 375
diff changeset
29 SortArray** O_output = (struct SortArray **)&context->data[context->odg];
379
2744cb933ebc Fix compile error for bitonicSort but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 377
diff changeset
30 goto bitonicSwap(context,
2744cb933ebc Fix compile error for bitonicSort but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 377
diff changeset
31 &context->data[context->idg]->SortArray,
404
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
32 &context->data[context->idg+1]->MultiDim,
379
2744cb933ebc Fix compile error for bitonicSort but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 377
diff changeset
33 context->next,
404
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
34 O_output,
c5cd9888bf2a Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
35 Gearef(context, LoopCounter));
375
ad44fdb11433 Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 374
diff changeset
36 }