changeset 527:7d9d209bdc82

add word_count3
author yutaka@henri.cr.ie.u-ryukyu.ac.jp
date Tue, 20 Oct 2009 16:28:16 +0900
parents 214cd21049e0
children fb8ed646feb8
files example/word_count3/Func.h example/word_count3/Makefile example/word_count3/Makefile.cell example/word_count3/Makefile.def example/word_count3/Makefile.linux example/word_count3/Makefile.macosx example/word_count3/README example/word_count3/main.cc example/word_count3/ppe/Exec.cc example/word_count3/ppe/Exec.h example/word_count3/ppe/Hello.cc example/word_count3/ppe/Hello.h example/word_count3/ppe/Print.cc example/word_count3/ppe/Print.h example/word_count3/ppe/RunFinish.cc example/word_count3/ppe/RunFinish.h example/word_count3/ppe/Wait.cc example/word_count3/ppe/Wait.h example/word_count3/ppe/task_init.cc example/word_count3/spe/Exec.cc example/word_count3/spe/Exec.h example/word_count3/spe/Hello.cc example/word_count3/spe/Hello.h example/word_count3/spe/Makefile example/word_count3/spe/Print.cc example/word_count3/spe/Print.h example/word_count3/spe/Wait.cc example/word_count3/spe/Wait.h example/word_count3/spe/spe-main.cc
diffstat 29 files changed, 982 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/Func.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,8 @@
+enum {
+    HELLO_TASK = 0,
+    WAIT_TASK,
+    EXEC_TASK,
+    PRINT_TASK,
+};
+
+#define DATA_NUM 12
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/Makefile	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,20 @@
+default: macosx
+
+macosx: FORCE
+	@echo "Make for Mac OS X"
+	@$(MAKE) -f Makefile.macosx
+
+linux: FORCE
+	@echo "Make for Linux"
+	@$(MAKE) -f Makefile.linux
+
+cell: FORCE
+	@echo "Make for CELL (Cell)"
+	@$(MAKE) -f Makefile.cell
+
+FORCE:
+
+clean:
+	@$(MAKE) -f Makefile.macosx clean
+	@$(MAKE) -f Makefile.linux clean
+	@$(MAKE) -f Makefile.cell clean
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/Makefile.cell	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,39 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # 除外するファイルを書く
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lCellManager -lspe2 -lpthread -Wl,--gc-sections 
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET) speobject
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+speobject:
+	cd spe; $(MAKE)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo ppu-gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	cd spe; $(MAKE) clean
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/Makefile.def	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,14 @@
+TARGET = post
+
+# include/library path
+# ex: macosx
+#CERIUM = /Users/gongo/Source/Cerium
+
+# ex: linux/ps3
+CERIUM = ../../../Cerium
+
+CC      = g++
+CFLAGS  = -g -Wall -O9
+
+INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L${CERIUM}/TaskManager
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/Makefile.linux	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,36 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # 除外するファイルを書く
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	rm -f spe/*~ spe/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/Makefile.macosx	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,36 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # 除外するファイルを書く
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager `sdl-config --libs`
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	rm -f spe/*~ spe/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/README	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,53 @@
+/*
+ * $Id: README,v 1.2 2008/10/21 07:38:41 gongo Exp $
+ */
+
+- 概要
+
+基本的には HelloWorld と同じなんですが、
+Hello Task が終了すると、set_post で指定した関数を呼び出すようにしています。
+この関数を使えば、タスクが終了した事が検知できる。きっと多分。
+引数は void* のみです。特に問題はないと信じてます。
+
+API
+  set_post(void (*func)(void*), void *arg);
+
+func の実装
+  void
+  func(void *p) {}
+
+- 実行方法
+
+% ./post [-cpu CPU_NUM] [-count COUNT]
+
+  -cpu     使用する SPU の数です。
+  -count   表示する "Hello, World!!" の数。
+           正確には post_func を使って繰り返し呼ぶ Hello Task の数。
+
+- 実行例
+
+% ./post 
+Hello, World!! post_func output 1
+post function : 1
+
+% ./post -count 10
+Hello, World!! post_func output 10
+post function : 10
+Hello, World!! post_func output 9
+post function : 9
+Hello, World!! post_func output 8
+post function : 8
+Hello, World!! post_func output 7
+post function : 7
+Hello, World!! post_func output 6
+post function : 6
+Hello, World!! post_func output 5
+post function : 5
+Hello, World!! post_func output 4
+post function : 4
+Hello, World!! post_func output 3
+post function : 3
+Hello, World!! post_func output 2
+post function : 2
+Hello, World!! post_func output 1
+post function : 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/main.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,358 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "TaskManager.h"
+#include "Func.h"
+
+#define TASKBUFF (1)
+
+extern void task_init(void);
+
+static TaskManager *manager;
+
+static int count = 1;
+static char *file = NULL;
+
+const char *usr_help_str = "Usage: ./post [-cpu spe_num] [-count N]\n\
+  -count  Number of print \"Hello, World!!\"";
+
+
+struct task_list_t {
+  HTaskPtr task;
+  task_list_t *next;
+};
+
+typedef struct {
+  caddr_t file_mmap;
+  off_t size;
+} st_mmap_t;
+
+
+typedef struct {
+
+  /*16task罸冴綽荀紊*/
+  task_list_t *task_list;
+  HTaskPtr run_wait_task;
+  int *task_num;
+  int *sum_task_num;
+
+  /*data蚊綽荀紊*/
+  int *file_size;
+  int *division_size;
+  int *division_out_size;
+  int *status_num;
+  int *out_task_num;
+  int *out_size;
+  int *sum_i;
+  int *word_flag;
+  caddr_t file_mmap;
+  unsigned long long *o_data;
+  
+} data_list_t;
+
+/*筝sizefix_byte_size違(筝吾莨若c鐚)*/
+int
+fix_byte(int size,int fix_byte_size)
+{
+    size = (size/fix_byte_size)*fix_byte_size  + ((size%fix_byte_size)!= 0)*fix_byte_size;
+    
+    return size;
+}
+
+void
+create_data(char *filename, data_list_t *data)
+{
+
+  data->file_size = (int*)manager->allocate(sizeof(int));
+  data->division_size = (int*)manager->allocate(sizeof(int));
+  data->division_out_size = (int*)manager->allocate(sizeof(int));
+  data->status_num = (int*)manager->allocate(sizeof(int));
+  data->out_size = (int*)manager->allocate(sizeof(int));
+  data->out_task_num = (int*)manager->allocate(sizeof(int));
+  data->task_num = (int*)manager->allocate(sizeof(int));
+  data->sum_task_num = (int*)manager->allocate(sizeof(int));
+  data->sum_i = (int*)manager->allocate(sizeof(int));
+  *data->sum_i = 0;
+  data->word_flag = (int*)manager->allocate(sizeof(int));
+  *data->word_flag = 0;
+  data->run_wait_task = (HTaskPtr)manager->allocate(sizeof(HTask));
+  data->run_wait_task = manager->create_task(WAIT_TASK);
+
+
+
+  /*潟違!*/
+  int fd = -1;
+  int map = MAP_PRIVATE;
+  off_t size;
+  struct stat sb;
+  
+  if ((fd=open(filename,O_RDONLY,0666))==0) {
+    fprintf(stderr,"can't open %s\n",filename);
+    }
+  
+  if (fstat(fd,&sb)) {
+	fprintf(stderr,"can't fstat %s\n",filename);
+  }
+  
+  printf("file size %d\n",(int)sb.st_size);
+  
+  /*size若吾潟違泣ゃ冴違*/
+  size = fix_byte(sb.st_size,4096);
+  
+  printf("fix 4096byte file size %d\n",(int)size);
+  
+  data->file_mmap = (char*)mmap(NULL,size,PROT_READ,map,fd,(off_t)0);
+  if (data->file_mmap == (caddr_t)-1) {
+    fprintf(stderr,"Can't mmap file\n");
+    perror(NULL);
+    exit(0);
+    }
+  
+  if (size >= 4096*4) {
+    *data->division_size = 4096 * 4; /*16kbyte*/
+  }
+  else {
+    *data->division_size = size;
+  }
+  
+  *data->file_size = size;
+
+  /* status  2ゃс8 * 2 = 16; 8  unsinged long long*/
+  *data->division_out_size = 16;
+  
+  /*"word num" and "line num"*/
+  *data->status_num = 2;
+  *data->sum_task_num = size / (*data->division_size);
+
+  if (*data->sum_task_num < TASKBUFF) {
+    *data->task_num = *data->sum_task_num;
+  }
+  else {
+    *data->task_num = TASKBUFF;
+  }
+
+  *data->out_task_num = *data->sum_task_num + ( (*data->division_size) * (*data->sum_task_num) < size);
+  
+  *data->out_size = (*data->division_out_size) * (*data->out_task_num);
+  data->o_data = (unsigned long long*)manager->allocate(*data->out_size);
+  
+
+}
+
+void
+func2(void *p)
+{
+  data_list_t *data = (data_list_t*)p;
+
+  int in_off_set = 0;
+  int out_off_set = 0;
+
+  if (*data->file_size > 0) {
+
+    in_off_set = (*data->sum_i) * (*data->division_size);
+    out_off_set = (*data->sum_i) * (*data->status_num);
+    *data->division_size = *data->file_size;
+
+    HTaskPtr task = (HTaskPtr)manager->allocate(sizeof(HTask));
+    task = manager->create_task(EXEC_TASK);
+    task->add_inData(data->file_mmap + in_off_set, *data->division_size);
+    task->add_outData(data->o_data + out_off_set, *data->division_out_size);
+    task->add_param(*data->division_size);
+    task->add_param(*data->word_flag);
+    data->run_wait_task->wait_for(task);
+    task->set_cpu(SPE_ANY);
+    task->spawn();
+
+  }
+
+  data->run_wait_task->spawn();
+
+}
+
+void
+func1(void *p)
+{
+
+  /*receive*/
+  HTaskPtr wait_task = manager->create_task(WAIT_TASK);
+  data_list_t *data = (data_list_t*)p;
+
+
+  if (*data->sum_task_num < *data->task_num) {
+    *data->task_num = *data->sum_task_num;
+  }
+
+
+  /*run*/
+  task_list_t *t = data->task_list;
+
+  for (;t != NULL; t = t->next) {
+    wait_task->wait_for(t->task);
+    t->task->spawn();
+  }
+
+  task_list_t *now = NULL;
+  task_list_t *next = (task_list_t*)manager->allocate(sizeof(task_list_t));
+  next = NULL;
+
+  *data->sum_task_num -= *data->task_num;
+  if (*data->sum_task_num < TASKBUFF) {
+    *data->task_num =  *data->sum_task_num;
+  } else {
+    *data->task_num =  TASKBUFF;
+  }
+
+
+  /*for (int i = 0; i < *data->task_num; i++) {  
+
+    now = (task_list_t*)manager->allocate(sizeof(task_list_t));
+    now->task = (HTaskPtr)manager->allocate(sizeof(HTask));
+    now->task = manager->create_task(HELLO_TASK);
+    now->task->set_cpu(SPE_ANY);
+    now->next = next;
+
+    next = now;
+
+    }*/
+
+
+  int in_off_set = 0;
+  int out_off_set = 0;
+  char next_word = 0;
+
+  for (int i = 0; i < *data->task_num; i++) {  
+
+    in_off_set = (*data->sum_i) * (*data->division_size);
+    out_off_set = (*data->sum_i) * (*data->status_num);
+    next_word = data->file_mmap[(*data->sum_i + 1) * (*data->division_size) - 1];
+
+    now = (task_list_t*)manager->allocate(sizeof(task_list_t));
+    now->task = (HTaskPtr)manager->allocate(sizeof(HTask));
+    now->task = manager->create_task(EXEC_TASK);
+    now->task->add_inData(data->file_mmap + in_off_set, *data->division_size);
+    now->task->add_outData(data->o_data + out_off_set, *data->division_out_size);
+    now->task->add_param(*data->division_size);
+    now->task->add_param(*data->word_flag);
+    now->task->set_cpu(SPE_ANY);
+    now->next = next;
+
+    next = now;
+
+    *data->word_flag = ((next_word != 0x20) && (next_word != 0x0A));
+    *data->file_size -= *data->division_size;
+    *data->sum_i += 1;
+
+  }
+
+
+
+  data->task_list = now;
+  
+  
+  if (*data->sum_task_num > 0) {
+    wait_task->set_post(func1,p);
+  }
+
+  /* 鴻 task 腟篋緇ゃ*/
+  else {
+    wait_task->set_post(func2,p);
+  }
+
+  /* 16task 腟篋緇 */
+  wait_task->spawn();
+    
+}
+
+
+int
+init(int argc, char **argv)
+{
+    for (int i = 1; argv[i]; ++i) {
+	if (strcmp(argv[i], "-count") == 0) {
+            count = atoi(argv[++i]);
+        } else if (strcmp(argv[i], "-file") == 0) {
+	  file = argv[++i];
+	}
+
+
+    }
+
+    return 0;
+}
+
+void
+run_init(TaskManager *manager)
+{
+
+  data_list_t *data = (data_list_t*)manager->allocate(sizeof(data_list_t));;
+
+  /*data create from input file*/
+  create_data(file,data);
+
+  HTaskPtr t_print = manager->create_task(PRINT_TASK);
+  t_print->add_inData(data->o_data, *data->out_size);
+  t_print->add_param(*data->out_task_num);
+  t_print->add_param(*data->status_num);
+  t_print->wait_for(data->run_wait_task);
+
+  /*task create*/
+  task_list_t *now = NULL;
+  task_list_t *next = (task_list_t*)manager->allocate(sizeof(task_list_t));
+  next = NULL;
+
+  int in_off_set = 0;
+  int out_off_set = 0;
+  char next_word = 0;
+
+  for (int i = 0; i < *data->task_num; i++) {  
+
+    in_off_set = (*data->sum_i) * (*data->division_size);
+    out_off_set = (*data->sum_i) * (*data->status_num);
+    next_word = data->file_mmap[(*data->sum_i + 1) * (*data->division_size) - 1];
+
+    now = (task_list_t*)manager->allocate(sizeof(task_list_t));
+    now->task = (HTaskPtr)manager->allocate(sizeof(HTask));
+    now->task = manager->create_task(EXEC_TASK);
+    now->task->add_inData(data->file_mmap + in_off_set, *data->division_size);
+    now->task->add_outData(data->o_data + out_off_set, *data->division_out_size);
+    now->task->add_param(*data->division_size);
+    now->task->add_param(*data->word_flag);
+    now->task->set_cpu(SPE_ANY);
+    now->next = next;
+
+    next = now;
+
+    *data->word_flag = ((next_word != 0x20) && (next_word != 0x0A));
+    *data->file_size -= *data->division_size;
+    *data->sum_i += 1;
+
+  }
+
+  data->task_list = now;
+
+  func1((void*)data);
+
+  t_print->spawn();
+
+}
+
+int
+TMmain(TaskManager *manager_, int argc, char *argv[])
+{
+    manager = manager_;
+
+    if (init(argc, argv) < 0) {
+	return -1;
+    }
+
+    task_init();
+    run_init(manager);
+
+    return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Exec.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Exec);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    char *i_data = (char*)s->get_input(rbuf, 0);
+    unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
+    int length = s->get_param(0);
+    int word_flag = s->get_param(1);
+    int word_num = 0;
+    int line_num = 0;
+    int i;
+
+    /*絖障с蕋吟若*/
+    for(i = 0; i < length; i++) {
+	if ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) {
+	    //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]);
+	    break;
+	}
+	//s->printf("[SPE%d]%c",id,i_data[start_num]);
+	word_num += word_flag;
+	word_flag = 0;
+	line_num += (i_data[i] == 0x0A);
+    }
+
+    word_flag = 0;
+
+	for (; i < length; i++) {
+
+	    //s->printf("[SPE%d]%c",id,i_data[i]);
+
+	if((i_data[i] != 0x20) && (i_data[i] != 0x0A)) {
+	    //s->printf("絖  = %d\n", word_num + word_flag);
+	    word_num += word_flag;
+	    word_flag = 0;
+	}
+
+	if (i_data[i] == 0x20) {
+	    //printf("鴻若\n");
+	    word_flag = 1;
+	}
+
+	if (i_data[i] == 0x0A) {
+	    //printf("壕\n");
+	    line_num += 1;
+	    word_flag = 1;
+	}
+
+    }
+
+    word_num += word_flag;
+
+    //printf("%d %d\n",word_num,line_num);
+
+    o_data[0] = (unsigned long long)word_num;
+    o_data[1] = (unsigned long long)line_num;
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Exec.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Hello.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Hello.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Hello);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+
+    s->printf("Hello, World!!\n");
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Hello.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Print.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <string.h>
+#include "Print.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Print);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    unsigned long long *idata = (unsigned long long*)s->get_input(rbuf, 0);
+    int task_num = s->get_param(0);
+    int status_num = s->get_param(1);
+    unsigned long long word_data[task_num];
+
+    s->printf("start sum\n");
+
+    for (int i = 0; i < status_num; i++) {
+	word_data[i] = 0;
+    }
+
+    for (int i = 0; i < task_num*status_num; i += status_num) {
+	for (int j = 0; j < status_num; j++) {
+	    word_data[j] += idata[i+j];
+	}
+    }
+
+    for (int i = 0; i < status_num; i++) {
+	s->printf("%llu ",word_data[i]);
+    }
+
+    s->printf("\n");
+
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Print.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_PRINT
+#define INCLUDED_TASK_PRINT
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/RunFinish.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,10 @@
+#include "RunFinish.h"
+
+/* 綽 */
+SchedDefineTask(RunFinish);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{    
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/RunFinish.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_RUNFINISH
+#define INCLUDED_TASK_RUNFINISH
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Wait.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Wait.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Wait);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/Wait.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_WAIT
+#define INCLUDED_TASK_WAIT
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/ppe/task_init.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,22 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+/* 綽篏臀吾 */
+SchedExternTask(Print);
+SchedExternTask(Exec);
+SchedExternTask(Hello);
+SchedExternTask(Wait);
+
+/**
+ * ∽違 ../spe/spe-main c
+ * у若喝冴違∽違
+ * 絅純∽医сk (SchedRegisterTask 綽)
+ */
+void
+task_init(void)
+{
+    SchedRegisterTask(PRINT_TASK, Print);
+    SchedRegisterTask(EXEC_TASK, Exec);
+    SchedRegisterTask(HELLO_TASK, Hello);
+    SchedRegisterTask(WAIT_TASK, Wait);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Exec.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Exec);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    char *i_data = (char*)s->get_input(rbuf, 0);
+    unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
+    int length = s->get_param(0);
+    int word_flag = s->get_param(1);
+    int word_num = 0;
+    int line_num = 0;
+    int i;
+
+    /*絖障с蕋吟若*/
+    for(i = 0; i < length; i++) {
+	if ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) {
+	    //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]);
+	    break;
+	}
+	//s->printf("[SPE%d]%c",id,i_data[start_num]);
+	word_num += word_flag;
+	word_flag = 0;
+	line_num += (i_data[i] == 0x0A);
+    }
+
+    word_flag = 0;
+
+	for (; i < length; i++) {
+
+	    //s->printf("[SPE%d]%c",id,i_data[i]);
+
+
+	if (i_data[i] == 0x20) {
+	    //s->printf("鴻若\n");
+	    word_flag = 1;
+	}
+
+	else if (i_data[i] == 0x0A) {
+	    //s->printf("壕\n");
+	    line_num += 1;
+	    word_flag = 1;
+	}
+
+	else {
+	    word_num += word_flag;
+	    word_flag = 0;
+	}
+
+    }
+
+    word_num += word_flag;
+
+    //s->printf("%d %d\n",word_num,line_num);
+
+    o_data[0] = (unsigned long long)word_num;
+    o_data[1] = (unsigned long long)line_num;
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Exec.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Hello.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Hello.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Hello);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    printf("Hello, World!!\n");
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Hello.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Makefile	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,26 @@
+include ../Makefile.def
+
+TARGET = ../spe-main
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+CC      = spu-g++
+CFLAGS  = -g -Wall -fno-exceptions -fno-rtti #-DDEBUG
+INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L../${CERIUM}/TaskManager -lspemanager
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+clean:
+	rm -f $(TARGET) $(OBJS)
+	rm -f *~ \#*
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Print.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <string.h>
+#include "Print.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Print);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    unsigned long long *idata = (unsigned long long*)s->get_input(rbuf, 0);
+    int task_num = s->get_param(0);
+    int status_num = s->get_param(1);
+    unsigned long long word_data[task_num];
+
+    for (int i = 0; i < status_num; i++) {
+	word_data[i] = 0;
+    }
+
+    for (int i = 0; i < task_num*status_num; i += status_num) {
+	for (int j = 0; j < status_num; j++) {
+	    word_data[j] += idata[i+j];
+	}
+    }
+
+    for (int i = 0; i < status_num; i++) {
+	s->printf("%llu ",word_data[i]);
+    }
+
+    s->printf("\n");
+
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Print.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_PRINT
+#define INCLUDED_TASK_PRINT
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Wait.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Wait.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Wait);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/Wait.h	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_WAIT
+#define INCLUDED_TASK_WAIT
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count3/spe/spe-main.cc	Tue Oct 20 16:28:16 2009 +0900
@@ -0,0 +1,20 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+SchedExternTask(Hello);
+SchedExternTask(Wait);
+SchedExternTask(Exec);
+SchedExternTask(Print);
+
+/**
+ * ∽違 SpeScheduler 若違
+ * 綽∽医с蕁障
+ */
+void
+task_init(Scheduler *s)
+{
+  SchedRegisterTask(HELLO_TASK, Hello);
+  SchedRegisterTask(WAIT_TASK, Wait);
+  SchedRegisterTask(EXEC_TASK, Exec);
+  SchedRegisterTask(PRINT_TASK, Print);
+}