changeset 1279:de51d55ea403 draft

add collada file directory
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Fri, 25 Nov 2011 17:00:05 +0900
parents 88b75be39952 (current diff) 4ba9b622073d (diff)
children 4b04301478f5
files example/Eratosthenes/Func.h example/Eratosthenes/Makefile example/Eratosthenes/Makefile.cell example/Eratosthenes/Makefile.def example/Eratosthenes/Makefile.linux example/Eratosthenes/Makefile.macosx example/Eratosthenes/README example/Eratosthenes/bitmap.h example/Eratosthenes/main.cc example/Eratosthenes/ppe/.#Hello.cc example/Eratosthenes/ppe/Prime.cc example/Eratosthenes/ppe/Prime.h example/Eratosthenes/ppe/PrintTask.cc example/Eratosthenes/ppe/PrintTask.h example/Eratosthenes/ppe/SaveTask.cc example/Eratosthenes/ppe/SaveTask.h example/Eratosthenes/ppe/task_init.cc example/Eratosthenes/spe/Makefile example/Eratosthenes/spe/Prime.cc example/Eratosthenes/spe/Prime.h example/Eratosthenes/spe/PrintTask.cc example/Eratosthenes/spe/PrintTask.h example/Eratosthenes/spe/spe-main.cc example/Miller_Rabin/run.sh example/Miller_Rabin/time.sh
diffstat 54 files changed, 447 insertions(+), 777 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Camera.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/Camera.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -120,7 +120,8 @@
 
     fov  = 60.0f;
     near = 0.0f;
-    far  = 1000.0f;
+    far  = 10.0f;
+
 
     zd[0] =  0.0f;
     zd[1] =  0.0f;
@@ -176,9 +177,9 @@
     float cx[4], cy[4], cz[4], p[4];
     float tm[16];
 
-    radx = angle[0]*3.14/180;
-    rady = angle[1]*3.14/180;
-    radz = angle[2]*3.14/180;
+    radx = angle[0]*M_PI/180;
+    rady = angle[1]*M_PI/180;
+    radz = angle[2]*M_PI/180;
 
     float sinx = sin(radx);
     float cosx = cos(radx);
@@ -205,10 +206,14 @@
     tm[14] = 0.0f;
     tm[15] = 1.0f;
 
+    /* transform */
+
     applyMatrix(cz, tm, zd);
     applyMatrix(cy, tm, yd);
     applyMatrix(p, tm, xyz);
 
+    /* define view axis of coordinates */
+
     outerProduct(cx, cy, cz);
     normalize(cx, cx);
     normalize(cz, cz);
@@ -311,6 +316,9 @@
     
     matrix4x4(tmp, this->m_pers, this->m_screen);
     matrix4x4(this->matrix, this->m_view, tmp);
+    /* 法線ベクトル、光源ベクトル に使うビュー座標変換までの行列 */
+    for (int i = 0; i < 16; i++) this->real_matrix[i] = this->m_view[i];
+
 #else
     get_matrix(matrix, angle, xyz, NULL);
 #endif
--- a/Renderer/Engine/ChangeLog	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/ChangeLog	Fri Nov 25 17:00:05 2011 +0900
@@ -1,3 +1,14 @@
+2011-9-7  Shinji Kono  <kono@ie.u-ryukyu.ac.jp>
+
+	allExecute 使わない方の Camera の処理をしないとだめ。
+
+	    Camera のbrother ===> sprite
+	    Camera のchildren ===> sceneGraph
+
+	じゃないの? Camera に座標と行列をcopyする必要があると思われる。
+
+	matrix/real_matrix は重複っぽい。そもそも、なんで別なんだ? 普通は同じ値?
+
 2011-2-14 Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
 
 	CreatePolygonFromScenenGraph を SPEで動くようにTask化。もうできるのはわかっているけど
@@ -25,16 +36,16 @@
 2009-12-19  Shinji Kono  <kono@ie.u-ryukyu.ac.jp>
 
 	SgChange/viewer は大域変数使いすぎ。禁止って言ったのに。
-        linda api は、federated linda 対応でないものが使われている。
-        対応したものは、どこにあるんだろう?
+	linda api は、federated linda 対応でないものが使われている。
+	対応したものは、どこにあるんだろう?
 
-        他の例題いじるのは、自分の例題を動かしてからにして欲しい。
+	他の例題いじるのは、自分の例題を動かしてからにして欲しい。
 
-        まぁねぇ。Pipeline execution するのに、sgpack とかも Pipeline buffer
-        にするのは気づかないものなんだろうな... なくても、動かないことは
-        ないのか。
+	まぁねぇ。Pipeline execution するのに、sgpack とかも Pipeline buffer
+	にするのは気づかないものなんだろうな... なくても、動かないことは
+	ないのか。
 
-        viewer.cc の大域変数を落すところから始めるべきか?
+	viewer.cc の大域変数を落すところから始めるべきか?
 
 2009-11-15  Shinji Kono  <kono@ie.u-ryukyu.ac.jp>
 
@@ -80,7 +91,7 @@
 	       ---------------------------------------
 	data = |   vertex   |   normal   |  texture  | sizeof(data) = size*3
 	       ---------------------------------------
