annotate src/parallel_execution/examples/bitonicSort.cbc @ 371:c3a7a086e82a

Add bitonicSort
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Fri, 07 Jul 2017 14:58:26 +0900
parents
children fb50cf8aa615
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
371
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <string.h>
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <stdlib.h>
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <unistd.h>
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "../../context.h"
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 int cpu_num = 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 int length = 100;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 int gpu_num = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 int CPU_ANY = -1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 int CPU_CUDA = -1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 void *start_taskManager(struct Context *context) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager));
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 return 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #ifdef USE_CUDAWorker
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #ifdef USE_CUDA_MAIN_THREAD
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 extern volatile int cuda_initialized;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #endif
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #endif
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 // loopCounter->tree = createRedBlackTree(context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 loopCounter->i = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #ifdef USE_CUDAWorker
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #ifdef USE_CUDA_MAIN_THREAD
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 while(! cuda_initialized) {};
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #endif
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #endif
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 goto meta(context, C_createTask1);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 __code initDataGears_stub(struct Context* context) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 struct TaskManager* taskManager = Gearef(context, TaskManager);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 taskManager->taskManager = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 #if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD))
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 goto initDataGears(context, loopCounter, taskManager);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 #else
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 cuda_initialized = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 pthread_t thread;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 pthread_create(&thread, NULL, (void*)&start_taskManager, context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 while (taskManager->taskManager == 0);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 TaskManager *t = (TaskManager*)taskManager->taskManager;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 struct Queue *q = (Queue *)im->workers[0];
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 createCUDAWorker(context,0,q, im);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 pthread_join(thread,0);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 exit(0);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 #endif
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 __code code1(struct Time* time) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 printf("cpus:\t\t%d\n", cpu_num);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 printf("gpus:\t\t%d\n", gpu_num);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 printf("length:\t\t%d\n", length);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 /* puts("queue"); */
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 /* print_queue(context->data[ActiveQueue]->queue.first); */
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 /* puts("tree"); */
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 /* print_tree(context->data[Tree]->tree.root); */
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 /* puts("result"); */
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 //time->next = C_code2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 goto meta(context, C_exit_code);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 //goto meta(context, C_start_time);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 __code code1_stub(struct Context* context) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 goto code1(context, Gearef(context, Time));
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 int waitFlag = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 struct SortArray* inputSortArray = &ALLOCATE_DATA_GEAR(context, sortArray)->sortArray;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 inputSortArray->array = array;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 for (int i=2; i <= length; i=2*i) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 int first = 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 lastOne = (length <= i*2) ? true : false;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 for (int j=i>>1; 0 < j; j=j>>1) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, sortArray)->sortArray;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 outputSortArray->array = array;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 for(int k=0; 0 < length/2; k++) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 struct Context* task = NEW(struct Context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 struct Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 struct Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 struct Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 integer1->value = j;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 integer2->value = first;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 integer3->value = k;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 task->next = C_swap;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if (waitFlag) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 task->idgCount = length/2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 } else {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 task->idgCount = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 task->idg = task->dataNum;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 task->data[task->idg+1] = (union Data*)inputSortArray;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 task->data[task->idg+2] = (union Data*)integer1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 task->data[task->idg+3] = (union Data*)integer2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 task->data[task->idg+4] = (union Data*)integer3;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 task->maxIdg = task->idg + 4;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 task->odg = task->maxIdg;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 task->data[task->odg] = outputSortArray;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 task->maxOdg = task->odg + 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 first = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 inputSortArray = outputSortArray;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 waitFlag = 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 goto meta(context, taskManager->taskManager->TaskManager.shutdown);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 __code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 3);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 // par goto mult(integer1, integer2, integer3, __exit);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 struct Context* task = NEW(struct Context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 initContext(task);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 task->taskManager = &taskManager->taskManager->TaskManager;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 task->next = C_mult;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 task->idgCount = 2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 task->idg = task->dataNum;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 task->data[task->idg] = (union Data*)integer1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 task->data[task->idg+1] = (union Data*)integer2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 task->maxIdg = task->idg + 2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 task->odg = task->maxIdg;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 task->data[task->odg] = (union Data*)integer3;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 task->maxOdg = task->odg + 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 tasks[0] = task;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 Integer* integer4 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 Integer* integer5 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 // par goto add(integer4, integer5, integer1, __exit);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 task = NEW(struct Context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 initContext(task);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 task->taskManager = &taskManager->taskManager->TaskManager;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 task->next = C_add;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 task->idgCount = 2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 task->idg = task->dataNum;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 task->data[task->idg] = (union Data*)integer4;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 task->data[task->idg+1] = (union Data*)integer5;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 task->maxIdg = task->idg + 2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 task->odg = task->maxIdg;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 task->data[task->odg] = (union Data*)integer1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 task->maxOdg = task->odg + 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 tasks[1] = task;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 // par goto initIntegerDataGears(integer2, integer4, integer5, __exit);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 task = NEW(struct Context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 initContext(task);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 task->taskManager = &taskManager->taskManager->TaskManager;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 task->next = C_initIntegerDataGears;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 task->idgCount = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 task->idg = task->dataNum;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 task->maxIdg = task->idg;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 task->odg = task->maxIdg;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 task->data[task->odg] = (union Data*)integer2;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 task->data[task->odg+1] = (union Data*)integer4;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 task->data[task->odg+2] = (union Data*)integer5;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 task->maxOdg = task->odg + 3;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 tasks[2] = task;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 taskManager->contexts = tasks;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 // goto crateTask1();
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 taskManager->next1 = C_createTask1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 goto meta(context, taskManager->taskManager->TaskManager.spawnTasks);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 void init(int argc, char** argv) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 for (int i = 1; argv[i]; ++i) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 if (strcmp(argv[i], "-cpu") == 0)
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 cpu_num = (int)atoi(argv[i+1]);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 else if (strcmp(argv[i], "-l") == 0)
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 length = (int)atoi(argv[i+1]);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 else if (strcmp(argv[i], "-cuda") == 0) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 gpu_num = 1;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 CPU_CUDA = 0;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 }
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 int main(int argc, char** argv) {
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 init(argc, argv);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 struct Context* main_context = NEW(struct Context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 initContext(main_context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 main_context->next = C_initDataGears;
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 goto start_code(main_context);
c3a7a086e82a Add bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 }