changeset 807:3763d29f41a3

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 22 May 2010 18:21:13 +0900
parents 974cd68383b3 (current diff) 32584e896fe7 (diff)
children 8a6f1fa038de
files TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/kernel/ppe/TaskManagerImpl.h
diffstat 46 files changed, 972 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Func.h	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/Func.h	Sat May 22 18:21:13 2010 +0900
@@ -6,5 +6,7 @@
 
 enum {
 #include "RenderingGlobal.h"
+#include "global_alloc.h"
+#include "KeyID.h"
 };
 
--- a/Renderer/Engine/KeyStat.h	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/KeyStat.h	Sat May 22 18:21:13 2010 +0900
@@ -1,12 +1,6 @@
 #ifndef INCLUDED_KEY_STATUS
 #define INCLUDED_KEY_STATUS
 
-enum {
-    NONE,
-    HOLD,
-    PUSH,
-};
-
 // 可変長の構造体にする。
 // int で1つ送り bit field でやると
 struct key_stat {
--- a/Renderer/Engine/RenderingGlobal.h	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/RenderingGlobal.h	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,6 @@
+
+/*Light 用の global_alloc ID*/
+
+  Light,
+  LightSwitch,
+  LightSysSwitch,
--- a/Renderer/Engine/SgChange.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/SgChange.cc	Sat May 22 18:21:13 2010 +0900
@@ -12,7 +12,6 @@
 #include "Pad.h"
 #include "Application.h"
 #include "lindaapi.h"
-#include "global_alloc.h"
 
 static void post2runLoop(SchedTask *s, void *viewer, void *s1);
 static void post2run(SchedTask *s, void *viewer, void *s1);
--- a/Renderer/Engine/global_alloc.h	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/global_alloc.h	Sat May 22 18:21:13 2010 +0900
@@ -1,21 +1,11 @@
-#ifndef GLOBAL_ACCLOC_H
-#define GLOBAL_ACCLOC_H
 
 /*!
   global_alloc 用の ID
 
   should be auto genarated.
  */
-enum global_allocate_id {
 
   GLOBAL_TEXTURE_HASH,
   GLOBAL_TILE_LIST,
   KEY_STATUS,
   LOAD_ID,
-  Light,
-  LightSwitch,
-  LightSysSwitch,
-
-};
-
-#endif
--- a/Renderer/Engine/spe/DrawSpan.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/spe/DrawSpan.cc	Sat May 22 18:21:13 2010 +0900
@@ -6,7 +6,6 @@
 #include "viewer_types.h"
 #include "Func.h"
 #include "sys.h"
-#include "global_alloc.h"
 #include "SchedTask.h"
 #include "Tapestry.h"
 #include "SpanPack.h"
--- a/Renderer/Engine/spe/InitKey.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/spe/InitKey.cc	Sat May 22 18:21:13 2010 +0900
@@ -2,8 +2,8 @@
 #include <string.h>
 #include "InitKey.h"
 #include "Func.h"
-#include "global_alloc.h"
 #include "KeyStat.h"
+#include "SchedTask.h"
 
 SchedDefineTask(InitKey);
 
--- a/Renderer/Engine/spe/InitKey.h	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/spe/InitKey.h	Sat May 22 18:21:13 2010 +0900
@@ -1,7 +0,0 @@
-#ifndef INCLUDED_TASK_INIT_KEY
-#define INCLUDED_TASK_INIT_KEY
-
-#include "SchedTask.h"
-
-
-#endif
--- a/Renderer/Engine/spe/Load_Texture.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/spe/Load_Texture.cc	Sat May 22 18:21:13 2010 +0900
@@ -6,7 +6,6 @@
 #include "Load_Texture.h"
 #include "texture.h"
 #include "Func.h"
-#include "global_alloc.h"
 
 SchedDefineTask(LoadTexture);
 
--- a/Renderer/Engine/spe/UpdateKey.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/spe/UpdateKey.cc	Sat May 22 18:21:13 2010 +0900
@@ -1,7 +1,7 @@
 #include "TaskManager.h"
 #include "KeyStat.h"
 #include "UpdateKey.h"
-#include "global_alloc.h"
+#include "Func.h"
 
 SchedDefineTask(UpdateKey);
 
--- a/Renderer/Engine/task/DrawSpan.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Sat May 22 18:21:13 2010 +0900
@@ -6,7 +6,6 @@
 #include "viewer_types.h"
 #include "Func.h"
 #include "sys.h"
-#include "global_alloc.h"
 #include "SchedTask.h"
 #include "Tapestry.h"
 #include "SpanPack.h"
--- a/Renderer/Engine/task/InitKey.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/task/InitKey.cc	Sat May 22 18:21:13 2010 +0900
@@ -2,7 +2,6 @@
 #include <string.h>
 #include "InitKey.h"
 #include "Func.h"
-#include "global_alloc.h"
 #include "KeyStat.h"
 
 SchedDefineTask(InitKey);
--- a/Renderer/Engine/task/Load_Texture.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/task/Load_Texture.cc	Sat May 22 18:21:13 2010 +0900
@@ -3,7 +3,6 @@
 #include "Load_Texture.h"
 #include "texture.h"
 #include "Func.h"
-#include "global_alloc.h"
 #include "Tapestry.h"
 
 SchedDefineTask(LoadTexture);
--- a/Renderer/Engine/task/UpdateKey.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/task/UpdateKey.cc	Sat May 22 18:21:13 2010 +0900
@@ -1,7 +1,7 @@
 #include "TaskManager.h"
 #include "KeyStat.h"
 #include "UpdateKey.h"
-#include "global_alloc.h"
+#include "Func.h"
 
 SchedDefineTask(UpdateKey);
 
--- a/Renderer/Engine/viewer.cc	Sat May 22 18:20:16 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Sat May 22 18:21:13 2010 +0900
@@ -12,7 +12,6 @@
 #include "Pad.h"
 #include "Application.h"
 #include "lindaapi.h"
-#include "global_alloc.h"
 
 static void post2runLoop(SchedTask *s,void *viewer,void *s1);
 static void post2runDraw(SchedTask *s,void *viewer,void *s1);
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.cc	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.cc	Sat May 22 18:21:13 2010 +0900
@@ -26,6 +26,7 @@
 
 HTaskPtr TaskManagerImpl::create_task(int cmd) {return 0;}
 HTaskPtr TaskManagerImpl::create_task(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws) { return 0; }
+HTask * TaskManagerImpl::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) {return 0;}
 void TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) {}
 void TaskManagerImpl::spawn_task(HTaskPtr) {}
 void TaskManagerImpl::set_task_cpu(HTaskPtr, CPU_TYPE) {}
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.h	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.h	Sat May 22 18:21:13 2010 +0900
@@ -21,6 +21,7 @@
     void show_profile();
     HTaskPtr create_task(int cmd);
     HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size);
