annotate src/parallel_execution/main.cbc @ 277:9d671e63df74

generate extern
author mir3636
date Thu, 02 Feb 2017 18:29:50 +0900
parents src/parallel_execution/main.c@cd3486e4ba70
children 23767f714f4a
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
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "context.h"
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "origin_cs.h"
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
8 extern union Data* createRedBlackTree(struct Context* context);
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
9 extern union Data* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
10 extern void allocator(struct Context* context);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
12 int cpu_num = 1;
116
f57e9ffa7960 add comment rb_tree
ikkun
parents: 112
diff changeset
13 int length = 102400;
f57e9ffa7960 add comment rb_tree
ikkun
parents: 112
diff changeset
14 int split = 8;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
15 int* array_ptr;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
16
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
17 void print_queue(struct Element* element) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
18 while (element) {
185
247a2c4a8908 fix compile errors
mir3636
parents: 182
diff changeset
19 printf("%p\n", ((struct Task *)(element->data)));
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
20 element = element->next;
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 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
23
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
24 void print_tree(struct Node* node) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
25 if (node != 0) {
196
119c035e0e36 replace Array and Stack for array and stack
ikkun
parents: 187
diff changeset
26 printf("%d\n", node->value->Array.index);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
27 print_tree(node->left);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
28 print_tree(node->right);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
29 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
30 }
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
32 __code initDataGears(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
33 loopCounter->tree = &createRedBlackTree(context)->Tree;
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
34 loopCounter->i = 0;
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
35 taskManager->taskManager = (union Data*)&createTaskManager(context, cpu_num, 0, 0)->TaskManager;
248
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
36 goto meta(context, C_createTask1);
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
37 }
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
38
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
39 __code initDataGears_stub(struct Context* context) {
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
40 goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager));
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
41 }
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
42
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
43 __code code1(struct Context* context, struct Time* time) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
44 printf("cpus:\t\t%d\n", cpu_num);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
45 printf("length:\t\t%d\n", length);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
46 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
47 /* puts("queue"); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
48 /* print_queue(context->data[ActiveQueue]->queue.first); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
49 /* puts("tree"); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
50 /* print_tree(context->data[Tree]->tree.root); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
51 /* puts("result"); */
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
52
232
123b0d277b84 worker interface
mir3636
parents: 220
diff changeset
53 time->next = C_code2;
248
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
54 goto meta(context, C_exit_code);
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
55 //goto meta(context, C_start_time);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 __code code1_stub(struct Context* context) {
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
59 goto code1(context, Gearef(context, Time));
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
62 __code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) {
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
63 int i = loopCounter->i;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
64
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
65 if (i < length) {
114
0f0459653d77 Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
66 //printf("%d\n", array->array[i]);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
67 if (array->array[i] == (i*2)) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
68 loopCounter->i++;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
69 goto meta(context, C_code2);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
70 } else
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
71 puts("wrong result");
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
72
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
73 }
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
74
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
75 goto meta(context, C_code2);
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
76 }
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
77
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
78 __code code2_stub(struct Context* context) {
217
c34e6aa10967 Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 211
diff changeset
79 goto code2(context, &context->data[D_Node]->Node.value->Array, &context->data[D_LoopCounter]->LoopCounter);
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
80 }
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
81
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
82 __code createData1(struct Context* context, struct Allocate* allocate, struct LoopCounter* loopCounter) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
83 int i = loopCounter->i;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
84
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
85 if ((length/split*i) < length) {
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
86 goto meta(context, C_createData2);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
87 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
88
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
89 loopCounter->i = 0;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
90 goto meta(context, C_code1);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
91 }
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
92
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
93 __code createData1_stub(struct Context* context) {
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
94 goto createData1(context, Gearef(context, Allocate), Gearef(context, LoopCounter));
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
95 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
96
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
97 __code createData2(struct Context* context, struct LoopCounter* loopCounter, struct Array* array, struct Node* node, Tree* tree) {
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
98 int i = loopCounter->i;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
99
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
100 array->index = i;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
101 array->prefix = length/split;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
102 array->array = array_ptr;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
103
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
104 node->key = i;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
105 node->value = (union Data*)array;
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
106
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
107 tree->tree = (union Data*)loopCounter->tree;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
108
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
109 tree->next = C_createTask1;
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
110 tree->node = node;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
111
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
112 goto meta(context, loopCounter->tree->put);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
113 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
114
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
115 __code createData2_stub(struct Context* context) {
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
116 Array* array = &ALLOCATE(context, Array)->Array;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
117 goto createData2(context,
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
118 Gearef(context, LoopCounter),
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
119 array,
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
120 Gearef(context, Node),
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
121 Gearef(context, Tree));
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
122 }
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
123
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
124 __code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
125 int i = loopCounter->i;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
126
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
127 if ((length/split*i) < length) {
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
128 taskManager->next = C_createTask2;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
129 goto meta(context, taskManager->taskManager->TaskManager.createTask);
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
130 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
131
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
132 loopCounter->i = 0;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
133 goto meta(context, C_code1);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
134 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
135
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
136 __code createTask1_stub(struct Context* context) {
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
137 goto createTask1(context,
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
138 Gearef(context, LoopCounter),
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
139 Gearef(context, TaskManager));
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
140 }
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
141
257
cd3486e4ba70 fix make error of twice
mir3636
parents: 248
diff changeset
142 __code createTask2(struct Context* context, LoopCounter* loopCounter, TaskManager* taskManager,struct Context* task, Array* array) {
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
143 int i = loopCounter->i;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
144
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
145 if ((length/split*i) < length) {
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
146 array->index = i;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
147 array->prefix = length/split;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
148 array->array = array_ptr;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
149 task->idgCount = 0;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
150 task->next = C_twice;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
151 // task->data[task->idg] = (union Data*)array;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
152 taskManager->next = C_createTask1;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
153 loopCounter->i++;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
154
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
155 goto meta(context, taskManager->taskManager->TaskManager.spawn);
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 loopCounter->i = 0;
248
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
158 taskManager->next = C_code1;
1ede5390cda2 Fix segmentation fault but not multi thread running
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 247
diff changeset
159 goto meta(context, taskManager->taskManager->TaskManager.shutdown);
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
160 }
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
161
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
162 __code createTask2_stub(struct Context* context) {
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
163 Array* array = &ALLOCATE(context, Array)->Array;
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
164 goto createTask2(context,
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
165 Gearef(context, LoopCounter),
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
166 Gearef(context, TaskManager),
247
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
167 Gearef(context, TaskManager)->context,
ce262b2c1daf Fix createTask for main
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
168 array);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
169 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
170
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
171 void init(int argc, char** argv) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
172 for (int i = 1; argv[i]; ++i) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
173 if (strcmp(argv[i], "-cpu") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
174 cpu_num = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
175 else if (strcmp(argv[i], "-l") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
176 length = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
177 else if (strcmp(argv[i], "-s") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
178 split = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
179 }
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
180 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
181
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
182
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 int main(int argc, char** argv) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
184 init(argc, argv);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
185
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
186 array_ptr = NEWN(length, int);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
187
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
188 for(int i=0; i<length; i++)
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
189 array_ptr[i]=i;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
191 struct Context* main_context = NEW(struct Context);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 initContext(main_context);
220
6c0692c9bfed Fix rb_tree
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
193 main_context->next = C_initDataGears;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 goto start_code(main_context);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 }
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
197