changeset 33:3946f8d26710 draft default tip

add benchmarck/binary-trees
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 09 Apr 2013 16:41:30 +0900
parents e3b6e2eef223
children
files DPP/Makefile DPP/ltl.cbc DPP/queue.cbc DPP/state_db.c DPP/tableau.cbc DPP/tableau2.cbc Scheduler/Makefile Scheduler/scheduler.c benchmark/binary-trees/Makefile benchmark/binary-trees/binary-trees benchmark/binary-trees/binary-trees.c
diffstat 11 files changed, 343 insertions(+), 199 deletions(-) [+]
line wrap: on
line diff
--- a/DPP/Makefile	Tue Oct 09 17:34:59 2012 +0900
+++ b/DPP/Makefile	Tue Apr 09 16:41:30 2013 +0900
@@ -3,8 +3,9 @@
 #MCC=mcc
 TARGET=dpp dpp2 tableau tableau2 tableau3
 #MCCFLAGS=-s
-#CFLAGS=-I. -g -Wall
-CFLAGS=-O3 -Wall
+
+#CFLAGS=-O3 -Wall
+CFLAGS=-O0 -g3
 
 .SUFFIXES:	.cbc .c .o
 
--- a/DPP/ltl.cbc	Tue Oct 09 17:34:59 2012 +0900
+++ b/DPP/ltl.cbc	Tue Apr 09 16:41:30 2013 +0900
@@ -10,8 +10,8 @@
 
     if (last->left_fork->owner == NULL) return 0;
     while (current != last) {
-	if (current->left_fork->owner == NULL) return 0;
-	current = current->right;
+		if (current->left_fork->owner == NULL) return 0;
+		current = current->right;
     }
     return 1;
 }
@@ -19,7 +19,7 @@
 code check(int *always_flag, PhilsPtr phils, TaskPtr list)
 {
     if (p(list->phils)) {
-	*always_flag = 0;
+		*always_flag = 0;
     }
     goto tableau(list);
 }
@@ -28,8 +28,8 @@
 show_result(int always_flag)
 {
     if (always_flag == 1) {
-	printf("[]~p is valid.\n");
+		printf("[]~p is valid.\n");
     } else {
-	printf("[]~p is not valid.\n");
+		printf("[]~p is not valid.\n");
     }
 }