+    HTaskPtr create_task_array(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws);
     void set_task_depend(HTaskPtr master, HTaskPtr slave);
     void spawn_task(HTaskPtr);
     void set_task_cpu(HTaskPtr, CPU_TYPE);
--- a/TaskManager/Makefile.def	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/Makefile.def	Sat May 22 18:21:13 2010 +0900
@@ -29,8 +29,8 @@
 
 ABIBIT = 32
 
-OPT = #-O9 
-OPT =  -g
+OPT = -O9 
+#OPT =  -g
 
 CC     = g++   
 CFLAGS = -Wall `sdl-config --cflags` -m$(ABIBIT)   $(OPT)
--- a/TaskManager/kernel/ppe/TaskManager.h	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/kernel/ppe/TaskManager.h	Sat May 22 18:21:13 2010 +0900
@@ -21,6 +21,8 @@
     /* user function */
     HTaskPtr create_task(int cmd);
     HTaskPtr create_task(int cmd, memaddr r, long rs, memaddr w, long ws);
+    HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData);
+
     void run();
     void *allocate(int size);
     void set_TMend(void (*endf)(TaskManager *manager));
@@ -36,9 +38,6 @@
     void init();
     void finish();
 
-    HTask *create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData);
-
-
 private:
     int machineNum;
 };
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/kernel/ppe/TaskManagerImpl.h	Sat May 22 18:21:13 2010 +0900
@@ -47,7 +47,6 @@
     virtual HTaskPtr create_task(int cmd);
     virtual HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size);
     virtual HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData);
