changeset 1250:c41f10c1e138 draft

merge
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Fri, 11 Nov 2011 18:07:53 +0900
parents fd9b7519a17b (current diff) 8bc038529958 (diff)
children 6da91e7cbffb
files example/Eratosthenes/ppe/.#Hello.cc
diffstat 51 files changed, 1280 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Fri Nov 11 18:05:47 2011 +0900
+++ b/.hgtags	Fri Nov 11 18:07:53 2011 +0900
@@ -8,3 +8,4 @@
 b2b4a1243961a6e6c78c51fbc9d036a24dd52a68 simple-task-regression
 89689d1fb8cc40ce1ae57dd8ea19f5358200e714 before-simple-task
 7763f03a94e1ad475710eac4f5c2210e7db649ea before-dma-manager
+cd50c48f45e7696f3a9767b15ba4f5760958eb47 real_matrix
--- a/Renderer/Engine/task/CreatePolygon.cc	Fri Nov 11 18:05:47 2011 +0900
+++ b/Renderer/Engine/task/CreatePolygon.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -1,5 +1,9 @@
 #include "CreatePolygon.h"
 
+/*
+ * This program is not used 2011/11/11
+ */
+
 SchedDefineTask(CreatePolygon);
 
 static void
--- a/Renderer/Engine/task/CreatePolygon.h	Fri Nov 11 18:05:47 2011 +0900
+++ b/Renderer/Engine/task/CreatePolygon.h	Fri Nov 11 18:07:53 2011 +0900
@@ -1,3 +1,7 @@
+/*
+ * This program is not used 2011/11/11
+ */
+
 #ifndef INCLUDED_CREATE_SPAN
 #define INCLUDED_CREATE_SPAN
 
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Fri Nov 11 18:05:47 2011 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -1,4 +1,7 @@
 /**
+ * SceneGraphを読み込んでpolygonの座標に変換行列を掛けて
+ * 実座標のpolygonを生成する。
+ *
  * SceneGraph が増えてくると動かなくなるかもしれない。
  * 一応 mainMem とかで動くようになるとは思うけど。
  * だめだったら、そこら辺が怪しいと思うべき
@@ -10,7 +13,7 @@
 
 #define  STATUS_NUM 3
 
-SchedDefineTask(CreatePolygonFromSceneGraph);
+SchedDefineTask1(CreatePolygonFromSceneGraph,createPolygon);
 
 /**
  *  ベクトルに行列を乗算する
@@ -62,7 +65,7 @@
 
 
 static int 
-run(SchedTask *smanager, void *rbuf, void *wbuf)
+createPolygon(SchedTask *smanager, void *rbuf, void *wbuf)
 {
 
     /*
@@ -78,7 +81,11 @@
     //pp, matrix, real_matrix を受け取る
     PolygonPackPtr in_pp      = (PolygonPackPtr)smanager->get_input(rbuf, 0);
     float *matrix             = (float*)smanager->get_input(rbuf, 1);
-    float *real_matrix        = (float*)smanager->get_input(rbuf, 2);
+    float real_matrix[16]; //        = (float*)smanager->get_input(rbuf, 2);
+
+    for (int i = 0; i<16; i++) real_matrix[i]=matrix[i];
+    real_matrix[4*0+3]=real_matrix[4*1+3]=real_matrix[4*2+3]=0;
+     
     texture_list *tritexinfo  = (texture_list*)smanager->get_input(rbuf, 3);
     
     PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0);
--- a/SceneGraph/BlenderScript/export_xml3.py	Fri Nov 11 18:05:47 2011 +0900
+++ b/SceneGraph/BlenderScript/export_xml3.py	Fri Nov 11 18:07:53 2011 +0900
@@ -26,15 +26,10 @@
 ######################################################
 
 import math
-#import subprocess
 import os
-#import Blender
 import struct
 import base64
 import bpy
-#from Blender import NMesh, Scene, Object, Material, Texture, Window
-#from Blender import sys as bsys, Mathutils, Draw, BGL
-#from Blender.sys import *
 
 global anim
 anim = 0
@@ -84,7 +79,6 @@
 
 #exporting an anime
 ###change
-#def export_anime(object_name):
 def export_anime(object_name,file):
 	startF = Blender.Get('staframe')
 	endF = Blender.Get('endframe')
@@ -128,7 +122,6 @@
 
 # exporting a mesh
 ##change
-#def exportMesh(mesh, obj):
 def exportMesh(mesh, obj, file):
 
 	vdata = []   # list of [ii0, ii1, ii2, ...] lists indexed by Blender-Vertex-index
@@ -169,9 +162,7 @@
 	###change
 	def getFaces():
 		##change
-		#str = ""
 		file.write("")
-		# matrix = obj.matrix
 		# already calcurated?
 		matrix = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
 
@@ -182,14 +173,11 @@
 				if parent_name:
 					parent_name = "{0:s}".format(parent_name)
 					###change
-					#str += "\t<surface name=\"{0:s}\" size=\"{0:d}\" prim=\"Triangle\" parent={0:s}>\n".format((obj.name, len(fl)*3, parent_name[8:-1])
 					file.write("\t<surface name=\"{0:s}\" size=\"{1:d}\" prim=\"Triangle\" parent={2:s}>\n".format(obj.name, len(fl)*3, parent_name[8:-1]))
 				else:
 					###change
-					#str += "\t<surface name=\"{0:s}\" size=\"{0:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format((obj.name, len(fl)*3)
 					file.write("\t<surface name=\"{0:s}\" size=\"{1:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format(obj.name, len(fl)*3))
 				###change
-				#str += "\t\t<coordinate>\n"
 				file.write("\t\t<coordinate>\n")
 				for f in fl:
 					tri_first = vlist[f[0]]
@@ -233,17 +221,23 @@
 
 
 				### get texture_image and change base64 data
-				#texture = mesh.faces[0].image
 				texture = None
-				if mesh.uv_texture_stencil:
+				if mesh.uv_texture_stencil and  mesh.uv_texture_stencil.data.values() != []:
 					texture = mesh.uv_texture_stencil.data[0].image
 				if texture:
-					file.write(loadTexture(texture.name))	
+					file.write(loadTexture(texture))
 				else:
 					file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png"))
+					#sample_whited = 0 
+					#if (sample_whited == 0):
+					file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n")
+					file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n")
+					#sample_whited=1
 					file.write("\t\t</image>\n")
 
-		#return str
+					
+
+
 
 	vdata = []
 	vlist = []
@@ -258,13 +252,9 @@
 			else:
 				normal = face.normal
 			uvs = []
-			if mesh.uv_texture_stencil:
-				uv_texture = mesh.uv_texture_stencil.data[face.index]
-				uvs = [uv_texture.uv1, uv_texture.uv2, uv_texture.uv3, uv_texture.uv4]
-			print(len(uvs))
-			print(" ")
-			print(len(face.vertices))
-			print("\n")
+			if mesh.uv_texture_stencil and mesh.uv_texture_stencil.data.values() != []:
+				uv_tex = mesh.uv_texture_stencil.data[face.index]
+				uvs = [uv_tex.uv1, uv_tex.uv2, uv_tex.uv3, uv_tex.uv4]
 			if len(uvs) == len(face.vertices):
 				uv = uvs[vi]
 			else:
@@ -281,21 +271,22 @@
 
 	#return str
 	
-sample_whited = 0
+
 
-def make_material_chunk(material, image, file):
-	if image:
-		file.write(loadTexture(image))	
-	else:
-		file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png"))
-		global sample_whited
-		if (sample_whited == 0):
-
-		    file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
-		    file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
-		    sample_whited=1
-
-		file.write("\t\t</image>\n")
+#sample_whited = 0
+# don't call this method#
+#def make_material_chunk(material, image, file):
+#	if image:
+#		file.write(loadTexture(image))
+#	else:
+#		file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png"))
+#		global sample_whited
+#		if (sample_whited == 0):
+#		    file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
+#		    file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
+#		    sample_whited=1
+#
+#		file.write("\t\t</image>\n")
 
 ######################################################
 # EXPORT
@@ -347,32 +338,25 @@
 		if derived == None: continue
 
 		for ob_derived, mat in derived:
-#               for ob_derived, mat in getDerivedObjects(ob, False):
-
 			if ob.type not in ('MESH', 'CURVE', 'SURFACE', 'TEXT', 'META'):
 				continue
 
-			data = ob_derived.to_mesh(sce, True, 'PREVIEW')
-#			data = bpy.data.meshes[ob_derived.name]
-			data.uv_texture_stencil = bpy.data.meshes[ob_derived.name].uv_texture_stencil
-#                       data = getMeshFromObject(ob_derived, None, True, False, sce)
+			data = ob_derived.data
+
 			if data:
 				data.transform(mat)
-#                               data.transform(mat, recalc_normals=False)
 				mesh_objects.append((ob_derived, data))
 				mat_ls = data.materials
 				mat_ls_len = len(mat_ls)
 
 				# get material/image tuples.
 				if len(data.uv_textures):
-#                               if data.faceUV:
 					if not mat_ls:
 						mat = mat_name = None
 
 					for f, uf in zip(data.faces, data.uv_texture_stencil.data):
 						if mat_ls:
 							mat_index = f.material_index
-#                                                       mat_index = f.mat
 							if mat_index >= mat_ls_len:
 								mat_index = f.mat = 0
 							mat = mat_ls[mat_index]
@@ -381,7 +365,6 @@
 						# else there alredy set to none
 
 						img = uf.image
-#                                               img = f.image
 						if img: img_name = img.name
 						else:   img_name = None
 
@@ -396,18 +379,16 @@
 					# Why 0 Why!
 					for f in data.faces:
 						if f.material_index >= mat_ls_len:
-#                                               if f.mat >= mat_ls_len:
 							f.material_index = 0
 							# f.mat = 0
 
 		if free:
 			free_derived_objects(ob)
 
-
 	# Make material chunks for all materials used in the meshes:
-	for mat_and_image in materialDict.values():
-		print("make material chunk {0:s}\n".format(mat_and_image[1]))
-		make_material_chunk(mat_and_image[0], mat_and_image[1], file)
+	# for mat_and_image in materialDict.values():
+	# 	print("make material chunk {0:s}\n".format(mat_and_image[1]))
+	# 	make_material_chunk(mat_and_image[0], mat_and_image[1], file)
 
 	# Give all objects a unique ID and build a dictionary from object name to object id:
 	"""
@@ -427,11 +408,16 @@
 		file.write("\t</surface>\n")
 #               if not blender_mesh.users:
 #		bpy.data.remove_mesh(blender_mesh)
-		bpy.data.meshes.remove(blender_mesh)
+#		bpy.data.meshes.remove(blender_mesh)
 #               blender_mesh.verts = None
 
+	file.write("</OBJECT-3D>\n")
 	# Close the file:
 	file.close()
+# reinitialize
+	global images
+	images = {}
+
 
 
 
@@ -445,8 +431,8 @@
 	imageCount += 1
 	images[name] = imageCount
 	image_path = texture.filepath
-	input = open(expandpath(image_path), 'r')	
-	output = open('output.txt', 'w')
+	input = open(bpy.path.abspath(image_path), 'rb')
+	output = open('output.txt', 'wb')
 	base64.encode(input,output)
 	input.close()
 	output.close()
@@ -481,7 +467,7 @@
 
 def menu_func(self, context):
     default_path = bpy.data.filepath.replace(".blend", ".xml")
-    self.layout.operator(ExportPS3.bl_idname, text="PS3 Cerium (.xml)").path = default_path 
+    self.layout.operator(ExportPS3.bl_idname, text="PS3 Cerium (.xml)").filepath = default_path 
 
     
 def register():
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/Func.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+enum {
+#include "SysTasks.h"
+	Prime,
+	SaveTask,
+	PrintTask,
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/Makefile	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,24 @@
+default: macosx
+
+macosx: FORCE
+	@echo "Make for Mac OS X"
+	@$(MAKE) -f Makefile.macosx
+
+fifo64: FORCE
+	@echo "Make for Mac OS X 64bit mode"
+	@$(MAKE) -f Makefile.macosx ABIBIT=64
+
+linux: FORCE
+	@echo "Make for Linux"
+	@$(MAKE) -f Makefile.linux
+
+cell: FORCE
+	@echo "Make for PS3 (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/Eratosthenes/Makefile.cell	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,45 @@
+include ./Makefile.def
+
+ABIBIT=32
+CFLAGS += -m$(ABIBIT)  -D__CERIUM_CELL__
+
+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) $(CFLAGS) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+speobject:
+	cd spe; $(MAKE) ABIBIT=$(ABIBIT)
+
+run:
+	./$(TARGET) -cpu 6 
+
+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/Eratosthenes/Makefile.def	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,15 @@
+TARGET = prime
+
+# include/library path
+# ex  macosx
+#CERIUM = /Users/gongo/Source/Cerium
+
+# ex  linux/ps3
+CERIUM = ../../../Cerium
+
+CC      = g++
+#CFLAGS  = -O9 -Wall
+CFLAGS  = -g -Wall
+
+INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L${CERIUM}/TaskManager
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/Makefile.linux	Fri Nov 11 18:07:53 2011 +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/Eratosthenes/Makefile.macosx	Fri Nov 11 18:07:53 2011 +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/Eratosthenes/README	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,16 @@
+- 概要
+
+指定された範囲の素数を計算するプログラムです。
+
+- 実行方法
+
+% ./prime [-num number] [-print]
+
+  -num		出力する素数の範囲   
+  -print	計算した素数を出力
+
+- 実行例 (-cpu は Cerium 標準のオプションです)
+
+% ./prime -num 100 -print -cpu 6
+0 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/bitmap.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,123 @@
+#ifndef BITMAP_H_
+#define BITMAP_H_
+/*
+ * $Id: bitmap.c,v 0.2 2010/07/27 15:27:02 dankogai Exp dankogai $
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include "bitmap.h"
+
+typedef struct {
+    int    fd;
+    size_t size;
+    char  *map;
+} bitmap;
+
+
+extern "C" {
+	bitmap *bitmap_free(bitmap *b);
+	bitmap *bitmap_new(size_t size, const char *filename);
+	int bitmap_save(bitmap *b, const char *filename);
+	void bitmap_fill(bitmap *b, int val);
+	inline int bitmap_set(bitmap *b, size_t where, int val);
+	inline int bitmap_get(bitmap *b, size_t where);
+}
+
+bitmap *bitmap_free(bitmap *b){
+    if (b){
+        if (b->map) {
+            if (b->fd){
+                munmap(b->map, b->size);
+                close(b->fd);
+            }else{
+                free(b->map);
+            }
+        }
+        free(b);
+    }
+    return (bitmap *)NULL;
+}
+
+bitmap *bitmap_new(size_t size, const char *filename){
+    bitmap *b = (bitmap *)malloc(sizeof(bitmap));
+    struct stat st;
+    if (!b) return (bitmap *)NULL;
+    if (filename){
+        b->fd = open(filename, 
+                     size ? O_RDWR|O_CREAT : O_RDONLY, 
+                     size ? (mode_t)0644   : (mode_t)0444);
+        if (b->fd == -1) {
+            perror(filename);
+            return bitmap_free(b);
+        }
+        if (size){
+            if (ftruncate(b->fd, size >> 3) == -1){
+                perror(filename);
+                return bitmap_free(b);
+            }
+            b->map = (char *)mmap(0, size >> 3, PROT_READ|PROT_WRITE,
+                                  MAP_SHARED, b->fd, 0);
+
+        }
+        else{
+            fstat(b->fd, &st);
+            size = st.st_size << 3;
+            b->map = (char *)mmap(0, size >> 3, PROT_READ, 
+                                  MAP_PRIVATE, b->fd, 0);
+        }
+        if (b->map == MAP_FAILED) return bitmap_free(b);
+    }
+    else{
+        if (!size) return (bitmap *)NULL;
+        b->map = (char *)malloc(size >> 3);
+        if (!b->map) return bitmap_free(b);
+        b->fd = 0;
+    }
+    b->size = size;
+    return b;
+}
+
+int bitmap_save(bitmap *b, const char *filename){
+    int ok = 0, fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0644);
+    if (fd != -1){
+        if (write(fd, b->map, (b->size >> 3)) != -1) ok = 1;
+    }
+    if (!ok) perror(filename);
+    close(fd);
+    return ok;
+}
+
+void bitmap_fill(bitmap *b, int val){
+    size_t i;
+    for (i = 0; i < (b->size >> 3); i++) b->map[i] = val ? 0xff : 0;
+}
+
+static const int bits[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
+
+inline int bitmap_set(bitmap *b, size_t where, int val){
+    if (val) b->map[where >> 3] |=  bits[where & 7];
+    else b->map[where >> 3] &= ~bits[where & 7];
+    return val;
+}
+
+inline int bitmap_get(bitmap *b, size_t where){
+    return !!(b->map[where >> 3] & bits[where & 7]);
+}
+
+#ifdef TEST
+#include <errno.h>
+int main (int argc, char **argv){
+    bitmap *b = bitmap_new(4096, (argc > 1 ? argv[1] : NULL));
+    if (!b) return errno;
+    bitmap_set(b, 0, 1);
+    printf("%d\n", bitmap_get(b, 0));
+    bitmap_free(b);
+    return 0;
+}
+#endif
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/main.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+#include <math.h>
+#include "TaskManager.h"
+#include "Func.h"
+
+#include <stdint.h>
+typedef uint32_t U32;
+typedef uint64_t U64;
+
+#include "bitmap.h"
+
+const char* const sieveFile = "sieve32.bm";
+
+/* task_initを宣言 */
+extern void task_init(void);
+
+/* TaskManagerを宣言 */
+extern TaskManager *manager;
+
+static U64 start = 0;
+static U64 size  = 1000 * 1000 * 1000;
+static bool print_flag = false;
+
+/* help文章 */
+const char *usr_help_str = "Usage: ./prime [-cpu spe_num] [-num N]\n\
+							-cpu    Number of SPE (default 1) \n\
+							-start 	Calculate of Prime scope start (default 0) \n\
+							-size	Calculate of Prime scope size (default 1000 * 1000 * 1000)";
+
+	int
+init(int argc, char **argv)
+{
+	for (int i = 1; argv[i]; ++i) {
+		if (strcmp(argv[i], "-start") == 0) {
+			start = atoll(argv[++i]);
+		}
+		else if (strcmp(argv[i], "-size") == 0) {
+			size = atoll(argv[++i]);
+		}
+		else if (strcmp(argv[i], "-print") == 0) {
+			print_flag = true;
+		}
+	}
+	return 0;
+}
+
+	void
+prime_init(TaskManager *manager)
+{
+	bitmap *sieve = bitmap_new(0, sieveFile);
+	if (!sieve) {
+		perror(sieveFile);
+		exit(errno);
+	}
+
+	bitmap *b = bitmap_new(size >> 1, NULL);
+	bitmap_fill(b, 1);
+	if (start == 0) bitmap_set(b, 0, 0); // 1は素数ではない
+	U64 pmax = (U64)sqrtl(start+size);
+
+	HTask *save = manager->create_task(SaveTask);
+
+	HTask *print = manager->create_task(PrintTask);
+
+
+#ifdef VERBOSE
+	printf("pmax = %llu\n", pmax);
+#endif
+	U64 p, i;
+	for (p = 3; p < pmax;) {
+
+#ifndef VERBOSE
+		printf("sieving %llu\r", p);
+		fflush(stdout);
+#endif
+
+		HTask *prime = manager->create_task(Prime);
+		prime->set_param(0, b);
+		prime->set_param(1, p); // ふるいの値
+		prime->set_param(2, start);
+		prime->set_param(3, size);
+		prime->set_cpu(SPE_ANY);
+
+		save->wait_for(prime);
+
+		prime->spawn();
+
+		for(p += 2; !bitmap_get(sieve, p>>1); p += 2);
+	}
+
+    char filename[256];
+    snprintf(filename, 256, "%llu~%llu.bm", start, start+size);
+
+	save->set_param(0, b);
+	save->set_param(1, filename);
+	save->set_cpu(CPU_PPE);
+
+	print->wait_for(save);
+
+#ifdef VERBOSE
+		printf("saving %s\n", filename);
+#endif
+
+	save->spawn();
+
+	if ( print_flag ) {
+		print->set_param(0, b);
+		print->set_param(1, start);
+		print->spawn();
+	}
+
+}
+
+	int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+	if (init(argc, argv) < 0) {
+		return -1;
+	}
+
+	task_init();
+	prime_init(manager);
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/.#Hello.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,1 @@
+e065746@nakasone-hiroki-no-macbook.local.1456
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/Prime.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Prime.h"
+#include "Func.h"
+
+#include <stdint.h>
+typedef uint32_t U32;
+typedef uint64_t U64;
+
+#include "bitmap.h"
+
+SchedDefineTask1(Prime, prime);
+
+	static int
+prime(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	bitmap *b = (bitmap*)smanager->get_param(0);
+	U64 p	  = (U64)smanager->get_param(1);
+	U64 start = (U64)smanager->get_param(2);
+	U64 size  = (U64)smanager->get_param(3);
+
+
+	for ( U64 i = p + p - (start % p) ; i <= size; i += p) {
+		if ((i & 1) == 0) continue;
+		bitmap_set( b, i>>1, 0);
+	}
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/Prime.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRIME
+#define INCLUDED_TASK_PRIME
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/PrintTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <errno.h>
+#include "SchedTask.h"
+#include "PrintTask.h"
+#include "Func.h"
+
+#include "bitmap.h"
+
+SchedDefineTask1(PrintTask, print);
+
+	static int
+print(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	bitmap *b = (bitmap*)smanager->get_param(0);
+	unsigned long long offset = (unsigned long long)smanager->get_param(1);
+
+    size_t i;
+    for (i = 0; i < b->size; i++){
+        if (bitmap_get(b, i)) printf("%llu ", offset + (i<<1) + 1);
+    }
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/PrintTask.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRINTTASK
+#define INCLUDED_TASK_PRINTTASK
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/SaveTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "SaveTask.h"
+#include "Func.h"
+
+#include "bitmap.h"
+
+SchedDefineTask1(SaveTask, save);
+
+	static int
+save(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	bitmap *b = (bitmap*)smanager->get_param(0);
+	char *filename = (char*)smanager->get_param(1);
+
+	bitmap_save(b, filename);
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/SaveTask.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_SAVETASK
+#define INCLUDED_TASK_SAVETASK
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/ppe/task_init.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,14 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+SchedExternTask(Prime);
+SchedExternTask(SaveTask);
+SchedExternTask(PrintTask);
+
+	void
+task_init()
+{
+	SchedRegister(Prime);
+	SchedRegister(SaveTask);
+	SchedRegister(PrintTask);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/spe/Makefile	Fri Nov 11 18:07:53 2011 +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++  -D__CERIUM_CELL__ -DABIBIT=$(ABIBIT)
+CFLAGS  = -O9 -g -Wall -fno-exceptions -fno-rtti#-DDEBUG
+INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L../${CERIUM}/TaskManager -lspemanager  -Wl,--gc-sections 
+
+.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/Eratosthenes/spe/Prime.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <math.h>
+#include "SchedTask.h"
+#include "Prime.h"
+#include "Func.h"
+
+SchedDefineTask1(Prime, prime);
+
+	static int
+prime(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	int start = (int)smanager->get_param(0);	/* 素数判定の開始地点 */
+	int end   = (int)smanager->get_param(1);	/* 素数判定の終了地点 */
+	int range = end - start;					/* 判定する範囲		  */
+
+	/* 判定結果を収める配列を受け取る */
+	int *output = (int*)smanager->get_output(wbuf, 0);
+
+	/* 初期化 */
+	for (int i = 0; i < range; i++){
+		output[i] = 1;
+	}
+
+
+	for (int i = start, index = 0; i < end; i++, index++) {
+		int limit = (int)sqrt((double) i);		/* 割る数の最大値を求める */
+		for (int j = 2; j <= limit; j++) {
+			/* 割り切れた場合、0を代入し素数じゃないという判定を下す */
+			if (i % j == 0) {
+				output[index] = 0;
+				break;
+			}
+		}
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/spe/Prime.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRIME
+#define INCLUDED_TASK_PRIME
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/spe/PrintTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "PrintTask.h"
+#include "Func.h"
+
+SchedDefineTask1(PrintTask, print);
+
+	static int
+print(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	int print_flag = (long)smanager->get_param(1);		//プリントするかどうか
+
+	if (print_flag < 0) {
+		return 0;
+	}
+
+	int length = (int)smanager->get_param(0);			/* 出力する範囲 */
+	int *input = (int*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
+
+	/* 素数の判定結果が1ならば出力する */
+	for (int i = 0; i < length; i++) {
+		if ( input[i] == 1 ) {
+			printf("%d ",i);
+		}
+	}
+	printf("\n");
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/spe/PrintTask.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRINTTASK
+#define INCLUDED_TASK_PRINTTASK
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Eratosthenes/spe/spe-main.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,13 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+SchedExternTask(Prime);
+SchedExternTask(PrintTask);
+
+void
+task_init(Scheduler *s)
+{
+	SchedRegister(Prime);
+	SchedRegister(PrintTask);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/Func.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,5 @@
+enum {
+#include "SysTasks.h"
+	Prime,
+	PrintTask,
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/Makefile	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,24 @@
+default: macosx
+
+macosx: FORCE
+	@echo "Make for Mac OS X"
+	@$(MAKE) -f Makefile.macosx
+
+fifo64: FORCE
+	@echo "Make for Mac OS X 64bit mode"
+	@$(MAKE) -f Makefile.macosx ABIBIT=64
+
+linux: FORCE
+	@echo "Make for Linux"
+	@$(MAKE) -f Makefile.linux
+
+cell: FORCE
+	@echo "Make for PS3 (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/Miller_Rabin/Makefile.cell	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,45 @@
+include ./Makefile.def
+
+ABIBIT=32
+CFLAGS += -m$(ABIBIT)  -D__CERIUM_CELL__
+
+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) $(CFLAGS) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+speobject:
+	cd spe; $(MAKE) ABIBIT=$(ABIBIT)
+
+run:
+	./$(TARGET) -cpu 6 
+
+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/Miller_Rabin/Makefile.def	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,15 @@
+TARGET = prime
+
+# include/library path
+# ex  macosx
+#CERIUM = /Users/gongo/Source/Cerium
+
+# ex  linux/ps3
+CERIUM = ../../../Cerium
+
+CC      = g++
+#CFLAGS  = -O9 -Wall
+CFLAGS  = -g -Wall
+
+INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L${CERIUM}/TaskManager
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/Makefile.linux	Fri Nov 11 18:07:53 2011 +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/Miller_Rabin/Makefile.macosx	Fri Nov 11 18:07:53 2011 +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/Miller_Rabin/README	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,16 @@
+- 概要
+
+指定された範囲の素数を計算するプログラムです。
+
+- 実行方法
+
+% ./prime [-num number] [-print]
+
+  -num		出力する素数の範囲   
+  -print	計算した素数を出力
+
+- 実行例 (-cpu は Cerium 標準のオプションです)
+
+% ./prime -num 100 -print -cpu 6
+0 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/main.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,87 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "TaskManager.h"
+#include "Func.h"
+
+typedef unsigned long long U64;
+
+/* task_initを宣言 */
+extern void task_init(void);
+
+/* TaskManagerを宣言 */
+extern TaskManager *manager;
+
+static U64 num = 1000;
+static bool print_flag = false;
+
+/* help文章 */
+const char *usr_help_str = "Usage: ./prime [-cpu spe_num] [-num N]\n\
+							-cpu    Number of SPE (default 1) \n\
+							-num	Caluculate of Prime scope (default 1000 * 1000 * 1000) ";
+
+	int
+init(int argc, char **argv)
+{
+	for (int i = 1; argv[i]; ++i) {
+		if (strcmp(argv[i], "-num") == 0) {
+			num = atoi(argv[++i]);
+		}
+		else if (strcmp(argv[i], "-print") == 0) {
+			print_flag = true;
+		}
+	}
+	return 0;
+}
+
+	void
+prime_init(TaskManager *manager)
+{
+
+	U64 div_size = 1000;
+	U64 task_num = (num + div_size - 1) / div_size;
+
+	bool *output = (bool*)manager->allocate(sizeof(bool)*(task_num*div_size >> 1)); /* 判定結果を収める配列 */
+
+	HTask *print = manager->create_task(PrintTask);
+
+	for (U64 i = 0; i < task_num; i++) {
+
+		HTask *prime = manager->create_task(Prime);
+
+		prime->set_outData(0,&output[i*div_size>>1],sizeof(bool)*div_size>>1);
+
+		prime->set_cpu(SPE_ANY);
+
+		prime->set_param(0,(memaddr)(i*div_size));		// 開始地点
+		prime->set_param(1,(memaddr)((i+1)*div_size));	// 終了地点
+
+		print->wait_for(prime);
+
+		prime->spawn();
+	}
+
+	/* 出力用のタスクに判定結果を収めた配列を渡す */ 
+	print->set_inData(0,output,sizeof(bool)*task_num*div_size);
+	/* 出力する数を渡す */
+	print->set_param(0,(memaddr)num);
+	/* printするかどうかを渡す */
+	print->set_param(1,(memaddr)print_flag);
+	/* PPEを使うように指示 */
+	print->set_cpu(CPU_PPE);
+	/* タスクを登録 */
+	print->spawn();
+}
+
+	int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+	if (init(argc, argv) < 0) {
+		return -1;
+	}
+
+	task_init();
+	prime_init(manager);
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/ppe/Prime.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Prime.h"
+#include "Func.h"
+
+typedef unsigned long long U64;
+
+static U64 base[] = { 2, 3, 5, 7, 11 };
+#define MRMAX 5
+
+SchedDefineTask1(Prime, prime);
+
+static U64
+powMod(U64 base, U64 power, U64 mod)
+{
+	U64 result = 1;
+
+	while (power > 0) {
+		if ( power & 1 == 1 ) {
+			result = (result * base) % mod;
+		}
+		base = ( base * base ) % mod;
+		power >>= 1;
+	}
+	return result;
+}
+
+static bool
+millarRabin(U64 a, U64 s, U64 d, U64 n) {
+	U64 x = powMod(a, d, n);
+	if ( x == 1) return true;
+	for ( U64 r = 0; r < s; r++) {
+		if ( x == n-1 ) return true;
+		x = (x * x) % n;
+	}
+	return false;
+}
+
+static bool
+isPrime(U64 n) {
+
+	if ( n <= 1 ) return false;
+
+	U64 d = n - 1;
+	U64 s = 0;
+
+	while( (d & 1) == 0 ) {
+		d >>= 1;
+		s++;
+	}
+
+	for ( int i = 0; i < MRMAX; i++ ) {
+		if ( n == base[i] ) return true;
+		if (!millarRabin(base[i], s, d, n)) return false;
+	}
+	return true;
+}
+
+	static int
+prime(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	U64 start = (U64)smanager->get_param(0);	/* 素数判定の開始地点 */
+	U64 end   = (U64)smanager->get_param(1);	/* 素数判定の終了地点 */
+	U64 range = end - start;					/* 判定する範囲		  */
+	U64 index_range = range >> 1;
+
+	/* 判定結果を収める配列を受け取る */
+	bool *output = (bool*)smanager->get_output(wbuf, 0);
+
+	/* 初期化 */
+	for (U64 i = 0; i < index_range; i++){
+		output[i] = false;
+	}
+
+	for (U64 i = start + 1,index = 0; i < end ; i += 2, index++) {
+		if (isPrime(i)) {
+			output[index] = true;
+		}
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/ppe/Prime.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRIME
+#define INCLUDED_TASK_PRIME
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/ppe/PrintTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "PrintTask.h"
+#include "Func.h"
+
+typedef unsigned long long U64;
+
+SchedDefineTask1(PrintTask, print);
+
+	static int
+print(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	bool print_flag = (bool)smanager->get_param(1);		//プリントするかどうか
+
+	if (print_flag == false) {
+		return 0;
+	}
+
+	U64 size = ((U64)smanager->get_param(0)) >> 1;			/* 出力する範囲 */
+	bool *input = (bool*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
+	
+	printf("%d\n",(int)2);
+
+	/* 素数の判定結果が1ならば出力する */
+	for (U64 i = 1; i < size; i++) {
+		if ( input[i] == true ) {
+			printf("%llu\n",i*2+1);
+		}
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/ppe/PrintTask.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRINTTASK
+#define INCLUDED_TASK_PRINTTASK
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/ppe/task_init.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,12 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+SchedExternTask(Prime);
+SchedExternTask(PrintTask);
+
+	void
+task_init()
+{
+	SchedRegister(Prime);
+	SchedRegister(PrintTask);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/spe/Makefile	Fri Nov 11 18:07:53 2011 +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++  -D__CERIUM_CELL__ -DABIBIT=$(ABIBIT)
+CFLAGS  = -O9 -g -Wall -fno-exceptions -fno-rtti#-DDEBUG
+INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L../${CERIUM}/TaskManager -lspemanager  -Wl,--gc-sections 
+
+.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/Miller_Rabin/spe/Prime.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Prime.h"
+#include "Func.h"
+
+typedef unsigned long long U64;
+
+static U64 base[] = { 2, 3, 5, 7, 11 };
+#define MRMAX 5
+
+SchedDefineTask1(Prime, prime);
+
+static U64
+powMod(U64 base, U64 power, U64 mod)
+{
+	U64 result = 1;
+
+	while (power > 0) {
+		if ( power & 1 == 1 ) {
+			result = (result * base) % mod;
+		}
+		base = ( base * base ) % mod;
+		power >>= 1;
+	}
+	return result;
+}
+
+static bool
+millarRabin(U64 a, U64 s, U64 d, U64 n) {
+	U64 x = powMod(a, d, n);
+	if ( x == 1) return true;
+	for ( U64 r = 0; r < s; r++) {
+		if ( x == n-1 ) return true;
+		x = (x * x) % n;
+	}
+	return false;
+}
+
+static bool
+isPrime(U64 n) {
+
+	if ( n <= 1 ) return false;
+
+	U64 d = n - 1;
+	U64 s = 0;
+
+	while( (d & 1) == 0 ) {
+		d >>= 1;
+		s++;
+	}
+
+	for ( int i = 0; i < MRMAX; i++ ) {
+		if ( n == base[i] ) return true;
+		if (!millarRabin(base[i], s, d, n)) return false;
+	}
+	return true;
+}
+
+	static int
+prime(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	U64 start = (U64)smanager->get_param(0);	/* 素数判定の開始地点 */
+	U64 end   = (U64)smanager->get_param(1);	/* 素数判定の終了地点 */
+	U64 range = end - start;					/* 判定する範囲		  */
+	U64 index_range = range >> 1;
+
+	/* 判定結果を収める配列を受け取る */
+	bool *output = (bool*)smanager->get_output(wbuf, 0);
+
+	/* 初期化 */
+	for (U64 i = 0; i < index_range; i++){
+		output[i] = false;
+	}
+
+	for (U64 i = start + 1,index = 0; i < end ; i += 2, index++) {
+		if (isPrime(i)) {
+			output[index] = true;
+		}
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/spe/Prime.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRIME
+#define INCLUDED_TASK_PRIME
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/spe/PrintTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "PrintTask.h"
+#include "Func.h"
+
+typedef unsigned long long U64;
+
+SchedDefineTask1(PrintTask, print);
+
+	static int
+print(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+	bool print_flag = (bool)smanager->get_param(1);		//プリントするかどうか
+
+	if (print_flag == false) {
+		return 0;
+	}
+
+	U64 size = ((U64)smanager->get_param(0)) >> 1;			/* 出力する範囲 */
+	bool *input = (bool*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
+	
+	printf("%d\n",(int)2);
+
+	/* 素数の判定結果が1ならば出力する */
+	for (U64 i = 1; i < size; i++) {
+		if ( input[i] == true ) {
+			printf("%llu\n",i*2+1);
+		}
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/spe/PrintTask.h	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_TASK_PRINTTASK
+#define INCLUDED_TASK_PRINTTASK
+
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/spe/spe-main.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -0,0 +1,13 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+SchedExternTask(Prime);
+SchedExternTask(PrintTask);
+
+void
+task_init(Scheduler *s)
+{
+	SchedRegister(Prime);
+	SchedRegister(PrintTask);
+}
+
--- a/example/Prime/ppe/PrintTask.cc	Fri Nov 11 18:05:47 2011 +0900
+++ b/example/Prime/ppe/PrintTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -17,6 +17,9 @@
 	long length = (long)smanager->get_param(0);			/* 出力する範囲 */
 	bool *input = (bool*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
 
+	input[0] = false;
+	input[1] = false;
+
 	/* 素数の判定結果が1ならば出力する */
 	for (long i = 0; i < length; i++) {
 		if ( input[i] == true ) {
--- a/example/Prime/spe/PrintTask.cc	Fri Nov 11 18:05:47 2011 +0900
+++ b/example/Prime/spe/PrintTask.cc	Fri Nov 11 18:07:53 2011 +0900
@@ -17,6 +17,9 @@
 	long length = (long)smanager->get_param(0);			/* 出力する範囲 */
 	bool *input = (bool*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
 
+	input[0] = false;
+	input[1] = false;
+
 	/* 素数の判定結果が1ならば出力する */
 	for (long i = 0; i < length; i++) {
 		if ( input[i] == true ) {
--- a/example/basic/Makefile.def	Fri Nov 11 18:05:47 2011 +0900
+++ b/example/basic/Makefile.def	Fri Nov 11 18:07:53 2011 +0900
@@ -11,7 +11,5 @@
 OPT = -g
 CFLAGS  = $(OPT) -Wall 
 
-ABIBIT = 32
-
 INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
 LIBS = -L${CERIUM}/TaskManager
--- a/example/basic/Makefile.macosx	Fri Nov 11 18:05:47 2011 +0900
+++ b/example/basic/Makefile.macosx	Fri Nov 11 18:07:53 2011 +0900
@@ -4,6 +4,7 @@
 SRCS_EXCLUDE =  # 除外するファイルを書く
 SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
 OBJS = $(SRCS:.cc=.o)
+ABIBIT=64
 
 TASK_DIR  = ppe
 TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)