--- a/DPP/queue.cbc	Tue Oct 09 17:34:59 2012 +0900
+++ b/DPP/queue.cbc	Tue Apr 09 16:41:30 2013 +0900
@@ -1,35 +1,35 @@
 /*
-    OS Scheduler Simulator
+  OS Scheduler Simulator
 
-** 連絡先: 琉球大学情報工学科 河野 真治  
-** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
-**
-**    このソースのいかなる複写,改変,修正も許諾します。ただし、
-**    その際には、誰が貢献したを示すこの部分を残すこと。
-**    再配布や雑誌の付録などの問い合わせも必要ありません。
-**    営利利用も上記に反しない範囲で許可します。
-**    バイナリの配布の際にはversion messageを保存することを条件とします。
-**    このプログラムについては特に何の保証もしない、悪しからず。
-**
-**    Everyone is permitted to do anything on this program 
-**    including copying, modifying, improving,
-**    as long as you don't try to pretend that you wrote it.
-**    i.e., the above copyright notice has to appear in all copies.  
-**    Binary distribution requires original version messages.
-**    You don't have to ask before copying, redistribution or publishing.
-**    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+  ** 連絡先: 琉球大学情報工学科 河野 真治  
+  ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
+  **
+  **    このソースのいかなる複写,改変,修正も許諾します。ただし、
+  **    その際には、誰が貢献したを示すこの部分を残すこと。
+  **    再配布や雑誌の付録などの問い合わせも必要ありません。
+  **    営利利用も上記に反しない範囲で許可します。
+  **    バイナリの配布の際にはversion messageを保存することを条件とします。
+  **    このプログラムについては特に何の保証もしない、悪しからず。
+  **
+  **    Everyone is permitted to do anything on this program 
+  **    including copying, modifying, improving,
+  **    as long as you don't try to pretend that you wrote it.
+  **    i.e., the above copyright notice has to appear in all copies.  
+  **    Binary distribution requires original version messages.
+  **    You don't have to ask before copying, redistribution or publishing.
+  **    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
 
   Task Queue Manager
 
-** modify: Atsuki Shimoji(atsuki@cr.ie.u-ryukyu.ac.jp)
+  ** modify: Atsuki Shimoji(atsuki@cr.ie.u-ryukyu.ac.jp)
 
- */
+  */
 #include "queue.h"
 
 code create_queue(int count, PhilsPtr self, TaskPtr list, TaskPtr last,
-	    code (*dest)(
-		int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q
-	    ))
+				  code (*dest)(
+					  int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q
+					  ))
 {
 	TaskPtr q;
 	q = (TaskPtr)malloc(sizeof(Task));
@@ -58,9 +58,9 @@
 }
 
 code enqueue(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q,
-		code (*dest)(
-	    int count, PhilsPtr self, TaskPtr list, TaskPtr last
-	))
+			 code (*dest)(
+				 int count, PhilsPtr self, TaskPtr list, TaskPtr last
+				 ))
 {
 	q->next = list;
 	goto dest(count,self,q, last);
@@ -96,14 +96,14 @@
 {
     TaskPtr next;
     if (!self->list) {
-	die_exit("task iterator inconsistency");
+		die_exit("task iterator inconsistency");
     }
     next = self->list->next;
     if (!next) {
-	die_exit("task iterator next inconsistency");
+		die_exit("task iterator next inconsistency");
     }
     if (next == self->last) {
-	return 0;
+		return 0;
     }
     self->list = next;
     return next;
--- a/DPP/state_db.c	Tue Oct 09 17:34:59 2012 +0900
+++ b/DPP/state_db.c	Tue Apr 09 16:41:30 2013 +0900
@@ -30,18 +30,18 @@
 
 /*
 
-    lookup_StateDB(struct state *s, StateDB *parent, StatePtr *out)
+  lookup_StateDB(struct state *s, StateDB *parent, StatePtr *out)
 
-    s->memory points the real memory
-    if s is new, it is copied in the database (parent).
-    if s is in the database, existing state is returned.
+  s->memory points the real memory
+  if s is new, it is copied in the database (parent).
+  if s is in the database, existing state is returned.
 
-    if return value is 0, it returns new state.
-    if out is null, no copy_state is created. (lookup mode)
+  if return value is 0, it returns new state.
+  if out is null, no copy_state is created. (lookup mode)
 
-    Founded state or newly created state is returned in out.
+  Founded state or newly created state is returned in out.
     
- */
+*/
 
 int
 lookup_StateDB(StateDB s, StateDB *parent, StateDB *out)
@@ -50,33 +50,33 @@
     int r;
 
     while(1) {
-	db = *parent;
-	if (!db) {
-	    /* not found */
-	    if (out) {
-		db = create_stateDB();
-		db->left = db->right = 0;
-		db->memory = copy_memory(s->memory,&mem_db);
-		db->hash = s->hash;
-		state_count0 ++;
-		*parent = db;
-		*out = db;
-	    }
-	    return 0;
-	}
-	if (s->hash == db->hash) {
-	    r =  cmp_memory(s->memory,db->memory);
-	} else
-	    r =  (s->hash > db->hash)? 1 : -1;
-	if(!r) {
-	    /* bingo */
-	    if (out) *out = db;
-	    return 1;
-	} else if (r>0) {
-	    parent = &db->left;
-	} else if (r<0) {
-	    parent = &db->right;
-	}
+		db = *parent;
+		if (!db) {
+			/* not found */
+			if (out) {
+				db = create_stateDB();
+				db->left = db->right = 0;
+				db->memory = copy_memory(s->memory,&mem_db);
+				db->hash = s->hash;
+				state_count0 ++;
+				*parent = db;
+				*out = db;
+			}
+			return 0;
+		}
+		if (s->hash == db->hash) {
+			r =  cmp_memory(s->memory,db->memory);
+		} else
+			r =  (s->hash > db->hash)? 1 : -1;
+		if(!r) {
+			/* bingo */
+			if (out) *out = db;
+			return 1;
+		} else if (r>0) {
+			parent = &db->left;
+		} else if (r<0) {
+			parent = &db->right;
+		}
     }
 }
 
--- a/DPP/tableau.cbc	Tue Oct 09 17:34:59 2012 +0900
+++ b/DPP/tableau.cbc	Tue Apr 09 16:41:30 2013 +0900
@@ -54,33 +54,33 @@
     t = list->next;
 
     for (length = 1; t && t != list; length++) {
-	t = t->next;
+		t = t->next;
     }
     return length;
 }
 
 /*
-TaskPtr
-get_task(int num, TaskPtr list)
-{
-    while (num-- > 0) {
-	list = list->next;
-    }
-    return list;
-}
+  TaskPtr
+  get_task(int num, TaskPtr list)
+  {
+  while (num-- > 0) {
+  list = list->next;
+  }
+  return list;
+  }
 */
 
 static TaskIteratorPtr task_iter;
 static int depth,count;
 
 /*
-    Performe depth frist search
-    Possible task iterleave is generated by TaskIterator
-        (using task ring)
-    State are recorded in StateDB
-	all memory fragments are regsitered by add_memory_range()
-	including task queue
- */
+  Performe depth frist search
+  Possible task iterleave is generated by TaskIterator
+  (using task ring)
+  State are recorded in StateDB
+  all memory fragments are regsitered by add_memory_range()
+  including task queue
+*/
 
 
 code tableau(TaskPtr list)