-                \  size    / \   size   / \  size   /
+		\  size    / \   size   / \  size   /
 
 	てな感じで、SceneGraph->data の中に 3 つ入ってたわけです。
 	これだと、アクセスする時にどれがどれかわからんくなるし、
--- a/Renderer/Engine/Makefile	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/Makefile	Fri Nov 25 17:00:05 2011 +0900
@@ -26,7 +26,7 @@
 
 FORCE:
 	-mkdir -p ../../include/Cerium
-	rsync `find . -name Test -prune -or -name spe -prune -or -name task -prune -or -name '*.h' -print` ../../include/Cerium
+	rsync `find . -name Test -prune -or -name spe -prune -or -name task -prune -or -name '*.h' -print|sed -e 's-^./--'` ../../include/Cerium
 
 
 clean:
--- a/Renderer/Engine/SceneGraph.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -135,6 +135,10 @@
       matrix[i]      = 0;
       real_matrix[i] = 0;
     }
+    for (int i = 0; i < 4; i++) {
+      matrix[i*4+i]      = 1;
+      real_matrix[i*4+i] = 1;
+    }
 
 
     finalize = &SceneGraph::finalize_copy;
@@ -1127,6 +1131,7 @@
     for(int i=0;i<4;i++) {
 	for(int j=0;i<3;j++) {
 	    matrix[i*4+j] = matrix[i*4+j]*scale[i]; 
+            /* real_matrix は スケールする必要はないかも */
 	    real_matrix[i*4+j] = real_matrix[i*4+j]*scale[i]; 
         }
     }
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -172,7 +172,7 @@
     width_shift += text->seq;
     root->addChild(text);
     get_matrix_scale(text->matrix, text->angle, text->xyz, scale, root->matrix);
-    get_matrix(text->real_matrix, text->angle, text->xyz, root->real_matrix);
+    // get_matrix(text->real_matrix, text->angle, text->xyz, root->real_matrix);
     i += len;
   }
 }
@@ -406,8 +406,8 @@
     int light_num = 4;
     for (int i = 0; i < light_num; i++) {
 
-	get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
-
+        get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->real_matrix);
+      
 	light_vector[i*4] = 0.0f;
 	light_vector[i*4+1] = 0.0f;
 	light_vector[i*4+2] = 0.0f;
@@ -499,7 +499,7 @@
 	    /*親の回転、座標から、子の回転、座標を算出*/
 	    get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix);
 	    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-	    get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
+	    // get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
 	    //get_matrix(c->real_matrix, c->angle, c->xyz, camera->real_matrix);
 
 	}
@@ -529,6 +529,15 @@
 
 }
 
+
+void
+SceneGraphRoot::treeApply(int screen_w, int screen_h)
+{
+    // don't calcurate sg_draw_tree's brother
+    transTree(sg_draw_tree->children, camera);
+}
+
+
 /**
  *     破壊的に変換行列の親子関係を計算する
  */
@@ -544,9 +553,8 @@
 	    /*親の回転、座標から、子の回転、座標を算出*/
 	    matrix4x4(t->matrix,t->matrix,cur_parent->matrix);
 	    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-	    matrix4x4(t->real_matrix,t->real_matrix,cur_parent->real_matrix);
