Mercurial > hg > Members > kono > Cerium
view TaskManager/Test/Sum/main.cpp @ 298:58fd16298954
from EUC to UTF-8
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 07 Jun 2009 15:17:41 +0900 |
parents | 31a7ff27ee20 |
children |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include "TaskManager.h" #define MAX 1024 TaskManager *manager; int sum(void*, void*); int sum2(void*, void*); int data[MAX] __attribute__((aligned(16))); int buff[MAX] __attribute__((aligned(16))); int out[MAX] __attribute__((aligned(16))); int sum(void *wbuf, void *rbuf) { int *ret = (int*)wbuf; int *data = (int*)rbuf; int i; *ret = 0; for (i = 0; i < 16; i++) { *ret += data[i]; } return sizeof(int); } int sum2(void *wbuf, void *rbuf) { int *ret = (int*)wbuf; int *data = (int*)rbuf; int i; *ret = 0; for (i = 0; i < 64; i++) { *ret += data[i*4]; } return sizeof(int); } int init2(void *w, void *r) { int i, fd; int div = MAX/16; HTaskPtr *task = new HTaskPtr[div]; HTaskPtr last; for (i = 0; i < MAX; i++) { data[i] = i; } memset(buff, 0, sizeof(int)*1024); memset(out, 0, sizeof(int)*1024); fd = manager->open("Sum"); for (i = 0; i < div; i++) { task[i] = manager->create_task(fd, sizeof(int)*16, (unsigned int)&data[i*16], (unsigned int)&buff[i*4], NULL); } fd = manager->open("Sum2"); last = manager->create_task(fd, sizeof(int)*256, (unsigned int)buff, (unsigned int)&out[0], NULL); for (i = 0; i < div; i++) { manager->set_task_depend(task[i], last); } for (i = 0; i < div; i++) { manager->spawn_task(task[i]); } manager->spawn_task(last); return 0; } int result(void *w, void *r) { printf("manager : %d\n", out[0]); out[0] = 0; for (int i = 0; i < MAX; i++) { out[0] += i; } printf("for : %d\n", out[0]); return 0; } int init(void *w, void *r) { HTaskPtr init_task; HTaskPtr finish_task; int fd; fd = manager->open("Init2"); init_task = manager->create_task(fd, 0, 0, 0, NULL); manager->spawn_task(init_task); fd = manager->open("Result"); finish_task = manager->create_task(fd, 0, 0, 0, NULL); manager->set_task_depend(init_task, finish_task); manager->spawn_task(finish_task); return 0; } int main(void) { manager = new TaskManager(1); manager->init(); // ここは user 側で書かない...のか? // 設定ファイルかなにかで読むとか?違うな // あと、void* って書くのめんどくせ manager->set_symbol("Init", (void*)init); manager->set_symbol("Init2", (void*)init2); manager->set_symbol("Result", (void*)result); manager->set_symbol("Sum", (void*)sum); manager->set_symbol("Sum2", (void*)sum2); manager->set_init_task("Init"); manager->run(); manager->finish(); delete manager; return 0; }