@@ -89,30 +89,30 @@
 
     st.hash = get_memory_hash(mem,0);
     if (lookup_StateDB(&st, &state_db, &out)) {
-	// found in the state database
-	//printf("found %d\n",count);
-	while(!(list = next_task_iterator(task_iter))) {
-	    // no more branch, go back to the previous one
-	    TaskIteratorPtr prev_iter = task_iter->prev;
-	    if (!prev_iter) {
-		printf("All done count %d\n",count);
-		memory_usage();
-		goto ret(0,env);
-	    }
-	    //printf("no more branch %d\n",count);
-	    depth--;
-	    free_task_iterator(task_iter);
-	    task_iter = prev_iter;
-	}
-	// return to previous state
-	//    here we assume task list is fixed, we don't have to
-	//    recover task list itself
-	restore_memory(task_iter->state->memory);
-	//printf("restore list %x next %x\n",(int)list,(int)(list->next));
+		// found in the state database
+		//printf("found %d\n",count);
+		while(!(list = next_task_iterator(task_iter))) {
+			// no more branch, go back to the previous one
+			TaskIteratorPtr prev_iter = task_iter->prev;
+			if (!prev_iter) {
+				printf("All done count %d\n",count);
+				memory_usage();
+				goto ret(0,env);
+			}
+			//printf("no more branch %d\n",count);
+			depth--;
+			free_task_iterator(task_iter);
+			task_iter = prev_iter;
+		}
+		// return to previous state
+		//    here we assume task list is fixed, we don't have to
+		//    recover task list itself
+		restore_memory(task_iter->state->memory);
+		//printf("restore list %x next %x\n",(int)list,(int)(list->next));
     } else {
-	// one step further
-	depth++;
-	task_iter = create_task_iterator(list,out,task_iter);
+		// one step further
+		depth++;
+		task_iter = create_task_iterator(list,out,task_iter);
     }
     //printf("depth %d count %d\n", depth, count++);
     count++;
@@ -141,10 +141,10 @@
 code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q)
 {
     if (!q) {
-	goto die("Can't allocate Task\n");
+		goto die("Can't allocate Task\n");
     } else {
-	add_memory_range(q,sizeof(Task),&mem);
-	goto enqueue(count, self, list, last, q, task_entry1);
+		add_memory_range(q,sizeof(Task),&mem);
+		goto enqueue(count, self, list, last, q, task_entry1);
     }
 }
 