-	}
-
+	    // matrix4x4(t->real_matrix,t->real_matrix,cur_parent->real_matrix);
+	} 
 	if (t->children != NULL && c != NULL) {
 	    cur_parent = t;
 	    t = t->children;
--- a/Renderer/Engine/SceneGraphRoot.h	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.h	Fri Nov 25 17:00:05 2011 +0900
@@ -124,6 +124,7 @@
 
     /* Other System API */
     void allExecute(int screen_w, int screen_h);
+    void treeApply(int screen_w, int screen_h);
     void lightCalc();
     void flip();
     void copyTree(SceneGraphPtr from, SceneGraphPtr to);
--- a/Renderer/Engine/matrix_calc.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/matrix_calc.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -5,12 +5,6 @@
 #include "matrix_calc.h"
 using namespace std;
 
-void noMoreMemory()
-{
-  cout << "can't allocate memory\n";
-  exit(1);
-}
-
 void
 transMatrix(float *m0, float *m1, float *v)
 {
@@ -34,23 +28,22 @@
 }
 
 void
-inversMatrix(float *m0, float *m1)
+inverseMatrix(float *m0, float *m1)
 {
     float m[16];
 
     for (int i = 0; i < 4; i++) {
 	for (int j = 0; j < 4; j++) {
-	    m[i*4+j] = m1[j*4+i];
+	    m0[i*4+j] = m[i*4+j] = m1[j*4+i];
 	}
     }
 
-    m[12] = -(m1[12]*m[0] + m1[13]*m[1] + m1[14]*m[2]);
-    m[13] = -(m1[12]*m[4] + m1[13]*m[5] + m1[14]*m[6]);
-    m[14] = -(m1[12]*m[8] + m1[13]*m[9] + m1[14]*m[10]);
-    m[3] = m[7] = m[11] = 0.0f;
-    m[15] = 1.0f;
+    m0[12] = -(m1[12]*m[0] + m1[13]*m[1] + m1[14]*m[2]);
+    m0[13] = -(m1[12]*m[4] + m1[13]*m[5] + m1[14]*m[6]);
+    m0[14] = -(m1[12]*m[8] + m1[13]*m[9] + m1[14]*m[10]);
+    m0[3] = m0[7] = m0[11] = 0.0f;
+    m0[15] = 1.0f;
 
-    memcpy(m0, m, sizeof(float)*16);
 }
 
 /**
@@ -67,6 +60,7 @@
     }
 }
 
+
 /**
  * ベクトルの正規化
  *
@@ -117,13 +111,14 @@
 {
     float t[16];
 
+    // こういう小細工よりベクタ使った方が良いんだが
     for (int i = 0; i < 4; i++) {
-	for (int j = 0; j < 4; j++) {
+	for (int j = i+1; j < 4; j++) {
+	    float tmp = t[j*4+i];
 	    t[i*4+j] = m1[j*4+i];
+	    m1[j*4+i] = tmp;
 	}
     }
-
-    memcpy(m0, t, sizeof(float)*16);
 }
 
 /**
@@ -149,6 +144,17 @@
     }
 }
 
+void matrix4x4R(float xyz[16], float xyz1[16], float xyz2[16]) 
+{
+  for(int t=0; t<16; t+=4)
+    {
+      for(int i=0; i<4; i++)
+	{
+	  xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i] + xyz1[t+3]*xyz2[12+i];
+	}
+    }
+}
+
 /**
  *   c_xyz を中心に sacle 倍する
  */
@@ -185,9 +191,9 @@
 get_matrix( float *matrix, float *rxyz, float *txyz, float *stack)
 {
   float radx,rady,radz;
-  radx = rxyz[0]*3.141562/180;
-  rady = rxyz[1]*3.141562/180;
-  radz = rxyz[2]*3.141562/180;
+  radx = rxyz[0]*M_PI/180;
+  rady = rxyz[1]*M_PI/180;
+  radz = rxyz[2]*M_PI/180;
 
   float sinx = sin(radx);
   float cosx = cos(radx);
@@ -228,9 +234,9 @@
 get_matrix_scale( float *matrix, float *rxyz, float *txyz, float *scale, float *stack)
 {
   float radx,rady,radz;
-  radx = rxyz[0]*3.14/180;
-  rady = rxyz[1]*3.14/180;
-  radz = rxyz[2]*3.14/180;
+  radx = rxyz[0]*M_PI/180;
+  rady = rxyz[1]*M_PI/180;
+  radz = rxyz[2]*M_PI/180;
 
   float sinx = sin(radx)*scale[0];
   float cosx = cos(radx)*scale[0];
@@ -267,9 +273,43 @@
 
 }
 
+void
+rotate_matrix( float m[16], float rxyz[4] )
+{
+  float radx,rady,radz;
+  radx = rxyz[0]*M_PI/180;
+  rady = rxyz[1]*M_PI/180;
+  radz = rxyz[2]*M_PI/180;
+
+  float sinx = sin(radx);
+  float cosx = cos(radx);
+  float siny = sin(rady);
+  float cosy = cos(rady);
+  float sinz = sin(radz);
+  float cosz = cos(radz);
+
+  /* View Transform */
+  m[0] = cosz*cosy+sinz*sinx*siny;
+  m[1] = sinz*cosx;
+  m[2] = -cosz*siny+sinz*sinx*cosy;
+  m[3] = 0;
+  m[4] = -sinz*cosy+cosz*sinx*siny;
+  m[5] = cosz*cosx;
+  m[6] = sinz*siny+cosz*sinx*cosy;
+  m[7] = 0;
+  m[8] = cosx*siny;
+  m[9] = -sinx;
+  m[10] = cosx*cosy;
+  m[11] = 0;
+  m[12] = 0;
+  m[13] = 0;
+  m[14] = 0;
+  m[15] = 1;
+}
+
 void rotate_x(float *xyz, float r)
 {
-  float rad = r*3.14/180;
+  float rad = r*M_PI/180;
 
   xyz[0] = xyz[0];
   xyz[1] = xyz[1]*cos(rad) - xyz[2]*sin(rad);
@@ -278,7 +318,7 @@
 
 void rotate_y(float *xyz, float r)
 {
-  float rad = r*3.14/180;
+  float rad = r*M_PI/180;
 
   xyz[0] = xyz[0]*cos(rad) + xyz[2]*sin(rad);
   xyz[1] = xyz[1];
@@ -287,7 +327,7 @@
 
 void rotate_z(float *xyz, float r)
 {
-  float rad = r*3.14/180;
+  float rad = r*M_PI/180;
 
   xyz[0] = xyz[0]*cos(rad) - xyz[1]*sin(rad);
   xyz[1] = xyz[0]*sin(rad) + xyz[1]*cos(rad);
--- a/Renderer/Engine/matrix_calc.h	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/matrix_calc.h	Fri Nov 25 17:00:05 2011 +0900
@@ -18,7 +18,7 @@
 void outerProduct(float *v0, float *v1, float *v2);
 float innerProduct(float *v0, float *v1);
 void applyMatrix(float *v0, float *m, float *v1);
-void inversMatrix(float *m0, float *m1);
+void inverseMatrix(float *m0, float *m1);
 void transposeMatrix(float *m0, float *m1);
 void unitMatrix(float *m);
 void transMatrix(float *m0, float *m1, float *v);
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -46,17 +46,11 @@
     min = val[0];
 
     for (int i = 1; i < num; i++) {
-        
         if (max < val[i]) {
-        
             max = val[i];
-    
         } else if (min > val[i]) {
-
             min = val[i];
-
         }
-
     }
 
     return (max - min);
@@ -64,6 +58,7 @@
 }
 
 
+
 static int 
 createPolygon(SchedTask *smanager, void *rbuf, void *wbuf)
 {
@@ -72,7 +67,6 @@
 
       もっと細かなTaskに分けるぞ!
 
-
      */
 
     float xyz1[4], xyz2[4], xyz3[4];
@@ -81,11 +75,13 @@
     //pp, matrix, real_matrix を受け取る
     PolygonPackPtr in_pp      = (PolygonPackPtr)smanager->get_input(rbuf, 0);
     float *matrix             = (float*)smanager->get_input(rbuf, 1);
-    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;
-     
+    //float real_matrix[16]; //        = (float*)smanager->get_input(rbuf, 2);
+    float *real_matrix = (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);
@@ -118,34 +114,64 @@
       xyz3[2] = tri.ver3.z * -1.0f;
       xyz3[3] = 1.0f;
       
-      // matrix = 回転行列*透視変換行列
+      // matrix = ビュー座標変換行列*射影変換行列*スクリーン変換行列
       ApplyMatrix(xyz1, matrix);
       ApplyMatrix(xyz2, matrix);
       ApplyMatrix(xyz3, matrix);
 
       if (xyz1[2] > 100 && xyz2[2] > 100 && xyz3[2] > 100) {
 
-	xyz1[0] /= xyz1[2];
-	xyz1[1] /= xyz1[2];
-	xyz2[0] /= xyz2[2];
-	xyz2[1] /= xyz2[2];
-	xyz3[0] /= xyz3[2];
-	xyz3[1] /= xyz3[2];
+          /*
+           * 同次座標で除算、同次クリップ空間に変換する
+           *
+           */
+
+          xyz1[0] /= xyz1[2];
+          xyz1[1] /= xyz1[2];
+
+          xyz2[0] /= xyz2[2];
+          xyz2[1] /= xyz2[2];
+
+          xyz3[0] /= xyz3[2];
+          xyz3[1] /= xyz3[2];
+
+
+/*
+
+           * 本当はz座標で除算するんじゃなくて
+           * 同次座標でx,y,z座標を除算するんじゃないのかな
+           * これすると、光源がうまくいかず。多分z座標をどこかで使ってる
+           * 同次座標は、もとのz座標と同じだから、入れ替えてやればいいか。
+           * そしたらこの位置で、視錐台カリングとかもできるはず
+           *
+
+          xyz1[0] /= xyz1[3];
+          xyz1[1] /= xyz1[3];
+          xyz1[2] /= xyz2[3];
+
+          xyz2[0] /= xyz2[3];
+          xyz2[1] /= xyz2[3];
+          xyz2[2] /= xyz2[3];
+
+          xyz3[0] /= xyz3[3];
+          xyz3[1] /= xyz3[3];
+          xyz3[2] /= xyz2[3];
+*/
 
       } else {
-      
-	xyz1[0] = 0; 
-	xyz1[1] = 0;
-	xyz1[2] = 0;
+          
+          xyz1[0] = 0; 
+          xyz1[1] = 0;
+          xyz1[2] = 0;
 
-	xyz2[0] = 0;
-	xyz2[1] = 0; 
-	xyz2[2] = 0;
+          xyz2[0] = 0;
+          xyz2[1] = 0; 
+          xyz2[2] = 0;
 
-	xyz3[0] = 0; 
-	xyz3[1] = 0;
-	xyz3[2] = 0;
-
+          xyz3[0] = 0; 
+          xyz3[1] = 0;
+          xyz3[2] = 0;
+          
       }
    
       TrianglePackPtr triangle = &out_pp->tri[i];
@@ -185,20 +211,46 @@
       normal3[2] = tri.normal3.z * -1.0f;
       //normal3[3] = 1.0f;
       normal3[3] = 0.0f;
-      
+
+      /*
+       * 法線は回転、平行移動、ビュー座標変換までの段階でよい
+       * Camera が持っている matrix は 射影変換とスクリーン変換が入っている 
+       * 
+       * Matrix をバラバラに持つ必要がある 
+       * 今はreal_matrixがビュー座標変換行列までを演算した行列になっている
+       *
+       */
+
+      /*
+       * real_matrix = ビュー座標変換行列
+       * スケーリングが入ると、演算が終わった normal vector を正規化する必要がある
+       * 今は DrawSpan で normalize している
+       *
+       * normal vector の同次座標は 0 なので、real_matrix の平行移動部分を除く必要はない
+       *
+       */
+
       ApplyMatrix(normal1,real_matrix);
       ApplyMatrix(normal2,real_matrix);
       ApplyMatrix(normal3,real_matrix);
-      
-      normal1[0] /= normal1[2];
-      normal1[1] /= normal1[2];
+
+/*
+
+     * 法線ベクトルは透視変換しなくていい
+  
+      normal1[0] /= normal1[3];
+      normal1[1] /= normal1[3];
+      normal1[2] /= normal1[3];
       
-      normal2[0] /= normal2[2];
-      normal2[1] /= normal2[2];
+      normal2[0] /= normal2[3];
+      normal2[1] /= normal2[3];
+      normal2[2] /= normal2[3];
       
-      normal3[0] /= normal3[2];
-      normal3[1] /= normal3[2];
-      
+      normal3[0] /= normal3[3];
+      normal3[1] /= normal3[3];
+      normal3[2] /= normal3[3];
+*/
+
       triangle->normal1.x = normal1[0];
       triangle->normal1.y = normal1[1];
       triangle->normal1.z = normal1[2];
--- a/Renderer/Engine/task/DrawSpan.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -65,8 +65,7 @@
 static    int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
 // static    void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
 
-static int getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, 
-                       int endx, int index, int j, DrawParamPtr param);
+//static int getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, int endx, int index, int j, DrawParamPtr param);
 
 static    int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z,
                                   SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z);
@@ -469,7 +468,7 @@
 
     return ret;
 }
-
+#if 0
 static int
 getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, int endx, int index, int j, DrawParamPtr param) {
 
@@ -536,6 +535,7 @@
     return 1; 
 
 }
+#endif
 
 static int
 infinity_light_calc(int color,float normal_x, float normal_y,
@@ -550,7 +550,7 @@
     float light_vector[4];
     float *light_xyz = (float*)smanager->global_get(Light);
 
-    normalize(normal_vector, normal_vector);
+    //normalize(normal_vector, normal_vector);
 
     // 引数で受け取った color の rgb 情報の抜き出し
 #if LITTLEENDIAN
@@ -567,7 +567,8 @@
 
     int tmp_rgb[3] = {0,0,0};
     int light_num = 4;
-    float inner_product = 0.2; // 0.2 は環境光ってことにしてみた。
+    //float inner_product = 0.2; // 0.2 は環境光ってことにしてみた。
+    float inner_product = 0; // 0.2 は環境光ってことにしてみた。
     for (int i = 0; i < light_num; i++) {
 
       light_vector[0] = world_x - light_xyz[i*4];
--- a/Renderer/Engine/viewer.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Engine/viewer.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -293,6 +293,8 @@
 	} else {
 	    sgroot->allExecute(width, height);	
 	}
+    } else {
+	sgroot->treeApply(width, height);	
     }
 
     light_xyz_stock = sgroot->getLightVector();
--- a/Renderer/Test/Makefile.cell	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Test/Makefile.cell	Fri Nov 25 17:00:05 2011 +0900
@@ -15,7 +15,7 @@
 %.pb.cc: $(PROTODIR)/%.proto
 	$(PROTO) $(PROTOFLAGS) $<
 
-ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task property_universe chain_old property_chain aquarium network init_aquarium viewer_2
+ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task property_universe chain_old property_chain aquarium network init_aquarium viewer_2 light_test
 
 all: $(ALL)
 
@@ -121,6 +121,11 @@
 viewer_2 : $(VIEWER_OBJ2) 
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
+LIGHT_TEST = light_test.o
+light_test : $(LIGHT_TEST) 
+	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
+
+
 
 debug: $(TARGET)
 	sudo ppu-gdb ./$(TARGET) 
--- a/Renderer/Test/Makefile.macosx	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Test/Makefile.macosx	Fri Nov 25 17:00:05 2011 +0900
@@ -13,7 +13,7 @@
 %.pb.cc: $(PROTODIR)/%.proto
 	$(PROTO) $(PROTOFLAGS) $<
 
-ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange viewer aquarium network init_aquarium test_linda viewer_2
+ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange viewer viewer_2 light_test aquarium network init_aquarium test_linda
 
 all: $(ALL)
 
@@ -85,10 +85,22 @@
 SgRootChange : $(SGCHANGE_OBJ) 
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
-VIEWER_OBJ = viewer_2.o
+VIEWER_OBJ = viewer.o
 viewer : $(VIEWER_OBJ) 
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
+
+LIGHT_TEST_OBJ = light_test.o
+light_test : $(LIGHT_TEST_OBJ) 
+	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
+
+
+VIEWER_OBJ2 = viewer_2.o
+viewer_2 : $(VIEWER_OBJ2) 
+	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
+
+
+
 AQUARIUM_OBJ = aquarium.pb.o aquarium.o
 aquarium : $(AQUARIUM_OBJ)
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS) $(PROTOLIBS)
@@ -97,6 +109,7 @@
 network : $(NETWORK_OBJ)
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS) $(PROTOLIBS)
 
