annotate src/parallel_execution/main.c @ 170:ee7134f3bef1

Fix
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 22 Nov 2016 10:36:45 +0900
parents ea7b11f3e717
children 57a11c15ff4c
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
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 extern __code initContext(struct Context* context);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
9 extern void allocator(struct Context* context);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
11 int cpu_num = 1;
116
f57e9ffa7960 add comment rb_tree
ikkun
parents: 112
diff changeset
12 int length = 102400;
f57e9ffa7960 add comment rb_tree
ikkun
parents: 112
diff changeset
13 int split = 8;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
14 int* array_ptr;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
15
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
16 void print_queue(struct Element* element) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
17 while (element) {
113
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
18 printf("%d\n", ((struct Task *)(element->data))->key);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
19 element = element->next;
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
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
23 void print_tree(struct Node* node) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
24 if (node != 0) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
25 printf("%d\n", node->value->array.index);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
26 print_tree(node->left);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
27 print_tree(node->right);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
28 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
29 }
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 __code code1(struct Context* context) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
32 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
33 printf("length:\t\t%d\n", length);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
34 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
35 /* puts("queue"); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
36 /* print_queue(context->data[ActiveQueue]->queue.first); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
37 /* puts("tree"); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
38 /* print_tree(context->data[Tree]->tree.root); */
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
39 /* puts("result"); */
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
40
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
41 context->next = CreateWorker;
102
64c98838a291 remove stack StartTime&EndTime
ikkun
parents: 101
diff changeset
42
149
63ab65b28466 Add Gearef macro
one
parents: 148
diff changeset
43 struct Time *t = &context->data[D_Time]->Time;
102
64c98838a291 remove stack StartTime&EndTime
ikkun
parents: 101
diff changeset
44 t->next = CreateWorker;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
45 goto meta(context, StartTime);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 __code code1_stub(struct Context* context) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 goto code1(context);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
52 __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
53 int i = loopCounter->i;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
54
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
55 if (i < length) {
114
0f0459653d77 Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
56 //printf("%d\n", array->array[i]);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
57 if (array->array[i] == (i*2)) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
58 loopCounter->i++;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
59 goto meta(context, C_code2);
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
60 } else
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
61 puts("wrong result");
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
62
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
63 }
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
64
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
65 goto meta(context, Exit);
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
66 }
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
67
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
68 __code code2_stub(struct Context* context) {
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
69 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
70 }
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
71
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
72 __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
73 int i = loopCounter->i;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
74
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
75 if ((length/split*i) < length) {
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
76 allocate->size = sizeof(struct Array);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
77 allocator(context);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
78
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
79 goto meta(context, CreateData2);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
80 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
81
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
82 loopCounter->i = 0;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
83 goto meta(context, C_code1);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
84 }
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
85
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
86 __code createData1_stub(struct Context* context) {
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
87 goto createData1(context, &context->data[D_Allocate]->allocate, &context->data[D_LoopCounter]->loopCounter);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
88 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
89
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
90 __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
91 int i = loopCounter->i;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
92
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
93 array->index = i;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
94 array->prefix = length/split;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
95 array->array = array_ptr;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
96
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
97 node->key = i;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
98 node->value = (union Data*)array;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
99
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
100 tree->next = CreateTask1;
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
101 tree->node = node;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
102
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
103 goto meta(context, loopCounter->tree->put);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
104 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
105
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
106 __code createData2_stub(struct Context* context) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
107 goto createData2(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
108 &context->data[D_LoopCounter]->loopCounter,
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
109 &context->data[context->dataNum]->array,
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
110 &context->data[D_Node]->node,
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
111 Gearef(context, Tree));
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
112 }
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
113
169
ea7b11f3e717 Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 166
diff changeset
114 __code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct Queue* waitI, struct Element* element) {
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
115 int i = loopCounter->i;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
116
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
117 task->code = Twice;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
118 task->key = i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
119 task->waitMe = waitMe;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
120 task->waitI = waitI;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
121 task->idsCount = 0;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
122
113
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
123 element->data = (union Data *)task;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
124
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
125 context->next = CreateData1;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
126 loopCounter->i++;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
127
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
128 goto meta(context, SpawnTask);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
129 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
130
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
131 __code createTask1_stub(struct Context* context) {
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
132 Task* task = &ALLOCATE(context, Task)->Task;
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
133 Queue* waitMe = &ALLOCATE(context, Queue)->Queue;
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
134 Queue* waitI = &ALLOCATE(context, Queue)->Queue;
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
135 goto createTask1(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
136 &context->data[D_LoopCounter]->loopCounter,
160
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
137 task,
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
138 waitMe,
73c393f0dca3 fix main.c
mir3636
parents: 149
diff changeset
139 waitI,
169
ea7b11f3e717 Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 166
diff changeset
140 &context->data[D_Element]->element);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
141 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
142
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
143 //__code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct OdsQueue* waitI, struct Element* element, struct Queue* activeQueue) {
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
144 // int i = loopCounter->i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
145 //
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
146 // task->code = TaskC;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
147 // task->key = i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
148 // task->waitMe = waitMe;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
149 // task->waitI = waitI;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
150 // task->idsCount = 1;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
151 //
113
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
152 // element->data = (union Data *)task;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
153 //
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
154 // context->next = CreateData1;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
155 // loopCounter->i++;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
156 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
157 // goto meta_createTask2(context, activeQueue, PutQueue1);
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
158 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
159 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
160 //__code createTask4_stub(struct Context* context) {
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
161 // goto createTask2(context,
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
162 // &context->data[LoopCounter]->loopCounter,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
163 // &context->data[context->dataNum]->task,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
164 // &context->data[context->dataNum-1]->queue,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
165 // &context->data[context->dataNum-2]->odsQueue,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
166 // &context->data[Element]->element,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
167 // &context->data[ActiveQueue]->queue);
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
168 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
169 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
170 //__code createTask5(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Task* slave, struct Element* element) {
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
171 // int i = loopCounter->i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
172 //
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
173 // task->code = TaskB;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
174 // task->key = i;
113
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
175 // element->data = (union Data *)task;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
176 //
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
177 // context->next = CreateData1;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
178 // loopCounter->i++;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
179 //
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
180 // goto meta(context, WaitFor1);
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
181 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
182 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
183 //__code createTask5_stub(struct Context* context) {
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
184 // goto createTask2(context,
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
185 // &context->data[context->dataNum]->task,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
186 // &context->data[Element]->element);
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
187 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
188
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 int i = loopCounter->i;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 if (i < worker->num) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 struct Context* worker_context = &worker->contexts[i];
170
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
194 worker_context->next = C_getTask1;
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
195 worker_context->data[D_Tree] = context->data[D_Tree];
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
196 worker_context->data[D_ActiveQueue] = context->data[D_ActiveQueue];
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context);
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
198 worker_context->thread_num = i;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 loopCounter->i++;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 goto meta(context, CreateWorker);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 loopCounter->i = 0;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 goto meta(context, TaskManager);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
207
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 __code createWorker_stub(struct Context* context) {
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
209 goto createWorker(context, &context->data[D_LoopCounter]->loopCounter, &context->data[D_Worker]->worker);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 int i = loopCounter->i;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 if (i < worker->num) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 pthread_join(worker->contexts[i].thread, NULL);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 loopCounter->i++;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 goto meta(context, TaskManager);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 loopCounter->i = 0;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
223
149
63ab65b28466 Add Gearef macro
one
parents: 148
diff changeset
224 Time *t = &context->data[D_Time]->Time;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
225 t->next = C_code2;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
226 goto meta(context, EndTime);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
228
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 __code taskManager_stub(struct Context* context) {
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
230 goto taskManager(context, &context->data[D_LoopCounter]->loopCounter, &context->data[D_Worker]->worker);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
233 void init(int argc, char** argv) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
234 for (int i = 1; argv[i]; ++i) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
235 if (strcmp(argv[i], "-cpu") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
236 cpu_num = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
237 else if (strcmp(argv[i], "-l") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
238 length = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
239 else if (strcmp(argv[i], "-s") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
240 split = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
241 }
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
242 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
243
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
244
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 int main(int argc, char** argv) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
246 init(argc, argv);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
247
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
248 array_ptr = NEWN(length, int);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
249
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
250 for(int i=0; i<length; i++)
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
251 array_ptr[i]=i;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
253 struct Context* main_context = NEW(struct Context);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 initContext(main_context);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
255 main_context->next = CreateData1;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
257 struct Context* worker_contexts = NEWN(cpu_num, struct Context);
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
258
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
259 struct Worker* worker = &main_context->data[D_Worker]->worker;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 worker->num = cpu_num;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 worker->contexts = worker_contexts;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
262
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 for (int i = 0;i<cpu_num;i++)
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 initContext(&worker_contexts[i]);
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
265
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 goto start_code(main_context);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 }