@@ -152,22 +152,22 @@
 {
     StateDB out;
     /*
-    printf("int count %d, PhilsPtr self %x, TaskPtr list %x, TaskPtr last %x\n",
-	count, self, list, last);
+	  printf("int count %d, PhilsPtr self %x, TaskPtr list %x, TaskPtr last %x\n",
+	  count, self, list, last);
     */
 
     if (count++ < NUM_PHILOSOPHER) {
-	self = self->left;
-	goto create_queue(count,self,list,last,task_entry2);
+		self = self->left;
+		goto create_queue(count,self,list,last,task_entry2);
     } else {
-	// make circular task list
-	last->next = list;
-	st.memory = mem;
-	st.hash = get_memory_hash(mem,0);
-	lookup_StateDB(&st, &state_db, &out);
-	task_iter = create_task_iterator(list,out,0);
-	// start first task
-	goto list->phils->next(list->phils,list);
+		// make circular task list
+		last->next = list;
+		st.memory = mem;
+		st.hash = get_memory_hash(mem,0);
+		lookup_StateDB(&st, &state_db, &out);
+		task_iter = create_task_iterator(list,out,0);
+		// start first task
+		goto list->phils->next(list->phils,list);
     }
 }
 
@@ -193,7 +193,7 @@
 
     tmp_self = (PhilsPtr)malloc(sizeof(Phils));
     if (!tmp_self) {
-	goto die("Can't allocate Phils\n");
+		goto die("Can't allocate Phils\n");
     }
     self->right = tmp_self;
     tmp_self->id = id;
@@ -208,9 +208,9 @@
     id++;
 
     if (count == 0) {
-	goto init_final(tmp_self);
+		goto init_final(tmp_self);
     } else {
-	goto init_fork2(tmp_self, count, id);
+		goto init_fork2(tmp_self, count, id);
     }
 }
 
@@ -220,7 +220,7 @@
 
     tmp_fork = (ForkPtr)malloc(sizeof(Fork));
     if (!tmp_fork) {
-	goto die("Can't allocate Fork\n");
+		goto die("Can't allocate Fork\n");
     }
     tmp_fork->id = id;
     tmp_fork->owner = NULL;
@@ -236,7 +236,7 @@
 
     self = (PhilsPtr)malloc(sizeof(Phils));
     if (!self) {
-	goto die("Can't allocate Phils\n");
+		goto die("Can't allocate Phils\n");
     }
     phils_list = self;
     self->id = id;
@@ -260,7 +260,7 @@
 
     fork = (ForkPtr)malloc(sizeof(Fork));
     if (!fork) {
-	goto die("Can't allocate Fork\n");
+		goto die("Can't allocate Fork\n");
     }
     fork->id = id;
     fork->owner = NULL;
@@ -284,12 +284,12 @@
     srandom(555);
 
     if (ac==2) {
-	NUM_PHILOSOPHER = atoi(av[1]);
-	if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) {
-	    printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER );
-	    return 1; 
-	}
-	printf("number of philosopher = %d\n", NUM_PHILOSOPHER );
+		NUM_PHILOSOPHER = atoi(av[1]);
+		if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) {
+			printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER );
+			return 1; 
+		}
+		printf("number of philosopher = %d\n", NUM_PHILOSOPHER );
     }
 
     goto init_fork1(NUM_PHILOSOPHER);
--- a/DPP/tableau2.cbc	Tue Oct 09 17:34:59 2012 +0900
+++ b/DPP/tableau2.cbc	Tue Apr 09 16:41:30 2013 +0900
@@ -58,7 +58,7 @@
     t = list->next;
 
     for (length = 1; t && t != list; length++) {
-	t = t->next;
+		t = t->next;
     }
     return length;
 }