+
 INIT_AQUARIUM_OBJ = aquarium.pb.o init_aquarium.o
 init_aquarium : $(INIT_AQUARIUM_OBJ)
 	$(CC) $(CFLAGS) -o $@ $? $(LIBS) $(PROTOLIBS)
@@ -105,9 +118,6 @@
 test_linda : $(TEST_LINDA_OBJ)
 	$(CC) $(CFLAGS) -o $@ $? $(LIBS) $(PROTOLIBS)
 
-VIEWER_OBJ2 = viewer_2.o
-viewer_2 : $(VIEWER_OBJ2) 
-	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
 run: $(TARGET)
 	sudo ./$(TARGET) -width 576 -height 384 -bpp 32
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/light_test.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -0,0 +1,147 @@
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "light_test.h"
+
+
+// prototype
+static void light_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void light_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void light_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+
+static void object_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+
+static void
+object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+}
+
+static void
+object_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+}
+
+static void
+light_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    Pad *pad = sgroot->getController();
+
+    if (pad->circle.isPush()) {
+	node->set_move_collision(light_move_rotation, light_collision);
+    }
+
+    if (pad->left.isHold()) {
+        node->xyz[0] -= 10;
+    } else if (pad->right.isHold()) {
+        node->xyz[0] += 10;
+    }
+    if (pad->up.isHold()) {
+        node->xyz[1] -= 10;
+    } else if (pad->down.isHold()) {
+        node->xyz[1] += 10;
+    }
+
+
+}
+
+static void
+light_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    Pad *pad = sgroot->getController();
+    if (pad->circle.isPush()) {
+	node->set_move_collision(light_move_translation, light_collision);
+    }
+
+    if (pad->up.isHold()) {
+        node->xyz[2] += 10;
+    } else if (pad->down.isHold()) {
+        node->xyz[2] -= 10;
+    }
+
+    if (pad->up.isHold()) {
+        node->angle[0] += 10;
+    } else if (pad->down.isHold()) {
+        node->angle[0] -= 10;
+    }
+
+
+}
+
+
+static void
+light_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+
+}
+
+
+MainLoopPtr
+light_test::init(Viewer *sgroot, int screen_w, int screen_h)
+{
+
+    sgroot->createFromXMLfile( "xml_file/universe.xml");
+    sgroot->createFromXMLfile( "xml_file/cube.xml");
+    sgroot->OnLightSysSwitch();
+    SceneGraphPtr light = sgroot->getLight(0); 
+    //光源のスイッチON
+    sgroot->OnLightSwitch(1);
+
+    // SceneGraph ID から SceneGraph を生成する
+    SceneGraphPtr light_object = sgroot->createSceneGraph("Cube");
+    light_object->set_move_collision(light_move_translation, light_collision);
+    light_object->xyz[0] = screen_w / 2;
+    light_object->xyz[1] = screen_h / 2;
+   
+
+    SceneGraphPtr moon = sgroot->createSceneGraph("Moon");
+    moon->set_move_collision(object_move, object_collision);
+    moon->xyz[0] = screen_w / 2;
+    moon->xyz[1] = screen_h / 2;
+
+    
+    // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
+    SceneGraphPtr root = sgroot->createSceneGraph();
+
+    root->addChild(light_object);
+    light_object->addChild(light);
+    root->addChild(moon);
+
+    // SceneGraphRoot に、使用する SceneGraph を設定する
+    // このとき、ユーザーは SceneGraph の root を渡す。
+    sgroot->setSceneData(root);
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new light_test();
+}
+
+const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
+
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    task_initialize();
+    manager->set_TMend(TMend);
+    return init(manager, argc, argv);
+
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("test_nogl end\n");
+}
+
+/* end */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/light_test.h	Fri Nov 25 17:00:05 2011 +0900
@@ -0,0 +1,11 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+
+class light_test : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+};
+
--- a/Renderer/Test/viewer.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/Renderer/Test/viewer.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -75,15 +75,7 @@
 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, 
 	       int screen_h,  SceneGraphPtr tree)
 {
-//     if (node->xyz[1] > screen_h - object_radius) {
-// 		node->xyz[1] = screen_h - object_radius;
 
-// 		vy *= e;
-// 		if (vy > -g && vy < 0) {
-// 			vy = 0.0;
-// 			node->set_move_collision(object_move_idle, object_collision_idle);
-// 		}
-//     }
 }
 
 char *xmlfile;
