annotate src/parallel_execution/main.cbc @ 316:54d203daf06b

CUDAtwice.cbc is called.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 15 Feb 2017 16:25:23 +0900
parents 1839586f5b41
children 51aa65676e37
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
2 #include <string.h>
132
7c309e1aea73 Code Gears stack api
one
parents: 117
diff changeset
3 #include <stdlib.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
5 #include "../context.h"
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
7 int cpu_num = 1;
113
f57e9ffa7960 add comment rb_tree
ikkun
parents: 112
diff changeset
8 int length = 102400;
f57e9ffa7960 add comment rb_tree
ikkun
parents: 112
diff changeset
9 int split = 8;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
10 int* array_ptr;
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
11 int gpu_num = 0;
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
12 int CPU_ANY = -1;
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
13 int CPU_CUDA = -1;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
14
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
15 void print_queue(struct Element* element) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
16 while (element) {
185
247a2c4a8908 fix compile errors
mir3636
parents: 182
diff changeset
17 printf("%p\n", ((struct Task *)(element->data)));
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
18 element = element->next;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
19 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
20 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
21
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
22 void print_tree(struct Node* node) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
23 if (node != 0) {
195
119c035e0e36 replace Array and Stack for array and stack
ikkun
parents: 187
diff changeset
24 printf("%d\n", node->value->Array.index);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
25 print_tree(node->left);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
26 print_tree(node->right);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
27 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
28 }
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
30 void *start_taskManager(struct Context *context) {
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
31 goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager));
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
32 return 0;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
33 }
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
34
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
35 #ifdef USE_CUDAWorker
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
36 extern volatile int cuda_initialized;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
37 #endif
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
38
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
39 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
309
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 289
diff changeset
40 // loopCounter->tree = createRedBlackTree(context);
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
41 loopCounter->i = 0;
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
42 taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
43 #ifdef USE_CUDAWorker
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
44 while(! cuda_initialized) {};
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
45 #endif
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
46 TaskManager *t = taskManager->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
47 TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
48 printf("cuda initialized. TaskMangerImpl %p workers %p q %p\n", im, im->workers, im->workers[0]->tasks);
248
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
49 goto meta(context, C_createTask1);
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
50 }
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
51
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
52 __code initDataGears_stub(struct Context* context) {
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
53 struct TaskManager* taskManager = Gearef(context, TaskManager);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
54 taskManager->taskManager = 0;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
55 #ifndef USE_CUDAWorker
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
56 struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
57 goto initDataGears(context, loopCounter, taskManager);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
58 #else
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
59 cuda_initialized = 0;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
60 pthread_t thread;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
61 pthread_create(&thread, NULL, (void*)&start_taskManager, context);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
62 while (taskManager->taskManager == 0);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
63 TaskManager *t = (TaskManager*)taskManager->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
64 TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
65 struct Queue *q = (Queue *)im->workers[0];
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
66 printf("init TaskManagerImpl %p workers %p q %p \n",im, im->workers, q);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
67 createCUDAWorker(context,0,q, im);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
68 pthread_join(thread,0);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
69 exit(0);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
70 #endif
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
71 }
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
72
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
73 __code code1(struct Time* time) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
74 printf("cpus:\t\t%d\n", cpu_num);
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
75 printf("gpus:\t\t%d\n", gpu_num);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
76 printf("length:\t\t%d\n", length);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
77 printf("length/task:\t%d\n", length/split);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
78 /* puts("queue"); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
79 /* print_queue(context->data[ActiveQueue]->queue.first); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
80 /* puts("tree"); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
81 /* print_tree(context->data[Tree]->tree.root); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
82 /* puts("result"); */
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
83
232
123b0d277b84 worker interface
mir3636
parents: 220
diff changeset
84 time->next = C_code2;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
85 goto meta(context, C_code2);
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
86 //goto meta(context, C_exit_code);
248
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
87 //goto meta(context, C_start_time);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 __code code1_stub(struct Context* context) {
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
91 goto code1(context, Gearef(context, Time));
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
94 __code code2(struct LoopCounter* loopCounter) {
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
95 int i = loopCounter->i;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
96
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
97 if (i < length) {
287
6b099d73949c Add queueCount sem to SynchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
98 //printf("%d\n", array_ptr[i]);
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
99 if (array_ptr[i] == (i*2)) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
100 loopCounter->i++;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
101 goto meta(context, C_code2);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
102 } else
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
103 puts("wrong result");
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
104
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
105 }
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
106
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
107 goto meta(context, C_exit_code);
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
108 }
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
109
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
110 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
111 int i = loopCounter->i;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
112
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
113 TaskManager* t = (TaskManager*)taskManager->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
114 TaskManagerImpl* im = (TaskManagerImpl*)t->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
115 printf("createTask1 %p->workers %p\n", im, im->workers);
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
116
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
117 if ((length/split*i) < length) {
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
118 taskManager->next = C_createTask2;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
119 goto meta(context, taskManager->taskManager->TaskManager.createTask);
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
120 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
121
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
122 loopCounter->i = 0;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
123 taskManager->next = C_code1;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
124 goto meta(context, taskManager->taskManager->TaskManager.shutdown);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
125 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
126
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
127 __code createTask2(LoopCounter* loopCounter, TaskManager* taskManager,struct Context* task, LoopCounter* loopCounter2, Array* array) {
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
128 int i = loopCounter->i;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
129 array->index = i;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
130 array->prefix = length/split;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
131 array->array = array_ptr;
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
132 array->size = length;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
133 loopCounter2->i = 0;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
134 task->idgCount = 0;
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
135 if (gpu_num) {
314
1839586f5b41 pthread CUDA test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 313
diff changeset
136 #ifdef USE_CUDAWorker
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
137 task->next = C_CUDAtwice;
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
138 task->workerId = CPU_CUDA;
314
1839586f5b41 pthread CUDA test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 313
diff changeset
139 #else
1839586f5b41 pthread CUDA test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 313
diff changeset
140 task->next = C_twice;
1839586f5b41 pthread CUDA test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 313
diff changeset
141 #endif
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
142 } else {
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
143 task->next = C_twice;
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
144 }
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
145 task->data[task->dataNum] = (union Data*)loopCounter2;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
146 task->data[task->dataNum+1] = (union Data*)array;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
147 task->odg = task->dataNum + 2;
288
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
148 task->maxOdg = task->odg;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
149 taskManager->next = C_createTask1;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
150 loopCounter->i++;
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
151 TaskManager* t = (TaskManager*)taskManager->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
152 TaskManagerImpl* im = (TaskManagerImpl*)t->taskManager;
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 314
diff changeset
153 printf("im %p->workers %p\n", im, im->workers);
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
154 goto meta(context, taskManager->taskManager->TaskManager.spawn);
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
155 }
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
156
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
157 __code createTask2_stub(struct Context* context) {
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
158 LoopCounter* loopCounter = &ALLOCATE(context, LoopCounter)->LoopCounter;
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
159 Array* array = &ALLOCATE(context, Array)->Array;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
160 goto createTask2(context,
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
161 Gearef(context, LoopCounter),
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
162 Gearef(context, TaskManager),
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
163 Gearef(context, TaskManager)->context,
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
164 loopCounter,
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
165 array);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
166 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
167
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
168 void init(int argc, char** argv) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
169 for (int i = 1; argv[i]; ++i) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
170 if (strcmp(argv[i], "-cpu") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
171 cpu_num = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
172 else if (strcmp(argv[i], "-l") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
173 length = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
174 else if (strcmp(argv[i], "-s") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
175 split = (int)atoi(argv[i+1]);
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
176 else if (strcmp(argv[i], "-cuda") == 0) {
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
177 gpu_num = 1;
313
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 312
diff changeset
178 CPU_CUDA = 0;
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 309
diff changeset
179 }
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
180 }
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
181 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
182
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
183
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 int main(int argc, char** argv) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
185 init(argc, argv);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
186
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
187 array_ptr = NEWN(length, int);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
188
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
189 for(int i=0; i<length; i++)
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
190 array_ptr[i]=i;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
192 struct Context* main_context = NEW(struct Context);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 initContext(main_context);
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
194 main_context->next = C_initDataGears;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 goto start_code(main_context);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 }