@@ -67,7 +67,7 @@
 get_task(int num, TaskPtr list)
 {
     while (num-- > 0) {
-	list = list->next;
+		list = list->next;
     }
     return list;
 }
@@ -77,13 +77,13 @@
 static int depth,count;
 
 /*
-    Performe depth frist search
-    Possible task iterleave is generated by TaskIterator
-        (using task ring)
-    State are recorded in StateDB
-	all memory fragments are regsitered by add_memory_range()
-	including task queue
- */
+  Performe depth frist search
+  Possible task iterleave is generated by TaskIterator
+  (using task ring)
+  State are recorded in StateDB
+  all memory fragments are regsitered by add_memory_range()
+  including task queue
+*/
 
 
 code tableau(TaskPtr list)
@@ -92,31 +92,31 @@
 
     st.hash = get_memory_hash(mem,0);
     if (lookup_StateDB(&st, &state_db, &out)) {
-	// found in the state database
-	//printf("found %d\n",count);
-	while(!(list = next_task_iterator(task_iter))) {
-	    // no more branch, go back to the previous one
-	    TaskIteratorPtr prev_iter = task_iter->prev;
-	    if (!prev_iter) {
-		printf("All done count %d\n",count);
-		memory_usage();
-		show_result(always_flag);
-		goto ret(0,env);
-	    }
-	    //printf("no more branch %d\n",count);
-	    depth--;
-	    free_task_iterator(task_iter);
-	    task_iter = prev_iter;
-	}
-	// return to previous state
-	//    here we assume task list is fixed, we don't have to
-	//    recover task list itself
-	restore_memory(task_iter->state->memory);
-	//printf("restore list %x next %x\n",(int)list,(int)(list->next));
+		// found in the state database
+		//printf("found %d\n",count);
+		while(!(list = next_task_iterator(task_iter))) {
+			// no more branch, go back to the previous one
+			TaskIteratorPtr prev_iter = task_iter->prev;
+			if (!prev_iter) {
+				printf("All done count %d\n",count);
+				memory_usage();
+				show_result(always_flag);
+				goto ret(0,env);
+			}
+			//printf("no more branch %d\n",count);
+			depth--;
+			free_task_iterator(task_iter);
+			task_iter = prev_iter;
+		}
+		// return to previous state
+		//    here we assume task list is fixed, we don't have to
+		//    recover task list itself
+		restore_memory(task_iter->state->memory);
+		//printf("restore list %x next %x\n",(int)list,(int)(list->next));
     } else {
-	// one step further
-	depth++;
-	task_iter = create_task_iterator(list,out,task_iter);
+		// one step further
+		depth++;
+		task_iter = create_task_iterator(list,out,task_iter);
     }
     //printf("depth %d count %d\n", depth, count++);
     count++;
@@ -145,10 +145,10 @@
 code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q)
 {
     if (!q) {
-	goto die("Can't allocate Task\n");
+		goto die("Can't allocate Task\n");
     } else {
-	add_memory_range(q,sizeof(Task),&mem);
-	goto enqueue(count, self, list, last, q, task_entry1);
+		add_memory_range(q,sizeof(Task),&mem);
+		goto enqueue(count, self, list, last, q, task_entry1);
     }
 }
 
@@ -156,22 +156,22 @@
 {
     StateDB out;
     /*
-    printf("int count %d, PhilsPtr self %x, TaskPtr list %x, TaskPtr last %x\n",
-	count, self, list, last);
+	  printf("int count %d, PhilsPtr self %x, TaskPtr list %x, TaskPtr last %x\n",
+	  count, self, list, last);
     */
 
     if (count++ < NUM_PHILOSOPHER) {
-	self = self->left;
-	goto create_queue(count,self,list,last,task_entry2);
+		self = self->left;
+		goto create_queue(count,self,list,last,task_entry2);
     } else {
-	// make circular task list
-	last->next = list;
-	st.memory = mem;
-	st.hash = get_memory_hash(mem,0);
-	lookup_StateDB(&st, &state_db, &out);
-	task_iter = create_task_iterator(list,out,0);
-	// start first task
-	goto list->phils->next(list->phils,list);
+		// make circular task list
+		last->next = list;
+		st.memory = mem;
+		st.hash = get_memory_hash(mem,0);
+		lookup_StateDB(&st, &state_db, &out);
+		task_iter = create_task_iterator(list,out,0);
+		// start first task
+		goto list->phils->next(list->phils,list);
     }
 }
 