@@ -105,6 +97,7 @@
 	light->xyz[0] = screen_w / 2;
 	light->xyz[1] = screen_h / 2;
 	light->xyz[2] = -100;
+
     }
 
 
--- a/TaskManager/Fifo/ReferencedDmaManager.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/TaskManager/Fifo/ReferencedDmaManager.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -5,5 +5,10 @@
 void *
 ReferencedDmaManager::dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask)
 {
+#ifdef __CERIUM_FIFO__
+	asm("prefetcht0 %0"::"m"(addr):"memory");
+#endif // __CERIUM_FIFO__
+
 	return (void*)addr;
 }
+
--- a/TaskManager/Fifo/ReferencedDmaManager.h	Fri Nov 25 16:58:09 2011 +0900
+++ b/TaskManager/Fifo/ReferencedDmaManager.h	Fri Nov 25 17:00:05 2011 +0900
@@ -7,7 +7,7 @@
 
 public:
 	/* functions */
-    void *dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask);
+    virtual void *dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask);
 } ;
 
 #endif/* REFERENCED_DMA_MANAGER */
--- a/TaskManager/Makefile.def	Fri Nov 25 16:58:09 2011 +0900
+++ b/TaskManager/Makefile.def	Fri Nov 25 17:00:05 2011 +0900
@@ -29,8 +29,8 @@
 
 ABIBIT = 64
 
