diff DPP/tableau.cbc @ 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 396046c5b0b0
children
line wrap: on
line diff
--- 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);