@@ -199,7 +199,7 @@
 
     tmp_self = (PhilsPtr)malloc(sizeof(Phils));
     if (!tmp_self) {
-	goto die("Can't allocate Phils\n");
+		goto die("Can't allocate Phils\n");
     }
     self->right = tmp_self;
     tmp_self->id = id;
@@ -214,9 +214,9 @@
     id++;
 
     if (count == 0) {
-	goto init_final(tmp_self);
+		goto init_final(tmp_self);
     } else {
-	goto init_fork2(tmp_self, count, id);
+		goto init_fork2(tmp_self, count, id);
     }
 }
 
@@ -226,7 +226,7 @@
 
     tmp_fork = (ForkPtr)malloc(sizeof(Fork));
     if (!tmp_fork) {
-	goto die("Can't allocate Fork\n");
+		goto die("Can't allocate Fork\n");
     }
     tmp_fork->id = id;
     tmp_fork->owner = NULL;
@@ -242,7 +242,7 @@
 
     self = (PhilsPtr)malloc(sizeof(Phils));
     if (!self) {
-	goto die("Can't allocate Phils\n");
+		goto die("Can't allocate Phils\n");
     }
     phils_list = self;
     self->id = id;
@@ -266,7 +266,7 @@
 
     fork = (ForkPtr)malloc(sizeof(Fork));
     if (!fork) {
-	goto die("Can't allocate Fork\n");
+		goto die("Can't allocate Fork\n");
     }
     fork->id = id;
     fork->owner = NULL;
@@ -290,12 +290,12 @@
     srandom(555);
 
     if (ac==2) {
-	NUM_PHILOSOPHER = atoi(av[1]);
-	if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) {
-	    printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER );
-	    return 1; 
-	}
-	printf("number of philosopher = %d\n", NUM_PHILOSOPHER );
+		NUM_PHILOSOPHER = atoi(av[1]);
+		if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) {
+			printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER );
+			return 1; 
+		}
+		printf("number of philosopher = %d\n", NUM_PHILOSOPHER );
     }
 
     goto init_fork1(NUM_PHILOSOPHER);
--- a/Scheduler/Makefile	Tue Oct 09 17:34:59 2012 +0900
+++ b/Scheduler/Makefile	Tue Apr 09 16:41:30 2013 +0900
@@ -1,7 +1,7 @@
 #CC = cbc-gcc-4.6.0
 CC = gcc
 #CFLAGS = -O3
-CFLAGS = -O0 -g3
+CFLAGS = -g
 PROG = scheduler
 
 all: $(PROG)
--- a/Scheduler/scheduler.c	Tue Oct 09 17:34:59 2012 +0900
+++ b/Scheduler/scheduler.c	Tue Apr 09 16:41:30 2013 +0900
@@ -87,7 +87,7 @@
 		task_list[i].wait = null_load;
 	}
 
-	scheduler->set_manager(m);
+	scheduler->set_manager(m,scheduler);
 	
 	for (i=0; i<MAX_GLOBAL_AREA; i++) {
 		scheduler->global_list[i] = NULL;
@@ -97,6 +97,7 @@
 		scheduler->main_mem_list[i] = (memaddr)NULL;
 	}
 
+
 }
 
 void set_manager(task_manager_impl *impl, main_scheduler *scheduler) 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/benchmark/binary-trees/Makefile	Tue Apr 09 16:41:30 2013 +0900
