annotate test/scheduler/test_sched.cbc @ 2:803d6bf22e6d default tip

second commit. it's far to complete..
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Dec 2009 16:19:56 +0900
parents aef83aed7a07
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "Task.h"
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #define __DEBUG(f, args...) \
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 fprintf(stderr, "in %s: "f, __FUNCTION__, ## args)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
9
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
10 void * allocate (size_t size);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
11
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
12 __code taskA_0(void *tsched, void *rbuff, void *wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
13 __code taskA_1(void *tsched, void *rbuff, void *wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
14 __code taskA_2(void *tsched, void *rbuff, void *wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
15 __code task0 (void *tsched, void *rbuff, void *wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
16 __code task1 (void *tsched, void *rbuff, void *wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
17 __code task2 (void *tsched, void *rbuff, void *wbuff);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 int main (int argc, char **argv);
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
19 __code startcode (void *tsched, void *arg);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
20 __code checkNewCode (void *tsched, int wait);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
21 __code exitCode (void *tsched, int id);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 void * allocate (size_t size);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #define NUM 3
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 __code
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
26 taskA_0(void *tsched, void *rbuff, void *wbuff)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
27 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
28 int i,j;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
29 double *t;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
30 int *count=rbuff;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
31
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
32 t = wbuff;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
33 double *result[NUM] = { t, t+3, t+6 };
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
34 for (i=0; i<NUM; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
35 for (j=0; j<NUM; j++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
36 if (i==j) result[i][j] = 1.0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
37 else result[i][j] = 0.0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
38 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
39 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
40
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
41 t = (double*)(count+1);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
42 double *base[NUM] = { t, t+3, t+6 };
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
43 printf("count = %d\n", *count);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
44 printf("base = \n");
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
45 for (i=0; i<NUM; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
46 printf("%lf, %lf, %lf\n", base[i][0], base[i][1], base[i][2]);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
47 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
48
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
49 goto scheduler(tsched, taskA_1,rbuff,wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
50 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
51 __code
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
52 taskA_1(void *tsched, void *rbuff, void *wbuff)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
53 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
54 int i,j,k;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
55 int *count = rbuff;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
56 double *t;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
57 double prod[NUM][NUM];
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
58
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
59 t = (double*)(count+1);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
60 double *base[NUM] = { t, t+3, t+6 };
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
61 t = wbuff;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
62 double *result[NUM] = { t, t+3, t+6 };
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
63
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
64 if (*count <= 0) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
65 //__DEBUG("task end\n", *count);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
66 goto scheduler(tsched, taskA_2,rbuff,wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
67 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
68 for (i=0; i<NUM; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
69 for (j=0; j<NUM; j++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
70 prod[i][j] = 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
71 for (k=0; k<NUM; k++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
72 prod[i][j] += result[j][k] * base[k][i];
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
73 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
74 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
75 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
76 for (i=0; i<NUM; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
77 for (j=0; j<NUM; j++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
78 result[i][j] = prod[i][j];
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
79 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
80 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
81
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
82 //__DEBUG("count=%d\n", *count);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
83 (*count)--;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
84 goto scheduler(tsched, taskA_1, rbuff, wbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
85 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
86 __code
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
87 taskA_2(void *tsched, void *rbuff, void *wbuff)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
88 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
89 int i;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
90 double *t;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
91
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
92 t = wbuff;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
93 double *result[NUM] = { t, t+3, t+6 };
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
94 printf("result = \n");
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
95 for (i=0; i<NUM; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
96 printf("%lf, %lf, %lf\n", result[i][0], result[i][1], result[i][2]);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
97 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
98
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
99 goto scheduler(tsched, END,NULL,NULL);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
100 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
101 __code
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
102 task0(void *tsched, void *rbuff, void *wbuff)
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 int i,j;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 double *in = rbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 double *out = wbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 double a[NUM][NUM] = {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 { 1.0, 0.0, 0.0 },
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 { 0.0, 1.0, 0.0 },
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 { 0.0, 0.0, 1.0 },
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 };
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 for (i=0; i<NUM; i++) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 out[i] = 0.0;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 for (j=0; j<NUM; j++) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 out[i] += a[i][j] * in[j];
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 __DEBUG("\n");
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
119 __DEBUG("%p %p\n", rbuff, wbuff);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
120 __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
121 __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
122 //goto task1(scheduler, wbuff, rbuff);
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
123 goto scheduler(tsched, task1, wbuff, rbuff);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 __code
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
126 task1(void *tsched, void *rbuff, void *wbuff)
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 int i,j;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 double *in = rbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 double *out = wbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 double a[NUM][NUM] = {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 { 1.0, 0.0, 0.0 },
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
133 { 0.0, 2.0, 0.0 },
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
134 { 0.0, 0.0, 3.0 },
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 };
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 for (i=0; i<NUM; i++) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 out[i] = 0.0;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 for (j=0; j<NUM; j++) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 out[i] += a[i][j] * in[j];
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 __DEBUG("\n");
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
143 __DEBUG("%p %p\n", rbuff, wbuff);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
144 __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
145 __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]);
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
146 //goto task2(tsched, wbuff, rbuff);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
147 goto scheduler(tsched, task2, wbuff, rbuff);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 __code
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
150 task2(void *tsched, void *rbuff, void *wbuff)
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 int i,j;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 double *in = rbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 double *out = wbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 double a[NUM][NUM] = {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 { 1.0, 0.0, 0.0 },
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 { 0.0, 1.0, 0.0 },
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 { 0.0, 0.0, 1.0 },
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 };
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 for (i=0; i<NUM; i++) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 out[i] = 0.0;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 for (j=0; j<NUM; j++) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 out[i] += a[i][j] * in[j];
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 __DEBUG("\n");
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
167 __DEBUG("%p %p\n", rbuff, wbuff);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
168 __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
169 __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]);
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
170 goto scheduler(tsched, END, rbuff, wbuff);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
173 #include "TaskScheduler.h"
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 int
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 main(int argc, char **argv)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 __DEBUG("\n");
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 goto initScheduler(startcode, NULL);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 return 0;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
183 __code
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
184 startcode(void *tsched, void *arg) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
185 int i,j;
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
186 double *readbuff, *writebuff;
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
187 readbuff = malloc(sizeof(int)+sizeof(double)*NUM*NUM);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
188 writebuff = malloc(sizeof(double)*NUM*NUM);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
189
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
190 int *count = (int*)readbuff;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
191 double *t = (double*)(count+1);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
192 double *base[NUM] = { t, t+3, t+6 };
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
194 *count = 2;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
195 for (i=0; i<NUM; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
196 for (j=0; j<NUM; j++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
197 if (i==j) base[i][j] = 1.0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
198 else base[i][j] = 0.0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
199 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
200 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
201 base[0][0] = 2.0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
202 base[2][1] = 0.5;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
203
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
204 __DEBUG("id=0 added.\n");
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
205 goto addCode(tsched, 0, taskA_0, readbuff, writebuff);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 __code
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
209 checkNewCode(void *tsched, int wait)
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 {
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
211 static int t = 0;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
212 double *readbuff, *writebuff;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
213
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
214 if (wait) {
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
215 __DEBUG("all tasks finished\n");
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
216 exit(0);
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
217 }
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
218
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
219 /*
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
220 if (t==0) {
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
221 readbuff = malloc(sizeof(double)*NUM);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
222 writebuff = malloc(sizeof(double)*NUM);
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
223 t++;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
224 __DEBUG("id=1 added.\n");
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
225 goto addCode(tsched, 1, taskA, readbuff, writebuff);
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
226 }
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
227 */
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
228 __DEBUG("no code added.\n");
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
229 goto selectCode(tsched);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 __code
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
233 exitCode(void *tsched, int id)
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 {
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
235 __DEBUG("exit task%d\n", id);
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
236 goto selectCode(tsched);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 void *
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 allocate(size_t size)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 void *rtn = malloc (size);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 if (!rtn) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 perror("malloc");
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 exit(1);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 return rtn;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
252