-OPT = -g -DMAIL_QUEUE -DNOT_CHECK #-DTASK_LIST_MAIL #-DEARLY_TOUCH -DUSE_CACHE
-# OPT = -O9 -DMAIL_QUEUE -DNOT_CHECK #-DTASK_LIST_MAIL #-DEARLY_TOUCH -DUSE_CACHE 
+# OPT = -g -O0 -DMAIL_QUEUE -DNOT_CHECK #-DTASK_LIST_MAIL #-DEARLY_TOUCH -DUSE_CACHE
+OPT = -O9 -DMAIL_QUEUE -DNOT_CHECK #-DTASK_LIST_MAIL #-DEARLY_TOUCH -DUSE_CACHE 
 
 
 
--- a/TaskManager/kernel/schedule/SchedTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -97,7 +97,8 @@
     run(this, readbuf, writebuf);
 	//;TODO
 	//ReferencedDmaManagerを使う場合ここでfreeすると、wordcountが動かない
-    //free(readbuf);
+	//wordcountのmain.ccのrun16が実行されるときに、readbufをポインタで受けてる
+    free(readbuf);
 	
 
     // 書き込む領域がなければ無視
--- a/example/Eratosthenes/Func.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-enum {
-#include "SysTasks.h"
-	Prime,
-	SaveTask,
-	PrintTask,
-};
--- a/example/Eratosthenes/Makefile	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-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
--- a/example/Eratosthenes/Makefile.cell	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-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
--- a/example/Eratosthenes/Makefile.def	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-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
--- a/example/Eratosthenes/Makefile.linux	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-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/\#*
--- a/example/Eratosthenes/Makefile.macosx	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-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/\#*
--- a/example/Eratosthenes/README	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-- 概要
-
-指定された範囲の素数を計算するプログラムです。
-
-- 実行方法
-
-% ./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 
-
--- a/example/Eratosthenes/bitmap.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#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
--- a/example/Eratosthenes/main.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-#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;
-}
--- a/example/Eratosthenes/ppe/.#Hello.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-e065746@nakasone-hiroki-no-macbook.local.1456
\ No newline at end of file
--- a/example/Eratosthenes/ppe/Prime.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#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;
-}
--- a/example/Eratosthenes/ppe/Prime.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef INCLUDED_TASK_PRIME
-#define INCLUDED_TASK_PRIME
-
-#include "SchedTask.h"
-
-#endif
--- a/example/Eratosthenes/ppe/PrintTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#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;
-}
--- a/example/Eratosthenes/ppe/PrintTask.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef INCLUDED_TASK_PRINTTASK
-#define INCLUDED_TASK_PRINTTASK
-
-#include "SchedTask.h"
-
-#endif
--- a/example/Eratosthenes/ppe/SaveTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#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;
-}
--- a/example/Eratosthenes/ppe/SaveTask.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef INCLUDED_TASK_SAVETASK
-#define INCLUDED_TASK_SAVETASK
-
-#include "SchedTask.h"
-
-#endif
--- a/example/Eratosthenes/ppe/task_init.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#include "Func.h"
-#include "Scheduler.h"
-
-SchedExternTask(Prime);
-SchedExternTask(SaveTask);
-SchedExternTask(PrintTask);
-
-	void
-task_init()
-{
-	SchedRegister(Prime);
-	SchedRegister(SaveTask);
-	SchedRegister(PrintTask);
-}
--- a/example/Eratosthenes/spe/Makefile	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-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 *~ \#*
--- a/example/Eratosthenes/spe/Prime.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-#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;
-}
--- a/example/Eratosthenes/spe/Prime.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef INCLUDED_TASK_PRIME
-#define INCLUDED_TASK_PRIME
-
-#include "SchedTask.h"
-
-#endif
--- a/example/Eratosthenes/spe/PrintTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#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;
-}
--- a/example/Eratosthenes/spe/PrintTask.h	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef INCLUDED_TASK_PRINTTASK
-#define INCLUDED_TASK_PRINTTASK
-
-#include "SchedTask.h"
-
-#endif
--- a/example/Eratosthenes/spe/spe-main.cc	Fri Nov 25 16:58:09 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#include "Func.h"
-#include "Scheduler.h"
-
-SchedExternTask(Prime);
-SchedExternTask(PrintTask);
-
-void
-task_init(Scheduler *s)
-{
-	SchedRegister(Prime);
-	SchedRegister(PrintTask);
-}
-
--- a/example/Miller_Rabin/Makefile.def	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Miller_Rabin/Makefile.def	Fri Nov 25 17:00:05 2011 +0900
@@ -9,7 +9,8 @@
 
 CC      = g++
 CFLAGS  = -O9 -Wall