@@ -0,0 +1,13 @@
+CC = clang
+
+PATH = ../../../../../opt
+LDFLAGS = -I$(PATH)/include/apr-1
+LINKFLAGS = -lapr-1 $(PATH)/lib/libapr-1.a
+
+FLAGS = -O3 -Wall $(LDFLAGS) $(LIBFLAGS) $(LINKFLAGS)
+
+binary: binary-trees.c
+	$(CC) $(FLAGS) -o binary-trees $^
+
+clean: 
+	rm binary-trees
Binary file benchmark/binary-trees/binary-trees has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/benchmark/binary-trees/binary-trees.c	Tue Apr 09 16:41:30 2013 +0900
@@ -0,0 +1,129 @@
+/* The Computer Language Benchmarks Game
+ * http://benchmarksgame.alioth.debian.org/
+ *
+ * contributed by Francesco Abbate
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+typedef off_t off64_t;
+#include <apr_pools.h>
+
+const size_t	LINE_SIZE = 64;
+
+struct node
+{
+  int i;
+  struct node *left;
+  struct node *right;
+};
+
+int
+node_check(const struct node *n)
+{
+  if (n->left)
+    {
+      int lc = node_check (n->left);
+      int rc = node_check (n->right);
+      return lc + n->i - rc;
+    }
+
+  return n->i;
+}
+
+struct node *
+node_get_avail (apr_pool_t *pool)
+{
+  return apr_palloc (pool, sizeof(struct node));
+}
+
+struct node *
+make (int i, int depth, apr_pool_t *pool)
+{
+  struct node *curr = node_get_avail (pool);
+
+  curr->i = i;
+
+  if (depth > 0)
+    {
+      curr->left  = make (2*i-1, depth - 1, pool);
+      curr->right = make (2*i  , depth - 1, pool);
+    }
+  else
+    {
+      curr->left  = NULL;
+      curr->right = NULL;
+    }
+
+  return curr;
+}
+
+int
+main(int argc, char *argv[])
+{
+  apr_pool_t *long_lived_pool;
+  int min_depth = 4;
+  int req_depth = (argc == 2 ? atoi(argv[1]) : 10);
+  int max_depth = (req_depth > min_depth + 2 ? req_depth : min_depth + 2);
+  int stretch_depth = max_depth+1;
+
+  apr_initialize();
+
+  /* Alloc then dealloc stretchdepth tree */
+  {
+    apr_pool_t *store;
+    struct node *curr;
+
+    apr_pool_create (&store, NULL);
+    curr = make (0, stretch_depth, store);
+    printf ("stretch tree of depth %i\t check: %i\n", stretch_depth, 
+	    node_check (curr));
+    apr_pool_destroy (store);
+  }
+
+  apr_pool_create (&long_lived_pool, NULL);
+
+  {
+    struct node *long_lived_tree = make(0, max_depth, long_lived_pool);
+
+    /* buffer to store output of each thread */
+    char *outputstr = (char*) malloc(LINE_SIZE * (max_depth +1) * sizeof(char));
+    int d;
+
+#pragma omp parallel for
+    for (d = min_depth; d <= max_depth; d += 2)
+      {
+        int iterations = 1 << (max_depth - d + min_depth);
+	apr_pool_t *store;
+        int c = 0, i;
+
+	apr_pool_create (&store, NULL);
+
+        for (i = 1; i <= iterations; ++i)
+	  {
+	    struct node *a, *b;
+
+	    a = make ( i, d, store);
+	    b = make (-i, d, store);
+            c += node_check (a) + node_check (b);
+	    apr_pool_clear (store);
+        }
+	apr_pool_destroy (store);
+	
+	/* each thread write to separate location */
+	sprintf(outputstr + LINE_SIZE * d, "%d\t trees of depth %d\t check: %d\n", (2 * iterations), d, c);
+      }
+
+    /* print all results */
+    for (d = min_depth; d <= max_depth; d += 2)
+      printf("%s", outputstr + (d * LINE_SIZE) );
+    free(outputstr);
+
+    printf ("long lived tree of depth %i\t check: %i\n", max_depth, 
+	    node_check (long_lived_tree));
+
+    return 0;
+  }
+}