changeset 1201:dd52af319c40 draft

add regex/
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Thu, 14 Jul 2011 18:53:40 +0900
parents 7b866a392adc
children 4fc2e027077e
files .hgignore example/regex/Makefile.def.orig example/regex/Makefile.def~ example/regex/Makefile.macosx.orig example/regex/Makefile.macosx~ example/regex/WordCount.h.orig example/regex/WordCount.h~ example/regex/main.cc.orig example/regex/main.cc~ example/regex/ppe/Exec.cc.orig example/regex/ppe/Exec.cc~ example/regex/ppe/Print.cc.orig example/regex/ppe/Print.cc~
diffstat 13 files changed, 1929 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Jul 14 18:51:10 2011 +0900
+++ b/.hgignore	Thu Jul 14 18:53:40 2011 +0900
@@ -9,6 +9,11 @@
 GSYMS
 GPATH
 
+Renderer/*
+
+example/*
+TaskManager/*
+
 
 syntax: regexp
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/regex/Makefile.def.orig	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,19 @@
+TARGET = grep
+
+# include/library path
+# ex  macosx
+#CERIUM = /Users/gongo/Source/Cerium
+ABIBIT=64
+
+# ex  linux/ps3
+CERIUM = ../../../Cerium
+
+
+#OPT =  -O9
+OPT =  -g -O0
+
+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/regex/Makefile.def~	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,23 @@
+<<<<<<< local
+TARGET = grep
+=======
+TARGET = word_count
+>>>>>>> other
+
+# include/library path
+# ex  macosx
+#CERIUM = /Users/gongo/Source/Cerium
+ABIBIT=64
+
+# ex  linux/ps3
+CERIUM = ../../../Cerium
+
+
+#OPT =  -O9
+OPT =  -g -O0
+
+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/regex/Makefile.macosx.orig	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,37 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE = grep_main.cc # 除外するファイルを書く
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = switchGrep.cc
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager `sdl-config --libs`
+CC += -m$(ABIBIT)
+
+.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/regex/Makefile.macosx~	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,49 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+<<<<<<< local
+SRCS_EXCLUDE = grep_main.cc # 除外するファイルを書く
+=======
+SRCS_EXCLUDE =  # 除外するファイルを書く
+>>>>>>> other
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+<<<<<<< local
+TASK_SRCS_EXCLUDE = switchGrep.cc
+=======
+TASK_SRCS_EXCLUDE =
+>>>>>>> other
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager `sdl-config --libs`
+CC += -m$(ABIBIT)
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+<<<<<<< local
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+=======
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) 
+>>>>>>> other
+
+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/regex/WordCount.h.orig	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,27 @@
+
+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;
+    int file_size;
+    HTaskPtr t_print;
+
+
+  bool print_count;
+  bool print_filename;
+  int count;
+  char *filename;
+} WordCount, ENV, *ENVP; 
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/regex/WordCount.h~	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,37 @@
+
+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;
+    int file_size;
+    HTaskPtr t_print;
+
+<<<<<<< local
+
+=======
+  //regexのENVの成分
+>>>>>>> other
+  bool print_count;
+  bool print_filename;
+  int count;
+  char *filename;
+<<<<<<< local
+} WordCount, ENV, *ENVP; 
+
+
+=======
+}WordCount;
+  //} WordCount, ENV;
+//typedef ENV *ENVP;
+>>>>>>> other
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/regex/main.cc.orig	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,510 @@
+#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 "grep.h"
+
+
+
+extern void task_init();
+
+int all = 0;
+int use_task_array = 1;
+int use_task_creater = 0;
+int use_compat = 0;
+int array_task_num = 8;
+int spe_num = 1;
+
+const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n";
+
+typedef struct {
+    caddr_t file_mmap;
+    off_t size;
+} st_mmap_t;
+
+
+static void simple_task_creater(int in_total_size, int out_total_size, 
+			     int command, int in_data_size, int out_data_size, 
+			     void *in_data, void *out_data, SchedTask *manager,
+			     HTask *wait_i, HTask *wait_me) {
+
+
+  int in_task_size = 0;
+  int out_task_size = 0;
+
+  if (in_total_size != 0) {
+    in_task_size = in_total_size / in_data_size;
+    if (in_total_size != in_task_size * in_data_size) {
+      printf("mismatch of in_total_size and in_data_size\n");
+    }
+  }
+
+  if (out_total_size != 0) {
+    out_task_size = out_total_size / out_data_size;
+    if (out_total_size != out_task_size * out_data_size) {
+      printf("mismatch of out_total_size and out_data_size\n");
+    }
+  }
+ 
+  /*in, out の大きい方に合わせるのがいいかな? Taskの数は1Task分に使うデータの大きいほうを取るような仕様がいいかな*/
+  int task_num = (in_task_size > out_task_size) ? in_task_size : out_task_size;
+
+  if (task_num == 0) task_num = 1;
+
+  /*spe分あればいいのかな?*/
+
+  int array_num = spe_num;
+  if (task_num < array_num) {
+    array_num = task_num;
+  }
+
+
+  HTaskPtr *task_array = (HTask**)manager->allocate(sizeof(HTask*)*array_num);
+  TaskPtr *t_exec = (Task**)manager->allocate(sizeof(Task*)*array_num);
+
+  int array_length = task_num / array_num;
+  int rest = task_num % array_num;
+
+  int index = 0;
+  
+  for (int k = 0; k < array_num; k++) {
+
+    task_array[k] = manager->create_task_array(command,array_length,0,1,1);
+    t_exec[k] = 0;
+    
+    if (wait_me != 0) {
+      wait_me->wait_for(task_array[k]);
+    }
+    if (wait_i != 0) {
+      task_array[k]->wait_for(wait_i);
+    }
+    
+  }
+
+  for (int j = 0; j < array_length; j++) {
+    for (int k = 0; k < array_num; k++) {
+      
+      t_exec[k] = task_array[k]->next_task_array(command,t_exec[k]);
+      t_exec[k]->set_inData(0,(char*)in_data + index*in_data_size, in_data_size);
+      t_exec[k]->set_outData(0,(char*)out_data + index*out_data_size, out_data_size);
+
+      index++;
+
+    }
+  }
+  
+  for (int k = 0; k < array_num; k++) {
+    task_array[k]->spawn_task_array(t_exec[k]->next());
+    task_array[k]->set_cpu(SPE_ANY);
+    task_array[k]->spawn();
+  }	
+
+  for (int k = 0; k < rest; k++) {
+    HTaskPtr t_exec = manager->create_task(command);
+    
+    t_exec->set_inData(0,(char*)in_data + index*in_data_size, in_data_size);
+    t_exec->set_outData(0,(char*)out_data + index*out_data_size, out_data_size);
+      
+    index++;
+
+    if (wait_me != 0) {
+      wait_me->wait_for(t_exec);
+    }
+    if (wait_i != 0) {
+      t_exec->wait_for(wait_i);
+    }
+
+    t_exec->spawn();
+    t_exec->set_cpu(SPE_ANY);
+
+  }
+
+
+}
+
+
+/*与えられた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 unsigned char reg_num = 3;
+static bool first_line_flag = true;
+
+static void
+run_tasks(SchedTask *manager, ENV *w, int task_count, HTaskPtr t_next, int size) 
+{
+ 
+  if (task_count < array_task_num) {
+    array_task_num = task_count;
+    if (task_count<=0) return;
+  }
+
+  if (use_task_creater) {
+    simple_task_creater(w->file_size, w->division_out_size * w->task_num, TASK_EXEC, w->division_size, w->division_out_size,
+			w->file_mmap, w->o_data, manager, w->t_print, 0);
+  }
+
+  if (use_task_array) {
+
+    int spl = spe_num * array_task_num;
+    int loop = (task_count + spl - 1) / spl;
+
+    for (int i = 0; i < loop; i += 1) {
+
+      if (spl > w->task_num) {
+	if (w->task_num >= spe_num) {
+	  array_task_num = w->task_num / spe_num;
+	} else {
+
+	  int task_num = w->task_num;
+
+	  for (int j = 0; j < task_num; j++) {
+	    HTask *h_exec = 0;
+	    int i = w->task_spwaned++;
+
+	    if (w->size < size) size = w->size;
+
+	    h_exec = manager->create_task(TASK_EXEC,
+					  (memaddr)(w->file_mmap + i*w->division_size), size,
+					  (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
+	    
+	    if (all) {
+	      w->t_print->wait_for(h_exec);
+	    } else {
+	      t_next->wait_for(h_exec);
+	    }
+	    
+	    h_exec->set_cpu(SPE_ANY);
+	    h_exec->spawn();
+	    
+	    w->size -= size;
+	    w->task_num--;
+	    
+	  }
+
+	  return;
+	}
+      }
+      
+      
+      HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num);
+      Task **t_exec = (Task**)manager->allocate(sizeof(Task*)*spe_num);
+    
+      for (int k = 0; k < spe_num; k++) {
+	//	task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1);
+	task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,2,1);
+	t_exec[k] = 0;
+	if (all) {
+	  w->t_print->wait_for(task_array[k]);
+	} else {
+	  t_next->wait_for(task_array[k]);
+	}
+      }	
+      
+      
+      for (int j = 0; j < array_task_num; j++) {
+	for (int k = 0; k < spe_num; k++) {
+	  
+	  int a = w->task_spwaned++;
+	  
+	  if (w->size < size) size = w->size;
+
+	  t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]);
+	  if(first_line_flag) {
+	    t_exec[k]->set_inData(0, (w->file_mmap + a*w->division_size) - reg_num , size + reg_num );	    
+	    first_line_flag = false;
+	  }else {
+	    t_exec[k]->set_inData(0, w->file_mmap + a*w->division_size, size );
+	  }
+	  t_exec[k]->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
+
+	  t_exec[k]->set_inData(1, (ENV*)w, sizeof(ENV));
+
+	  w->size -= size;
+	  w->task_num--;
+	}
+      }
+      
+      for (int k = 0; k < spe_num; k++) {
+	task_array[k]->spawn_task_array(t_exec[k]->next());
+	task_array[k]->set_cpu(SPE_ANY);
+	task_array[k]->spawn();
+      }	
+      
+    }
+
+    return;
+
+  }
+  
+  
+  for (int i = 0; i < task_count; i += array_task_num) {
+
+    HTask *h_exec = 0;
+    for (int j = 0; j < array_task_num; j++) {
+	int i = w->task_spwaned++;
+	if (w->size < size) size = w->size;
+	if (size==0) break;
+
+	if (use_compat) {
+	    h_exec = manager->create_task(TASK_EXEC);
+	    h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
+	    h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
+
+
+	    if (all) {
+	      w->t_print->wait_for(h_exec);
+	    } else {
+	      t_next->wait_for(h_exec);
+	    }
+	    
+	    h_exec->set_cpu(SPE_ANY);
+	    h_exec->spawn();
+
+	} else {
+	    h_exec = manager->create_task(TASK_EXEC,
+		(memaddr)(w->file_mmap + i*w->division_size), size,
+		(memaddr)(w->o_data + i*w->out_size), w->division_out_size);
+
+	    if (all) {
+	      w->t_print->wait_for(h_exec);
+	    } else {
+	      t_next->wait_for(h_exec);
+	    }
+
+	    h_exec->set_cpu(SPE_ANY);
+	    h_exec->spawn();
+	}
+	w->size -= size;
+	w->task_num--;
+    }
+
+  }
+
+}
+
+/**
+ *   このTaskは、PPE上で実行されるので、並列に実行されることはない
+ *   二つ実行されていて、Task が足りなくなることがないようにしている。
+ */
+
+SchedDefineTask1(RUN_TASK_BLOCKS,run16);
+
+static int
+run16(SchedTask *manager, void *in, void *out)
+{
+    ENV *w = *(ENV **)in;
+   
+    if (w->task_num < w->task_blocks) {
+	// last case
+	if (w->size >= w->division_size) 
+	    run_tasks(manager,w,w->task_num, w->t_print, w->division_size);
+	// remaining data 
+	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 blocks = 31 * 6 * 24;
+static int division = 16; // in Kbyte
+
+static void
+run_start(TaskManager *manager, char *filename)
+{
+    HTaskPtr t_print;
+
+    st_mmap_t st_mmap;
+    st_mmap = my_mmap(filename);
+    ENV *w = (ENV*)manager->allocate(sizeof(ENV));
+
+    // ENV->filename 
+    w->filename = filename;
+
+    // bzero(w,sizeof(ENV));
+
+    w->self = w;
+    //w->task_blocks = blocks;
+    w->task_spwaned = 0;
+
+    /*sizeはdivision_sizeの倍数にしている。*/
+    w->size = w->file_size = st_mmap.size;
+    w->file_mmap = st_mmap.file_mmap;
+    //    printf("w %lx\n",(long)w);
+
+    /* 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;
+
+    if(!all) {
+        w->task_blocks = blocks;
+    } else {
+        w->task_blocks = 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(4byte)を使用 */
+
+    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<20;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], "-a") == 0) {
+	    // create task all at once
+	    all = 1;
+	} else if (strcmp(argv[i], "-c") == 0) {
+	    use_task_array = 0;
+	    use_compat = 1;
+	} else if (strcmp(argv[i], "-s") == 0) {
+	    use_task_array = 0;
+	    use_compat = 0;
+	} else if (strcmp(argv[i], "-t") == 0) {
+	    use_task_creater = 1;
+	    use_task_array = 0;
+	    use_compat = 0;
+	} else if (strcmp(argv[i], "-anum") == 0) {
+	    array_task_num = atoi(argv[i+1]);
+	} else if (strcmp(argv[i], "-cpu") == 0) {
+	    spe_num = atoi(argv[i+1]);
+	    if (spe_num==0) spe_num = 1;
+	}
+    }
+    if (filename==0) {
+        puts(usr_help_str);
+	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/regex/main.cc~	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,590 @@
+#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"
+<<<<<<< local
+#include "grep.h"
+
+
+=======
+#include "WordCount.h"
+>>>>>>> other
+
+extern void task_init();
+<<<<<<< local
+
+=======
+#define _REGENUM_ 3
+>>>>>>> other
+int all = 0;
+int use_task_array = 1;
+int use_task_creater = 0;
+int use_compat = 0;
+int array_task_num = 8;
+int spe_num = 1;
+
+const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n";
+
+typedef struct {
+    caddr_t file_mmap;
+    off_t size;
+} st_mmap_t;
+
+
+static void simple_task_creater(int in_total_size, int out_total_size, 
+			     int command, int in_data_size, int out_data_size, 
+			     void *in_data, void *out_data, SchedTask *manager,
+			     HTask *wait_i, HTask *wait_me) {
+
+
+  int in_task_size = 0;
+  int out_task_size = 0;
+
+  if (in_total_size != 0) {
+    in_task_size = in_total_size / in_data_size;
+    if (in_total_size != in_task_size * in_data_size) {
+      printf("mismatch of in_total_size and in_data_size\n");
+    }
+  }
+
+  if (out_total_size != 0) {
+    out_task_size = out_total_size / out_data_size;
+    if (out_total_size != out_task_size * out_data_size) {
+      printf("mismatch of out_total_size and out_data_size\n");
+    }
+  }
+ 
+  /*in, out の大きい方に合わせるのがいいかな? Taskの数は1Task分に使うデータの大きいほうを取るような仕様がいいかな*/
+  int task_num = (in_task_size > out_task_size) ? in_task_size : out_task_size;
+
+  if (task_num == 0) task_num = 1;
+
+  /*spe分あればいいのかな?*/
+
+  int array_num = spe_num;
+  if (task_num < array_num) {
+    array_num = task_num;
+  }
+
+
+  HTaskPtr *task_array = (HTask**)manager->allocate(sizeof(HTask*)*array_num);
+  TaskPtr *t_exec = (Task**)manager->allocate(sizeof(Task*)*array_num);
+
+  int array_length = task_num / array_num;
+  int rest = task_num % array_num;
+
+  int index = 0;
+  
+  for (int k = 0; k < array_num; k++) {
+
+    task_array[k] = manager->create_task_array(command,array_length,0,1,1);
+    t_exec[k] = 0;
+    
+    if (wait_me != 0) {
+      wait_me->wait_for(task_array[k]);
+    }
+    if (wait_i != 0) {
+      task_array[k]->wait_for(wait_i);
+    }
+    
+  }
+
+  for (int j = 0; j < array_length; j++) {
+    for (int k = 0; k < array_num; k++) {
+      
+      t_exec[k] = task_array[k]->next_task_array(command,t_exec[k]);
+      t_exec[k]->set_inData(0,(char*)in_data + index*in_data_size, in_data_size);
+      t_exec[k]->set_outData(0,(char*)out_data + index*out_data_size, out_data_size);
+
+      index++;
+
+    }
+  }
+  
+  for (int k = 0; k < array_num; k++) {
+    task_array[k]->spawn_task_array(t_exec[k]->next());
+    task_array[k]->set_cpu(SPE_ANY);
+    task_array[k]->spawn();
+  }	
+
+  for (int k = 0; k < rest; k++) {
+    HTaskPtr t_exec = manager->create_task(command);
+    
+    t_exec->set_inData(0,(char*)in_data + index*in_data_size, in_data_size);
+    t_exec->set_outData(0,(char*)out_data + index*out_data_size, out_data_size);
+      
+    index++;
+
+    if (wait_me != 0) {
+      wait_me->wait_for(t_exec);
+    }
+    if (wait_i != 0) {
+      t_exec->wait_for(wait_i);
+    }
+
+    t_exec->spawn();
+    t_exec->set_cpu(SPE_ANY);
+
+  }
+
+
+}
+
+
+/*与えられた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);
+    }
+
+<<<<<<< local
+    //    printf("file size %d\n",(int)sb.st_size);
+=======
+    printf("file size %d\n",(int)sb.st_size);
+>>>>>>> other
+   
+    /*sizeをページングサイズの倍数にあわせる*/
+    st_mmap.size = fix_byte(sb.st_size,4096);
+
+<<<<<<< local
+    //    printf("fix 4096byte file size %d\n",(int)st_mmap.size);
+=======
+    printf("fix 4096byte file size %d\n",(int)st_mmap.size);
+>>>>>>> other
+
+    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;
+
+}
+
+<<<<<<< local
+static unsigned char reg_num = 3;
+static bool first_line_flag = true;
+
+=======
+>>>>>>> other
+static void
+<<<<<<< local
+run_tasks(SchedTask *manager, ENV *w, int task_count, HTaskPtr t_next, int size) 
+=======
+run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) 
+>>>>>>> other
+{
+ 
+  if (task_count < array_task_num) {
+    array_task_num = task_count;
+    if (task_count<=0) return;
+  }
+
+  if (use_task_creater) {
+    simple_task_creater(w->file_size, w->division_out_size * w->task_num, TASK_EXEC, w->division_size, w->division_out_size,
+			w->file_mmap, w->o_data, manager, w->t_print, 0);
+  }
+
+  if (use_task_array) {
+
+    int spl = spe_num * array_task_num;
+    int loop = (task_count + spl - 1) / spl;
+
+    for (int i = 0; i < loop; i += 1) {
+
+      if (spl > w->task_num) {
+	if (w->task_num >= spe_num) {
+	  array_task_num = w->task_num / spe_num;
+	} else {
+
+	  int task_num = w->task_num;
+
+	  for (int j = 0; j < task_num; j++) {
+	    HTask *h_exec = 0;
+	    int i = w->task_spwaned++;
+
+	    if (w->size < size) size = w->size;
+
+	    h_exec = manager->create_task(TASK_EXEC,
+					  (memaddr)(w->file_mmap + i*w->division_size), size,
+					  (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
+	    
+	    if (all) {
+	      w->t_print->wait_for(h_exec);
+	    } else {
+	      t_next->wait_for(h_exec);
+	    }
+	    
+	    h_exec->set_cpu(SPE_ANY);
+	    h_exec->spawn();
+	    
+	    w->size -= size;
+	    w->task_num--;
+	    
+	  }
+
+	  return;
+	}
+      }
+      
+      
+      HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num);
+      Task **t_exec = (Task**)manager->allocate(sizeof(Task*)*spe_num);
+    
+      for (int k = 0; k < spe_num; k++) {
+<<<<<<< local
+	//	task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1);
+	task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,2,1);
+=======
+	task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1);
+>>>>>>> other
+	t_exec[k] = 0;
+	if (all) {
+	  w->t_print->wait_for(task_array[k]);
+	} else {
+	  t_next->wait_for(task_array[k]);
+	}
+      }	
+      
+      
+      for (int j = 0; j < array_task_num; j++) {
+	for (int k = 0; k < spe_num; k++) {
+	  
+	  int a = w->task_spwaned++;
+	  
+	  if (w->size < size) size = w->size;
+<<<<<<< local
+=======
+	  
+	  t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]);
+	  //	  t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size);
+	  //grepの為_REGENUM_分文字を被させる
+	  t_exec[k]->set_inData(0, (w->file_mmap + a*w->division_size) - _REGENUM_, size);
+	  //	  t_exec[k]->set_inData(1, w, sizeof(WordCount));
+>>>>>>> other
+
+<<<<<<< local
+	  t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]);
+	  if(first_line_flag) {
+	    t_exec[k]->set_inData(0, (w->file_mmap + a*w->division_size) - reg_num , size + reg_num );	    
+	    first_line_flag = false;
+	  }else {
+	    t_exec[k]->set_inData(0, w->file_mmap + a*w->division_size, size );
+	  }
+=======
+>>>>>>> other
+	  t_exec[k]->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
+<<<<<<< local
+
+	  t_exec[k]->set_inData(1, (ENV*)w, sizeof(ENV));
+
+=======
+	  
+>>>>>>> other
+	  w->size -= size;
+	  w->task_num--;
+	}
+      }
+      
+      for (int k = 0; k < spe_num; k++) {
+	task_array[k]->spawn_task_array(t_exec[k]->next());
+	task_array[k]->set_cpu(SPE_ANY);
+	task_array[k]->spawn();
+      }	
+      
+    }
+
+    return;
+
+  }
+  
+  
+  for (int i = 0; i < task_count; i += array_task_num) {
+
+    HTask *h_exec = 0;
+    for (int j = 0; j < array_task_num; j++) {
+	int i = w->task_spwaned++;
+	if (w->size < size) size = w->size;
+	if (size==0) break;
+
+	if (use_compat) {
+	    h_exec = manager->create_task(TASK_EXEC);
+	    h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
+	    h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
+
+
+	    if (all) {
+	      w->t_print->wait_for(h_exec);
+	    } else {
+	      t_next->wait_for(h_exec);
+	    }
+	    
+	    h_exec->set_cpu(SPE_ANY);
+	    h_exec->spawn();
+
+	} else {
+	    h_exec = manager->create_task(TASK_EXEC,
+		(memaddr)(w->file_mmap + i*w->division_size), size,
+		(memaddr)(w->o_data + i*w->out_size), w->division_out_size);
+
+	    if (all) {
+	      w->t_print->wait_for(h_exec);
+	    } else {
+	      t_next->wait_for(h_exec);
+	    }
+
+	    h_exec->set_cpu(SPE_ANY);
+	    h_exec->spawn();
+	}
+	w->size -= size;
+	w->task_num--;
+    }
+
+  }
+
+}
+
+/**
+ *   このTaskは、PPE上で実行されるので、並列に実行されることはない
+ *   二つ実行されていて、Task が足りなくなることがないようにしている。
+ */
+
+SchedDefineTask1(RUN_TASK_BLOCKS,run16);
+
+static int
+run16(SchedTask *manager, void *in, void *out)
+{
+<<<<<<< local
+    ENV *w = *(ENV **)in;
+=======
+    WordCount *w = *(WordCount **)in;
+>>>>>>> other
+   
+    if (w->task_num < w->task_blocks) {
+	// last case
+	if (w->size >= w->division_size) 
+	    run_tasks(manager,w,w->task_num, w->t_print, w->division_size);
+	// remaining data 
+	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 blocks = 31 * 6 * 24;
+static int division = 16; // in Kbyte
+
+static void
+run_start(TaskManager *manager, char *filename)
+{
+    HTaskPtr t_print;
+
+    st_mmap_t st_mmap;
+    st_mmap = my_mmap(filename);
+<<<<<<< local
+    ENV *w = (ENV*)manager->allocate(sizeof(ENV));
+
+    // ENV->filename 
+    w->filename = filename;
+
+    // bzero(w,sizeof(ENV));
+=======
+    WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
+    // bzero(w,sizeof(WordCount));
+>>>>>>> other
+
+    w->self = w;
+    //w->task_blocks = blocks;
+    w->task_spwaned = 0;
+
+    /*sizeはdivision_sizeの倍数にしている。*/
+    w->size = w->file_size = st_mmap.size;
+    w->file_mmap = st_mmap.file_mmap;
+<<<<<<< local
+    //    printf("w %lx\n",(long)w);
+=======
+    printf("w %lx\n",(long)w);
+>>>>>>> other
+
+    /* 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;
+
+<<<<<<< local
+=======
+
+
+    // grepする時にかぶせる文字分をdivisionに追加
+    w->division_size += _REGENUM_;
+    // regexのENVの設定
+    w->print_count = false;
+    w->print_filename = false;
+    w->count = 0;
+    w->filename = filename;
+    
+
+>>>>>>> other
+    if(!all) {
+        w->task_blocks = blocks;
+    } else {
+        w->task_blocks = w->task_num;
+    }
+
+    w->out_task_num = out_task_num;
+    printf("task_num %d\n",w->task_num);
+<<<<<<< local
+    //    printf("out_task_num %d\n",w->out_task_num);
+=======
+    printf("out_task_num %d\n",w->out_task_num);
+>>>>>>> other
+
+    /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */
+
+    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);
+<<<<<<< local
+    /*
+=======
+>>>>>>> other
+    w->out_size = 4;
+    printf("out size %d\n",out_size);
+<<<<<<< local
+    */
+=======
+>>>>>>> other
+
+    /*各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<20;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], "-a") == 0) {
+	    // create task all at once
+	    all = 1;
+	} else if (strcmp(argv[i], "-c") == 0) {
+	    use_task_array = 0;
+	    use_compat = 1;
+	} else if (strcmp(argv[i], "-s") == 0) {
+	    use_task_array = 0;
+	    use_compat = 0;
+	} else if (strcmp(argv[i], "-t") == 0) {
+	    use_task_creater = 1;
+	    use_task_array = 0;
+	    use_compat = 0;
+	} else if (strcmp(argv[i], "-anum") == 0) {
+	    array_task_num = atoi(argv[i+1]);
+	} else if (strcmp(argv[i], "-cpu") == 0) {
+	    spe_num = atoi(argv[i+1]);
+	    if (spe_num==0) spe_num = 1;
+	}
+    }
+    if (filename==0) {
+        puts(usr_help_str);
+	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/regex/ppe/Exec.cc.orig	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,229 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+#include "WordCount.h"
+
+/* これは必須 */
+SchedDefineTask(Exec);
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+UCHARP get_word_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == ' ') return p+1;
+  }
+  return beg;
+}
+
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = (UCHARP)memchr(buf, key[0], end-buf))) {
+    for(i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s2(beg, buf, end, env);
+    break;
+  default:
+    return s1(beg, buf, end, env);
+    break;
+  }
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s4(beg, buf, end, env);
+    break;
+  default:
+    return s3(beg, buf, end, env);
+    break;
+  }
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s2(beg, buf, end, env);
+    break;
+  case 115:
+    return s5(beg, buf, end, env);
+    break;
+  default:
+    return s1(beg, buf, end, env);
+    break;
+  }
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s2(beg, buf, end, env);
+    break;
+  case 115:
+    return s5(beg, buf, end, env);
+    break;
+  default:
+    return s3(beg, buf, end, env);
+    break;
+  }
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  //  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, ' ', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    //    beg = get_line_beg(buf, beg);
+    beg = get_word_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      //      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+      ret = (UCHARP)memchr(buf, ' ', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
+
+
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+  //    char *i_data = (char *)rbuf;
+    char *i_data = (char *)s->get_input(rbuf, 0);
+    int length = (int)s->get_inputSize(0);
+
+    WordCount *env = (WordCount*)s->get_input(rbuf, 1);
+
+    UCHARP beg, buf, end;
+    beg = buf = (UCHARP)i_data;
+    end = beg + length - 1;
+    
+    s0(beg, buf, end, (ENVP)env);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/regex/ppe/Exec.cc~	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,287 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+<<<<<<< local
+#include "WordCount.h"
+=======
+#include "grep.c"
+>>>>>>> other
+
+/* これは必須 */
+SchedDefineTask(Exec);
+
+<<<<<<< local
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+UCHARP get_word_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == ' ') return p+1;
+  }
+  return beg;
+}
+
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = (UCHARP)memchr(buf, key[0], end-buf))) {
+    for(i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s2(beg, buf, end, env);
+    break;
+  default:
+    return s1(beg, buf, end, env);
+    break;
+  }
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s4(beg, buf, end, env);
+    break;
+  default:
+    return s3(beg, buf, end, env);
+    break;
+  }
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s2(beg, buf, end, env);
+    break;
+  case 115:
+    return s5(beg, buf, end, env);
+    break;
+  default:
+    return s1(beg, buf, end, env);
+    break;
+  }
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP c = buf++;
+  if (buf > end) return reject(beg, buf, end, env);
+  switch(*c) {
+  case 10:
+    return reject(beg, buf, end, env);
+  case 104:
+    return s2(beg, buf, end, env);
+    break;
+  case 115:
+    return s5(beg, buf, end, env);
+    break;
+  default:
+    return s3(beg, buf, end, env);
+    break;
+  }
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  //  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, ' ', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    //    beg = get_line_beg(buf, beg);
+    beg = get_word_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      //      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+      ret = (UCHARP)memchr(buf, ' ', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
+
+
+
+=======
+>>>>>>> other
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+<<<<<<< local
+  //    char *i_data = (char *)rbuf;
+    char *i_data = (char *)s->get_input(rbuf, 0);
+=======
+    char *i_data = (char *)rbuf;
+    unsigned long long *o_data = (unsigned long long*)wbuf;
+    unsigned long long *head_tail_flag = o_data +2;
+>>>>>>> other
+    int length = (int)s->get_inputSize(0);
+<<<<<<< local
+=======
+    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];
+>>>>>>> other
+
+<<<<<<< local
+    WordCount *env = (WordCount*)s->get_input(rbuf, 1);
+=======
+    /*
+    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;
+	}
+    }
+    */
+    unsigned char *beg, *buf, *end;
+    beg = buf = (unsigned char*)rbuf;
+    end = beg + length;
+    ENVP env = malloc(sizeof(ENVP));
+    filter(beg, buf, end, env);
+>>>>>>> other
+
+<<<<<<< local
+    UCHARP beg, buf, end;
+    beg = buf = (UCHARP)i_data;
+    end = beg + length - 1;
+=======
+>>>>>>> other
+    
+<<<<<<< local
+    s0(beg, buf, end, (ENVP)env);
+=======
+
+    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;
+>>>>>>> other
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/regex/ppe/Print.cc.orig	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,17 @@
+#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)
+{
+
+    ENV *w = *(WordCount**)rbuf;
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/regex/ppe/Print.cc~	Thu Jul 14 18:53:40 2011 +0900
@@ -0,0 +1,99 @@
+#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)
+{
+<<<<<<< local
+=======
+    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;
+>>>>>>> other
+
+<<<<<<< local
+    ENV *w = *(WordCount**)rbuf;
+=======
+    /*
+     *  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");
+>>>>>>> other
+
+    return 0;
+}