-#CFLAGS  = -g -Wall
+#CFLAGS  = -g -O0 -Wall
+#CFLAGS  = -pg -Wall
 
 INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
 LIBS = -L${CERIUM}/TaskManager
--- a/example/Miller_Rabin/main.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Miller_Rabin/main.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -38,7 +38,7 @@
 prime_init(TaskManager *manager)
 {
 
-	U64 div_size = 1000;
+	U64 div_size = 256;
 	U64 task_num = (num + div_size - 1) / div_size;
 
 	bool *output = (bool*)manager->allocate(sizeof(bool)*(task_num*div_size >> 1)); /* 判定結果を収める配列 */
@@ -62,7 +62,7 @@
 	}
 
 	/* 出力用のタスクに判定結果を収めた配列を渡す */ 
-	print->set_inData(0,output,sizeof(bool)*task_num*div_size);
+	print->set_inData(0,output,sizeof(bool)*(task_num*div_size >> 1));
 	/* 出力する数を渡す */
 	print->set_param(0,(memaddr)num);
 	/* printするかどうかを渡す */
--- a/example/Miller_Rabin/ppe/PrintTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Miller_Rabin/ppe/PrintTask.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -19,13 +19,14 @@
 	U64 size = ((U64)smanager->get_param(0)) >> 1;			/* 出力する範囲 */
 	bool *input = (bool*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
 	
-	printf("%d\n",(int)2);
+	printf("%d ",(int)2);
 
 	/* 素数の判定結果が1ならば出力する */
 	for (U64 i = 1; i < size; i++) {
 		if ( input[i] == true ) {
-			printf("%llu\n",i*2+1);
+			printf("%llu ",i*2+1);
 		}
 	}
+	printf("\n");
 	return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/run.sh	Fri Nov 25 17:00:05 2011 +0900
@@ -0,0 +1,14 @@
+#!/bin/zsh
+
+a=1
+while [ $a -le 24 ]
+do
+	b=0
+	while [ $b -le 5 ]
+	do
+		echo -n "CPU_NUM $a "
+		(time $* -cpu $a) 1>/dev/null
+		b=`expr $b + 1`
+	done
+	a=`expr $a + 1`
+done
--- a/example/Miller_Rabin/spe/PrintTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Miller_Rabin/spe/PrintTask.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -19,13 +19,14 @@
 	U64 size = ((U64)smanager->get_param(0)) >> 1;			/* 出力する範囲 */
 	bool *input = (bool*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
 	
-	printf("%d\n",(int)2);
+	printf("%d ",(int)2);
 
 	/* 素数の判定結果が1ならば出力する */
 	for (U64 i = 1; i < size; i++) {
 		if ( input[i] == true ) {
-			printf("%llu\n",i*2+1);
+			printf("%llu ",i*2+1);
 		}
 	}
+	printf("\n");
 	return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/Miller_Rabin/time.sh	Fri Nov 25 17:00:05 2011 +0900
@@ -0,0 +1,4 @@
+#!/bin/zsh
+
+./run.sh $* |& awk '{cpu[$2]+=$12; total[$2]++;} END {for(i in cpu){ ans=cpu[i]/total[i]; print "CPU" i "\t" ans }}' 
+
--- a/example/Prime/ppe/Prime.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Prime/ppe/Prime.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -11,11 +11,7 @@
 {
 	long start = (long)smanager->get_param(0);	/* 素数判定の開始地点 */
 	long end   = (long)smanager->get_param(1);	/* 素数判定の終了地点 */
-<<<<<<< local
-	long range = end - start;		        /* 判定する範囲	      */
-=======
 	long range = end - start;					/* 判定する範囲		  */
->>>>>>> other
 
 	/* 判定結果を収める配列を受け取る */
 	bool *output = (bool*)smanager->get_output(wbuf, 0);
@@ -26,16 +22,10 @@
 	}
 
 
-<<<<<<< local
- 	for (int i = start, index = 0; i < end; i++, index++) {
- 		int limit = (int)sqrt((double) i);	       /* 割る数の最大値を求める */
-		for (int j = 2; j <= limit; j++) {
-=======
 
 	for (long i = start, index = 0; i < end; i++, index++) {
 		long limit = (long)sqrt((double) i);		/* 割る数の最大値を求める */
 		for (long j = 2; j <= limit; j++) {
->>>>>>> other
 			/* 割り切れた場合、0を代入し素数じゃないという判定を下す */
 			if (i % j == 0) {
 				output[index] = false;
--- a/example/Prime/ppe/PrintTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Prime/ppe/PrintTask.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -23,8 +23,9 @@
 	/* 素数の判定結果が1ならば出力する */
 	for (long i = 0; i < length; i++) {
 		if ( input[i] == true ) {
-			printf("%ld\n",i);
+			printf("%ld ",i);
 		}
 	}
+	printf("\n");
 	return 0;
 }
--- a/example/Prime/spe/PrintTask.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/Prime/spe/PrintTask.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -23,8 +23,9 @@
 	/* 素数の判定結果が1ならば出力する */
 	for (long i = 0; i < length; i++) {
 		if ( input[i] == true ) {
-			printf("%ld\n",i);
+			printf("%ld ",i);
 		}
 	}
+	printf("\n");
 	return 0;
 }
--- a/example/many_task/Makefile.def	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/many_task/Makefile.def	Fri Nov 25 17:00:05 2011 +0900
@@ -6,7 +6,8 @@
 
 CERIUM = ../../../Cerium
 
-OPT = -g -O9
+OPT = -O9
+# OPT = -g -O9
 # OPT = -g
 CC      = g++
 CFLAGS  =  -DUSE_SIMPLE_TASK -Wall  $(OPT)
--- a/example/word_count/main.cc	Fri Nov 25 16:58:09 2011 +0900
+++ b/example/word_count/main.cc	Fri Nov 25 17:00:05 2011 +0900
@@ -11,6 +11,10 @@
 #include "Func.h"
 #include "WordCount.h"
 
+/* ;TODO
+ * PS3でCPU数が2以上の時に、あまりが計算されてない
+ */
+
 extern void task_init();
 
 int all = 0;
@@ -222,6 +226,7 @@
 	    h_exec->spawn();
 	    
 	    w->size -= size;
+		if (w->size == 0) break;
 	    w->task_num--;
 	    
 	  }