view test/scheduler/test_sched.cbc @ 0:5b089096921f

first commit.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Dec 2009 21:57:05 +0900
parents
children aef83aed7a07
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>

#include "Task.h"
#include "TaskScheduler.h"

#define __DEBUG(f, args...) \
	fprintf(stderr, "in %s: "f, __FUNCTION__, ## args)

__code task1 (Scheduler scheduler, void *rbuff, void *wbuff);
__code task2 (Scheduler scheduler, void *rbuff, void *wbuff);
int main (int argc, char **argv);
__code startcode (void *arg);
__code checkNewCode ();
__code exitCode ();

void * allocate (size_t size);

#define NUM 3
__code
task0(Scheduler scheduler, 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");
	goto task1(scheduler, rbuff, wbuff);
}
__code
task1(Scheduler scheduler, 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");
	goto task2(scheduler, rbuff, wbuff);
}
__code
task2(Scheduler scheduler, 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");
	goto scheduler(END, rbuff, wbuff);
}


int
main(int argc, char **argv)
{
	__DEBUG("\n");
	goto initScheduler(startcode, NULL);

	return 0;
}

__code startcode(void *arg) {
	double *rbuff, *wbuff;
	rbuff = malloc(sizeof(double)*NUM);
	wbuff = malloc(sizeof(double)*NUM);

	goto addCode(0, task1, rbuff, wbuff);
}

__code
checkNewCode()
{
	__DEBUG("\n");
	goto selectCode();
}

__code
exitCode()
{
	__DEBUG("exit\n");
	exit(0);
}

void *
allocate(size_t size)
{
	void *rtn = malloc (size);
	if (!rtn) {
		perror("malloc");
		exit(1);
	}
	return rtn;
}