-
     virtual void set_task_depend(HTaskPtr master, HTaskPtr slave);
     virtual void spawn_task(HTaskPtr);
     virtual void set_task_cpu(HTaskPtr, CPU_TYPE);
--- a/TaskManager/kernel/schedule/SchedTask.cc	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.cc	Sat May 22 18:21:13 2010 +0900
@@ -261,9 +261,10 @@
     return manager->create_task(cmd,r,rs,w,ws);
 }
 
-HTaskPtr 
-SchedTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) {
-    return manager->create_task_array(id, num_task, num_param, num_inData, num_outData) ;
+HTaskPtr
+SchedTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData)
+{
+  return manager->create_task_array(id, num_task, num_param, num_inData, num_outData);
 }
 
 
--- a/TaskManager/kernel/schedule/SchedTask.h	Sat May 22 18:20:16 2010 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.h	Sat May 22 18:21:13 2010 +0900
@@ -94,7 +94,7 @@
     // user
     HTaskPtr create_task(int cmd);
     HTaskPtr create_task(int cmd, memaddr r, long rs, memaddr w, long ws);
-    HTask *create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData);
+    HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData);
 
     void set_task_depend(HTaskPtr master, HTaskPtr slave);
     void spawn_task(HTaskPtr);
--- a/example/word_count/spe/Exec.cc	Sat May 22 18:20:16 2010 +0900
+++ b/example/word_count/spe/Exec.cc	Sat May 22 18:21:13 2010 +0900
@@ -12,6 +12,7 @@
     char *i_data = (char*)s->get_input(rbuf, 0);
     unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
     int length = (int)s->get_param(0);
+    //int length = s->read_size();
     int word_flag = 1-(int)s->get_param(1); 
     //int word_flag = (int)s->get_param(1); 
     int word_num = 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/Func.h	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,12 @@
