Mercurial > hg > Members > kent > CbCTaskManager
view 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 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "Task.h" #define __DEBUG(f, args...) \ fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) void * allocate (size_t size); __code taskA_0(void *tsched, void *rbuff, void *wbuff); __code taskA_1(void *tsched, void *rbuff, void *wbuff); __code taskA_2(void *tsched, void *rbuff, void *wbuff); __code task0 (void *tsched, void *rbuff, void *wbuff); __code task1 (void *tsched, void *rbuff, void *wbuff); __code task2 (void *tsched, void *rbuff, void *wbuff); int main (int argc, char **argv); __code startcode (void *tsched, void *arg); __code checkNewCode (void *tsched, int wait); __code exitCode (void *tsched, int id); void * allocate (size_t size); #define NUM 3 __code taskA_0(void *tsched, void *rbuff, void *wbuff) { int i,j; double *t; int *count=rbuff; t = wbuff; double *result[NUM] = { t, t+3, t+6 }; for (i=0; i<NUM; i++) { for (j=0; j<NUM; j++) { if (i==j) result[i][j] = 1.0; else result[i][j] = 0.0; } } t = (double*)(count+1); double *base[NUM] = { t, t+3, t+6 }; printf("count = %d\n", *count); printf("base = \n"); for (i=0; i<NUM; i++) { printf("%lf, %lf, %lf\n", base[i][0], base[i][1], base[i][2]); } goto scheduler(tsched, taskA_1,rbuff,wbuff); } __code taskA_1(void *tsched, void *rbuff, void *wbuff) { int i,j,k; int *count = rbuff; double *t; double prod[NUM][NUM]; t = (double*)(count+1); double *base[NUM] = { t, t+3, t+6 }; t = wbuff; double *result[NUM] = { t, t+3, t+6 }; if (*count <= 0) { //__DEBUG("task end\n", *count); goto scheduler(tsched, taskA_2,rbuff,wbuff); } for (i=0; i<NUM; i++) { for (j=0; j<NUM; j++) { prod[i][j] = 0; for (k=0; k<NUM; k++) { prod[i][j] += result[j][k] * base[k][i]; } } } for (i=0; i<NUM; i++) { for (j=0; j<NUM; j++) { result[i][j] = prod[i][j]; } } //__DEBUG("count=%d\n", *count); (*count)--; goto scheduler(tsched, taskA_1, rbuff, wbuff); } __code taskA_2(void *tsched, void *rbuff, void *wbuff) { int i; double *t; t = wbuff; double *result[NUM] = { t, t+3, t+6 }; printf("result = \n"); for (i=0; i<NUM; i++) { printf("%lf, %lf, %lf\n", result[i][0], result[i][1], result[i][2]); } goto scheduler(tsched, END,NULL,NULL); } __code task0(void *tsched, void *rbuff, void *wbuff) { int i,j; double *in = rbuff; double *out = wbuff; double a[NUM][NUM] = { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, }; for (i=0; i<NUM; i++) { out[i] = 0.0; for (j=0; j<NUM; j++) { out[i] += a[i][j] * in[j]; } } __DEBUG("\n"); __DEBUG("%p %p\n", rbuff, wbuff); __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]); __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]); //goto task1(scheduler, wbuff, rbuff); goto scheduler(tsched, task1, wbuff, rbuff); } __code task1(void *tsched, void *rbuff, void *wbuff) { int i,j; double *in = rbuff; double *out = wbuff; double a[NUM][NUM] = { { 1.0, 0.0, 0.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 0.0, 3.0 }, }; for (i=0; i<NUM; i++) { out[i] = 0.0; for (j=0; j<NUM; j++) { out[i] += a[i][j] * in[j]; } } __DEBUG("\n"); __DEBUG("%p %p\n", rbuff, wbuff); __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]); __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]); //goto task2(tsched, wbuff, rbuff); goto scheduler(tsched, task2, wbuff, rbuff); } __code task2(void *tsched, void *rbuff, void *wbuff) { int i,j; double *in = rbuff; double *out = wbuff; double a[NUM][NUM] = { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, }; for (i=0; i<NUM; i++) { out[i] = 0.0; for (j=0; j<NUM; j++) { out[i] += a[i][j] * in[j]; } } __DEBUG("\n"); __DEBUG("%p %p\n", rbuff, wbuff); __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]); __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]); goto scheduler(tsched, END, rbuff, wbuff); } #include "TaskScheduler.h" int main(int argc, char **argv) { __DEBUG("\n"); goto initScheduler(startcode, NULL); return 0; } __code startcode(void *tsched, void *arg) { int i,j; double *readbuff, *writebuff; readbuff = malloc(sizeof(int)+sizeof(double)*NUM*NUM); writebuff = malloc(sizeof(double)*NUM*NUM); int *count = (int*)readbuff; double *t = (double*)(count+1); double *base[NUM] = { t, t+3, t+6 }; *count = 2; for (i=0; i<NUM; i++) { for (j=0; j<NUM; j++) { if (i==j) base[i][j] = 1.0; else base[i][j] = 0.0; } } base[0][0] = 2.0; base[2][1] = 0.5; __DEBUG("id=0 added.\n"); goto addCode(tsched, 0, taskA_0, readbuff, writebuff); } __code checkNewCode(void *tsched, int wait) { static int t = 0; double *readbuff, *writebuff; if (wait) { __DEBUG("all tasks finished\n"); exit(0); } /* if (t==0) { readbuff = malloc(sizeof(double)*NUM); writebuff = malloc(sizeof(double)*NUM); t++; __DEBUG("id=1 added.\n"); goto addCode(tsched, 1, taskA, readbuff, writebuff); } */ __DEBUG("no code added.\n"); goto selectCode(tsched); } __code exitCode(void *tsched, int id) { __DEBUG("exit task%d\n", id); goto selectCode(tsched); } void * allocate(size_t size) { void *rtn = malloc (size); if (!rtn) { perror("malloc"); exit(1); } return rtn; }