annotate src/parallel_execution/main.c @ 132:7c309e1aea73

Code Gears stack api
author one
date Thu, 27 Oct 2016 18:54:11 +0900
parents a574ba0da60f
children d529c024e5a5
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;
113
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) {
114
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
64c98838a291 remove stack StartTime&EndTime
ikkun
parents: 101
diff changeset
43 struct Time *t = &context->data[Time]->time;
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) {
115
0f0459653d77 Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 114
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++;
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
59 goto meta(context, Code2);
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) {
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
69 goto code2(context, &context->data[Node]->node.value->array, &context->data[LoopCounter]->loopCounter);
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;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
83 goto meta(context, Code1);
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) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
87 goto createData1(context, &context->data[Allocate]->allocate, &context->data[LoopCounter]->loopCounter);
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
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
90 __code createData2(struct Context* context, struct LoopCounter* loopCounter, struct Array* array, struct Node* node) {
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
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
100 context->next = CreateTask1;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
101
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
102 goto meta(context, PutTree);
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
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
105 __code createData2_stub(struct Context* context) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
106 goto createData2(context,
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
107 &context->data[LoopCounter]->loopCounter,
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
108 &context->data[context->dataNum]->array,
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
109 &context->data[Node]->node);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
110 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
111
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
112 __code createTask1(struct Context* context, struct Allocate* allocate) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
113 allocate->size = sizeof(struct Task);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
114 allocator(context);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
115 goto meta(context, CreateTask2);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
116 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
117
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
118 __code createTask1_stub(struct Context* context) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
119 goto createTask1(context, &context->data[Allocate]->allocate);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
120 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
121
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
122 __code createTask2(struct Context* context, struct Allocate* allocate) {
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
123 allocate->size = sizeof(struct Queue);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
124 allocator(context);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
125 goto meta(context, CreateTask3);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
126 }
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
127
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
128 __code createTask2_stub(struct Context* context) {
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
129 goto createTask2(context, &context->data[Allocate]->allocate);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
130 }
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
131
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
132 __code createTask3(struct Context* context, struct Allocate* allocate) {
114
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
133 allocate->size = sizeof(struct Queue);
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
134 allocator(context);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
135 goto meta(context, CreateTask4);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
136 }
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
137
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
138 __code createTask3_stub(struct Context* context) {
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
139 goto createTask3(context, &context->data[Allocate]->allocate);
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
140 }
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
141
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
142 __code meta_createTask4(struct Context* context, struct Queue* activeQueue, enum Code next) {
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
143 context->data[Queue] = (union Data *)activeQueue;
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
144 goto (context->code[next])(context);
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
145 }
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
146
115
0f0459653d77 Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 114
diff changeset
147 __code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct Queue* waitI, struct Element* element, struct Queue* activeQueue) {
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
148 int i = loopCounter->i;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
149
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
150 waitMe->first = 0;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
151 waitMe->last = 0;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
152 waitMe->count = 0;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
153
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
154 waitI->first = 0;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
155 waitI->last = 0;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
156 waitI->count = 0;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
157
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
158 task->code = Twice;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
159 task->key = i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
160 task->waitMe = waitMe;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
161 task->waitI = waitI;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
162 task->idsCount = 0;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
163
114
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
164 element->data = (union Data *)task;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
165
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
166 context->next = CreateData1;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
167 loopCounter->i++;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
168
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
169 goto meta(context, SpawnTask);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
170 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
171
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
172 __code createTask4_stub(struct Context* context) {
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
173 goto createTask4(context,
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
174 &context->data[LoopCounter]->loopCounter,
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
175 &context->data[context->dataNum-2]->task,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
176 &context->data[context->dataNum-1]->queue,
115
0f0459653d77 Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 114
diff changeset
177 &context->data[context->dataNum]->queue,
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
178 &context->data[Element]->element,
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
179 &context->data[ActiveQueue]->queue);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
180 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
181
111
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 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
184 // int i = loopCounter->i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
185 //
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
186 // task->code = TaskC;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
187 // task->key = i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
188 // task->waitMe = waitMe;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
189 // task->waitI = waitI;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
190 // task->idsCount = 1;
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
191 //
114
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
192 // element->data = (union Data *)task;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
193 //
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
194 // context->next = CreateData1;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
195 // loopCounter->i++;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
196 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
197 // goto meta_createTask2(context, activeQueue, PutQueue1);
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
198 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
199 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
200 //__code createTask4_stub(struct Context* context) {
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
201 // goto createTask2(context,
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
202 // &context->data[LoopCounter]->loopCounter,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
203 // &context->data[context->dataNum]->task,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
204 // &context->data[context->dataNum-1]->queue,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
205 // &context->data[context->dataNum-2]->odsQueue,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
206 // &context->data[Element]->element,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
207 // &context->data[ActiveQueue]->queue);
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
208 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
209 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
210 //__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
211 // int i = loopCounter->i;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
212 //
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
213 // task->code = TaskB;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
214 // task->key = i;
114
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
215 // element->data = (union Data *)task;
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
216 //
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
217 // context->next = CreateData1;
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
218 // loopCounter->i++;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
219 //
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
220 // goto meta(context, WaitFor1);
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
221 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
222 //
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
223 //__code createTask5_stub(struct Context* context) {
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
224 // goto createTask2(context,
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
225 // &context->data[context->dataNum]->task,
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 111
diff changeset
226 // &context->data[Element]->element);
111
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
227 //}
556e203de999 Add dependency.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
228
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
229 __code putQueue1(struct Context* context, struct Allocate* allocate) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
230 allocate->size = sizeof(struct Element);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
231 allocator(context);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
232
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
233 goto meta(context, PutQueue2);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
234 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
235
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
236 __code putQueue1_stub(struct Context* context) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
237 goto putQueue1(context, &context->data[Allocate]->allocate);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
238 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
239
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
240 __code putQueue2(struct Context* context, struct Element* new_element, struct Element* element, struct Queue* queue) {
114
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
241 new_element->data = element->data;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
242
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
243 if (queue->first)
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
244 goto meta(context, PutQueue3);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
245 else
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
246 goto meta(context, PutQueue4);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
247 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
248
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
249 __code putQueue2_stub(struct Context* context) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
250 goto putQueue2(context,
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
251 &context->data[context->dataNum]->element,
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
252 &context->data[Element]->element,
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
253 &context->data[Queue]->queue);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
254 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
255
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
256 __code putQueue3(struct Context* context, struct Queue* queue, struct Element* new_element) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
257 struct Element* last = queue->last;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
258
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
259 if (__sync_bool_compare_and_swap(&queue->last, last, new_element)) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
260 last->next = new_element;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
261 queue->count++;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
262
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
263 goto meta(context, context->next);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
264 } else {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
265 goto meta(context, PutQueue3);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
266 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
267 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
268
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
269 __code putQueue3_stub(struct Context* context) {
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
270 goto putQueue3(context, &context->data[Queue]->queue, &context->data[context->dataNum]->element);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
271 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
272
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
273 __code putQueue4(struct Context* context, struct Queue* queue, struct Element* new_element) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
274 if (__sync_bool_compare_and_swap(&queue->first, 0, new_element)) {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
275 queue->last = new_element;
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
276 queue->count++;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
277
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
278 goto meta(context, context->next);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
279 } else {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
280 goto meta(context, PutQueue3);
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
281 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
282 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
283
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
284 __code putQueue4_stub(struct Context* context) {
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
285 goto putQueue4(context, &context->data[Queue]->queue, &context->data[context->dataNum]->element);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
286 }
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
287
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 __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
289 int i = loopCounter->i;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 if (i < worker->num) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 struct Context* worker_context = &worker->contexts[i];
91
1e074c3878c7 modify tree
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
293 worker_context->next = GetQueue;
1e074c3878c7 modify tree
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
294 worker_context->data[Tree] = context->data[Tree];
1e074c3878c7 modify tree
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
295 worker_context->data[ActiveQueue] = context->data[ActiveQueue];
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 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
297 worker_context->thread_num = i;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 loopCounter->i++;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 goto meta(context, CreateWorker);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 loopCounter->i = 0;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 goto meta(context, TaskManager);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
306
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 __code createWorker_stub(struct Context* context) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 goto createWorker(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 __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
312 int i = loopCounter->i;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 if (i < worker->num) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 pthread_join(worker->contexts[i].thread, NULL);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 loopCounter->i++;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 goto meta(context, TaskManager);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 loopCounter->i = 0;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
322
102
64c98838a291 remove stack StartTime&EndTime
ikkun
parents: 101
diff changeset
323 struct Time *t = &context->data[Time]->time;
64c98838a291 remove stack StartTime&EndTime
ikkun
parents: 101
diff changeset
324 t->next = Code2;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
325 goto meta(context, EndTime);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
327
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 __code taskManager_stub(struct Context* context) {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 goto taskManager(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
332 void init(int argc, char** argv) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
333 for (int i = 1; argv[i]; ++i) {
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
334 if (strcmp(argv[i], "-cpu") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
335 cpu_num = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
336 else if (strcmp(argv[i], "-l") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
337 length = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
338 else if (strcmp(argv[i], "-s") == 0)
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
339 split = (int)atoi(argv[i+1]);
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
340 }
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
341 }
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
342
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
343
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 int main(int argc, char** argv) {
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
345 init(argc, argv);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
346
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
347 array_ptr = NEWN(length, int);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
348
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
349 for(int i=0; i<length; i++)
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
350 array_ptr[i]=i;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
352 struct Context* main_context = NEW(struct Context);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 initContext(main_context);
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
354 main_context->next = CreateData1;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 95
diff changeset
356 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
357
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 struct Worker* worker = &main_context->data[Worker]->worker;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 worker->num = cpu_num;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 worker->contexts = worker_contexts;
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
361
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 for (int i = 0;i<cpu_num;i++)
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 initContext(&worker_contexts[i]);
109
059b26a250cc Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
364
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 goto start_code(main_context);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 }