+enum {
+#include "SysTasks.h"
+    TASK_EXEC,
+    RUN_TASK_BLOCKS,
+    TASK_PRINT,
+    RUN_FINISH,
+};
+
+#define DATA_NUM 12
+#define ADD_NUM 26
+
+#define DATA_ID 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/Makefile	Sat May 22 18:21:13 2010 +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_count_run16array/Makefile.cell	Sat May 22 18:21:13 2010 +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_count_run16array/Makefile.def	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,18 @@
+TARGET = word_count
+
+# include/library path
+# ex  macosx
+#CERIUM = /Users/gongo/Source/Cerium
+
+# ex  linux/ps3
+CERIUM = ../../../Cerium
+
+
+OPT =  -O9
+#OPT =  -g
+
+CC      = g++
+CFLAGS  =  -Wall $(OPT) 
+
+INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L${CERIUM}/TaskManager
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/Makefile.linux	Sat May 22 18:21:13 2010 +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_count_run16array/Makefile.macosx	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,37 @@
+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`
+CC += -m32
+
+.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_count_run16array/README	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,59 @@
+/*
+ * $Id: README,v 1.3 2008/10/20 08:49:52 gongo Exp $
+ */
+
+- 
+Task ΰ¸طꤹ
+
+ढä
+
+ idata Ȥ ( length*2)
+
+Exec:   idata  length ʬƼꡢǤͤû
+        Ⱦʬʬ뤿ᡢϤΥ 2 Ĥ˸ꡣ
+        ޤ3İʾǤ⤤ɤ͡
+
+Print:  idata ɽ롣
+
+
+¸طȤƤϡޤ Exec ˼¹ԤʤȤʤΤ
+
+------------> 
+
+Exec 1 
+       \ 
+         Print
+       /
+Exec 2
+
+
+ߤʴ
+ΰ¸ꤷʤȡPrint  Exec1,2 ׻
+idata ӤǤޤǽ롣
+
+
+- ¹ˡ
+
+% ./dependency [-cpu spe_num] [-nodepend]
+
+  -cpu       SPU ο
+  -nodepend  Exec  Print ˰¸ꤷʤ
+
+
+- ¹
+
+%./dependency
+[TASK_PRINT]
+13 13 13 13 13 13 13 13 13 13 13 13 26 26 26 26 26 26 26 26 26 26 26 26
+
+%./dependency -nodepend
+[TASK_PRINT]
+ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
+
+ξ硢Exec 1, 2 ν̤ PPE  idata ˽񤭹ޤ
+Print  idata  DMA ǥǡäƤɽƤ뤿
+ 0 ˤʤäƤ롣
+ΥƱ SPE Ǽ¹ԤƤȤơ
+Exec 1, 2 ΤȡPrint  DMA read ¹Ԥ
+Exec 1, 2  DMA write ѤǤФ⤷ǡ뤫⤷ʤ
+֤⤷פǤϻȤΤˤʤʤΤǡ¸ꤹ櫓Ǥ
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/WordCount.h	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,19 @@
+
+typedef struct wordCount {
+    struct wordCount *self;
+    int size;             // remaining file size
+    int division_size;    // for each word count task
+    int division_out_size;    
+    int out_size;    
+    int task_num;         // remaining task count
+    int task_blocks;      // spawn task one at a time
+    int status_num; 
+    int task_spwaned;
+    unsigned long long *o_data;
+    unsigned long long *head_tail_flag;
+    int out_task_num;
+    int pad; 
+    char * file_mmap;
+    HTaskPtr t_print;
+} WordCount;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/main.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,243 @@
+#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 "SchedTask.h"
+#include "Func.h"
+#include "WordCount.h"
+
+extern void task_init();
+
+const char *usr_help_str = "Usage: ./word_count [-cpu spe_num] [-file filename]\n";
+
+typedef struct {
+    caddr_t file_mmap;
+    off_t size;
+} st_mmap_t;
+
+
+
+/*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/
+static 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;
+}
+
+
+static st_mmap_t
+my_mmap(char *filename)
+{
+
+    /*マッピングだよ!*/
+    int fd = -1;
+    int map = MAP_PRIVATE;
+    st_mmap_t st_mmap;
+    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をページングサイズの倍数にあわせる*/
+    st_mmap.size = fix_byte(sb.st_size,4096);
+
+    printf("fix 4096byte file size %d\n",(int)st_mmap.size);
+
+    st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0);
+    if (st_mmap.file_mmap == (caddr_t)-1) {
+	fprintf(stderr,"Can't mmap file\n");
+	perror(NULL);
+	exit(0);
+    }
+
+    return st_mmap;
+
+}
+
+static void
+run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) 
+{
+  
+  int array_task_num = 8;
+  if (task_count < array_task_num) {
+    array_task_num = task_count;
+  }
+  
+  for (int i = 0; i < task_count; i += array_task_num) {
+        
+    HTask *task_array = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1);
+    t_next->wait_for(task_array);
+    
+    Task *t_exec = 0;
+    for (int j = 0; j < array_task_num; j++) {
+	int i = w->task_spwaned++;
+
+	t_exec = task_array->next_task_array(TASK_EXEC,t_exec);
+	t_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
+	t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
+	t_exec->set_param(0,size);
+	
+	w->size -= size;
+	w->task_num--;
+    }
+
+    task_array->spawn_task_array(t_exec->next());
+    task_array->set_cpu(SPE_ANY);
+    task_array->spawn();
+  } 
+}
+
+SchedDefineTask1(RUN_TASK_BLOCKS,run16);
+
+static int
+run16(SchedTask *manager, void *in, void *out)
+{
+    WordCount *w = *(WordCount **)in;
+   
+    if (w->task_num < w->task_blocks) {
+	if (w->size >= w->division_size) 
+	    run_tasks(manager,w,w->task_num, w->t_print, w->division_size);
+	while (w->size>0) 
+	    run_tasks(manager,w,1, w->t_print, w->size);
+	// printf("run16 last %d\n",w->task_num);
+    } else {
+	HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS,
+	    (memaddr)&w->self,sizeof(memaddr),0,0);
+	w->t_print->wait_for(t_next);
+
+	run_tasks(manager,w, w->task_blocks, t_next, w->division_size);
+
+	t_next->spawn();
+	// printf("run16 next %d\n",w->task_num);
+    }
+    return 0;
+}
+
+
+static int blocks = 48;
+static int division = 16; // in Kbyte
+static int profile = 0;
+
+static void
+run_start(TaskManager *manager, char *filename)
+{
+    HTaskPtr t_print;
+
+    st_mmap_t st_mmap;
+    st_mmap = my_mmap(filename);
+    WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
+    // bzero(w,sizeof(WordCount));
+
+    w->self = w;
+    w->task_blocks = blocks;
+    w->task_spwaned = 0;
+
+    /*sizeはdivision_sizeの倍数にしている。*/
+    w->size = st_mmap.size;
+    w->file_mmap = st_mmap.file_mmap;
+
+    /* 1task分のデータサイズ(byte) */
+    if (w->size >= 1024*division) {
+	w->division_size = 1024 * division;/*16kbyte*/
+    } else {
+	w->division_size = w->size;
+    }
+
+    printf("dvision_size %d\n",w->division_size);
+
+    /* "word num" and "line num" */
+    w->status_num = 2;
+    /* taskの数 */
+    w->task_num = w->size / w->division_size;
+    w->task_num = w->task_num + (w->division_size*w->task_num < w->size);
+    int out_task_num = w->task_num;
+
+    w->out_task_num = out_task_num;
+    printf("task_num %d\n",w->task_num);
+    printf("out_task_num %d\n",w->out_task_num);
+
+    /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */
+
+    w->division_out_size = sizeof(unsigned long long)*4;
+    int out_size = w->division_out_size*out_task_num;
+    w->o_data = (unsigned long long *)manager->allocate(out_size);
+    w->out_size = 4;
+    printf("out size %d\n",out_size);
+
+    /*各SPEの結果を合計して出力するタスク*/
+
+    t_print = manager->create_task(TASK_PRINT,
+	(memaddr)&w->self,sizeof(memaddr),0,0);
+
+    w->t_print = t_print;
+
+    for(int i = 0;i<1;i++) {
+	/* Task を task_blocks ずつ起動する Task */
+        /* serialize されていると仮定する... */
+	HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
+	    (memaddr)&w->self,sizeof(memaddr),0,0);
+	t_print->wait_for(t_exec);
+	t_exec->spawn();
+    }
+
+    t_print->spawn();
+}
+
+static char*
+init(int argc, char **argv)
+{
+    
+    char *filename = 0;
+    
+    for (int i = 1; argv[i]; ++i) {	
+	if (strcmp(argv[i], "-file") == 0) {
+	    filename = argv[i+1];
+	} else if (strcmp(argv[i], "-division") == 0) {
+	    division = atoi(argv[i+1]);
+	} else if (strcmp(argv[i], "-block") == 0) {
+	    blocks = atoi(argv[i+1]);
+	} else if (strcmp(argv[i], "-p") == 0) {
+	    profile = 1;
+	}
+    }
+    if (filename==0) {
+        printf("usage: %s [-block 10] -file filename\n",argv[0]);
+	exit(1);
+    }
+    
+    return filename;
+}
+
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+
+    char *filename = 0;
+    filename = init(argc, argv);
+    
+    if (filename < 0) {
+	return -1;
+    }
+
+    task_init();
+    run_start(manager, filename);
+
+    return 0;
+}
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/ppe/Exec.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,45 @@
+#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 *)rbuf;
+    unsigned long long *o_data = (unsigned long long*)wbuf;
+    unsigned long long *head_tail_flag = o_data +2;
+    int length = (int)s->get_param(0);
+    int word_flag = 0;
+    int word_num = 0;
+    int line_num = 0;
+    int i = 0;
+    
+    head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A);
+    word_num -= 1-head_tail_flag[0];
+
+    for (; i < length; i++) {
+	if (i_data[i] == 0x20) {
+	    word_flag = 1;
+	} else if (i_data[i] == 0x0A) {
+	    line_num += 1;
+	    word_flag = 1;
+	} else {
+	    word_num += word_flag;
+	    word_flag = 0;
+	}
+    }
+
+    word_num += word_flag;
+    head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A);
+
+    // s->printf("SPE word %d line %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_count_run16array/ppe/Exec.h	Sat May 22 18:21:13 2010 +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_count_run16array/ppe/Print.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include <string.h>
+#include "Print.h"
+#include "Func.h"
+#include "WordCount.h"
+
+/* これは必須 */
+SchedDefineTask1(Print,run_print);
+
+static int
+run_print(SchedTask *s, void *rbuf, void *wbuf)
+{
+    WordCount *w = *(WordCount**)rbuf;
+    unsigned long long *idata = w->o_data;
+    // long task_num = w->task_num;
+    long status_num = w->status_num;
+    int out_task_num = w->out_task_num;
+
+    /*
+     *  head_flag
+     *  o_data[0]
+     *  o_data[1]
+     *
+     */
+    unsigned long long word_data[2];
+
+    int flag_cal_sum = 0;
+    //printf("pad %d\n",pad);
+
+
+    /* head_tail_flag : task = 2 : 1
+     *
+     *    head_tail_flag[2]
+     *  ___________ __________
+     * |           |          |
+     * | head_flag | tail_fag | 
+     * |___________|__________|
+     *      [0]         [1] 
+     * 
+     * |----------------------|
+     *    unsigned long long 
+     *          16byte
+     *
+     * 配列先頭の head_flag はみない
+     * 配列末尾の tail_flag はみない
+     * 担当範囲前の末尾文字が「改行と、スペース以外」(tail_flag = 1)で、
+     * 担当範囲の先頭文字が「改行とスペース」(head_flag = 0)の場合
+     * 単語数を +1  することで、整合性がとれる。
+     *
+     * ex.
+     *    task_num 4
+     *    head_tail_flag[8]
+     *
+     *      0   1   2   3   4   5   6   7
+     *     ___ ___ ___ ___ ___ ___ ___ ___ 
+     *    | h | t | h | t | h | t | h | t |
+     *    |___|___|___|___|___|___|___|___|
+     *        |-------|-------|-------| 
+     *           比較    比較    比較
+     *
+     */
+
+    s->printf("start sum\n");
+
+    for (int i = 0; i < status_num; i++) {
+	word_data[i] = 0;
+    }
+
+    for (int i = 0; i < out_task_num ; i++) {
+	word_data[0] += idata[i*w->out_size+0];
+	word_data[1] += idata[i*w->out_size+1];
+	unsigned long long *head_tail_flag = 
+		       &idata[i*w->out_size+2];
+        if((i!=out_task_num-1)&&
+           (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) {
+	    flag_cal_sum++;
+        }
+    }
+
+    word_data[0] += flag_cal_sum;
+
+    for (int i = status_num-1; i >=0; i--) {
+	s->printf("%llu ",word_data[i]);
+    }
+
+    //printf("j = %d\n",j);
+
+
+    s->printf("\n");
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/ppe/Print.h	Sat May 22 18:21:13 2010 +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_count_run16array/ppe/RunFinish.cc	Sat May 22 18:21:13 2010 +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_count_run16array/ppe/RunFinish.h	Sat May 22 18:21:13 2010 +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_count_run16array/ppe/task_init.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,22 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+/* 必ずこの位置に書いて */
+SchedExternTask(Print);
+SchedExternTask(Exec);
+SchedExternTask(RUN_TASK_BLOCKS);
+SchedExternTask(RunFinish);
+
+/**
+ * この関数は ../spe/spe-main と違って
+ * 自分で呼び出せばいい関数なので
+ * 好きな関数名でおk (SchedRegisterTask は必須)
+ */
+void
+task_init(void)
+{
+    SchedRegisterTask(TASK_PRINT, Print);
+    SchedRegisterTask(TASK_EXEC, Exec);
+    SchedRegister(RUN_TASK_BLOCKS);
+    SchedRegisterTask(RUN_FINISH, RunFinish);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/spe/Exec.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,45 @@
+#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 *)rbuf;
+    unsigned long long *o_data = (unsigned long long*)wbuf;
+    unsigned long long *head_tail_flag = o_data +2;
+    int length = (int)s->get_param(0);
+    int word_flag = 0;
+    int word_num = 0;
+    int line_num = 0;
+    int i = 0;
+    
+    head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A);
+    word_num -= 1-head_tail_flag[0];
+
+    for (; i < length; i++) {
+	if (i_data[i] == 0x20) {
+	    word_flag = 1;
+	} else if (i_data[i] == 0x0A) {
+	    line_num += 1;
+	    word_flag = 1;
+	} else {
+	    word_num += word_flag;
+	    word_flag = 0;
+	}
+    }
+
+    word_num += word_flag;
+    head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A);
+
+    // s->printf("SPE word %d line %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_count_run16array/spe/Exec.cc.vector	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask(Exec);
+
+typedef char *cvector __attribute__ ((vector_size (16)));
+//   vectorize だと結果がよろしくない...
+//
+// typedef char *cvector;
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+#ifdef SIMPLE_TASK
+    cvector i_data = (cvector)rbuf;
+    char* i_data0 = (char*)rbuf;
+    unsigned long long *o_data = (unsigned long long*)wbuf;
+    unsigned long long *head_tail_flag = o_data +2;
+    int length = s->read_size();
+#else
+    cvector i_data = (cvector)s->get_input(rbuf, 0);
+    char* i_data0 = (char*)s->get_input(rbuf, 0);
+    unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
+    /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/
+    unsigned long long  *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1);
+    int length = (long)s->get_param(0);
+#endif
+
+    static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ;
+    cvector const space = (cvector)spaces;
+    static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
+    cvector const newline = (cvector)newlines;
+
+    int word_flag = 0;
+    int word_num = 0;
+    int line_num = 0;
+    int i = 0;
+    
+    /*文字なら1,スペースか改行なら0*/
+    char top = i_data0[0];
+    head_tail_flag[0] = ((top != 0x20) && (top != 0x0a));
+    word_num -= 1-head_tail_flag[0];
+
+    for (; i < length; i++) {
+	if (i_data[i] == space[i%16]) {
+	    //s->printf("スペース\n");
+	    word_flag = 1;
+	} else if (i_data[i] == newline[i%16]) {
+	    //s->printf("改行\n");
+	    line_num += 1;
+	    word_flag = 1;
+	} else {
+	    word_num += word_flag;
+	    word_flag = 0;
+	}
+    }
+
+    word_num += word_flag;
+    /*文字なら1,スペースか改行なら0*/
+    //printf("last word %c",i_data[i-1]);
+    char end = i_data0[i-1];
+    head_tail_flag[1] = ((end != 0x20) && (end != 0x0a));
+
+    // s->printf("SPU word %d line %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_count_run16array/spe/Exec.h	Sat May 22 18:21:13 2010 +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_count_run16array/spe/Makefile	Sat May 22 18:21:13 2010 +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  = -Wall -fno-exceptions -fno-rtti $(OPT) 
+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 *~ \#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/spe/Print.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include <string.h>
+#include "Print.h"
+#include "Func.h"
+#include "WordCount.h"
+
+/* これは必須 */
+SchedDefineTask1(Print,run_print);
+
+static int
+run_print(SchedTask *s, void *rbuf, void *wbuf)
+{
+    WordCount *w = *(WordCount**)rbuf;
+    unsigned long long *idata = w->o_data;
+    // long task_num = w->task_num;
+    long status_num = w->status_num;
+    int out_task_num = w->out_task_num;
+
+    /*
+     *  head_flag
+     *  o_data[0]
+     *  o_data[1]
+     *
+     */
+    unsigned long long word_data[2];
+
+    int flag_cal_sum = 0;
+    //printf("pad %d\n",pad);
+
+
+    /* head_tail_flag : task = 2 : 1
+     *
+     *    head_tail_flag[2]
+     *  ___________ __________
+     * |           |          |
+     * | head_flag | tail_fag | 
+     * |___________|__________|
+     *      [0]         [1] 
+     * 
+     * |----------------------|
+     *    unsigned long long 
+     *          16byte
+     *
+     * 配列先頭の head_flag はみない
+     * 配列末尾の tail_flag はみない
+     * 担当範囲前の末尾文字が「改行と、スペース以外」(tail_flag = 1)で、
+     * 担当範囲の先頭文字が「改行とスペース」(head_flag = 0)の場合
+     * 単語数を +1  することで、整合性がとれる。
+     *
+     * ex.
+     *    task_num 4
+     *    head_tail_flag[8]
+     *
+     *      0   1   2   3   4   5   6   7
+     *     ___ ___ ___ ___ ___ ___ ___ ___ 
+     *    | h | t | h | t | h | t | h | t |
+     *    |___|___|___|___|___|___|___|___|
+     *        |-------|-------|-------| 
+     *           比較    比較    比較
+     *
+     */
+
+    s->printf("start sum\n");
+
+    for (int i = 0; i < status_num; i++) {
+	word_data[i] = 0;
+    }
+
+    for (int i = 0; i < out_task_num ; i++) {
+	word_data[0] += idata[i*w->out_size+0];
+	word_data[1] += idata[i*w->out_size+1];
+	unsigned long long *head_tail_flag = 
+		       &idata[i*w->out_size+2];
+        if((i!=out_task_num-1)&&
+           (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) {
+	    flag_cal_sum++;
+        }
+    }
+
+    word_data[0] += flag_cal_sum;
+
+    for (int i = status_num-1; i >=0; i--) {
+	s->printf("%llu ",word_data[i]);
+    }
+
+    //printf("j = %d\n",j);
+
+
+    s->printf("\n");
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count_run16array/spe/Print.h	Sat May 22 18:21:13 2010 +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_count_run16array/spe/spe-main.cc	Sat May 22 18:21:13 2010 +0900
@@ -0,0 +1,16 @@
+#include "Func.h"
+#include "SchedTask.h"
+
+SchedExternTask(Print);
+SchedExternTask(Exec);
+
+/**
+ * この関数は SpeScheduler から呼ばれるので
+ * 必ずこの関数名でお願いします。
+ */
+void
+task_init(Scheduler *s)
+{
+    SchedRegisterTask(TASK_PRINT, Print);
+    SchedRegisterTask(TASK_EXEC, Exec);
+}