annotate src/parallel_execution/examples/twice.cbc @ 369:62a88864e1e2

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