From 0652ee2715994b48a9bbfd1132bf0b65ad206289 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Wed, 27 Nov 2013 18:46:13 +0000
Subject: [PATCH] commiting all changes.

---
 src/timestep.c |   39 +++++++++++++++++++++++++++++++++------
 src/vertex.c   |    4 ++--
 src/tape       |    2 +-
 src/bondflip.c |    1 +
 4 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/bondflip.c b/src/bondflip.c
index 478027d..1187caf 100644
--- a/src/bondflip.c
+++ b/src/bondflip.c
@@ -13,6 +13,7 @@
 #include<stdio.h>
 
 ts_bool single_bondflip_timestep(ts_vesicle *vesicle, ts_bond *bond, ts_double *rn){
+	return TS_SUCCESS;
 /*c  Vertex and triangle (lm and lp) indexing for bond flip:
 c      +----- k-------+              +----- k ------+
 c      |lm1 / | \ lp1 |              |lm1 /   \ lp1 |
diff --git a/src/tape b/src/tape
index 8d9080a..2e6e110 100644
--- a/src/tape
+++ b/src/tape
@@ -31,7 +31,7 @@
 #currently only none and smp makes sense. If set to none, smp_cores defaults to 1
 multiprocessing=smp
 #how many cores are allowed to process in SMP? If smp_cores=0, then number of threads will corespond with number of harware processor cores.
-smp_cores=4
+smp_cores=16
 #how many nodes in cluster?
 cluster_nodes=50
 #max number of processes in distributed (voluntary) environment
diff --git a/src/timestep.c b/src/timestep.c
index e2f89ef..aad7817 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -68,7 +68,9 @@
 		end=(thID+1)*partition_size;
 	}
     ts_double rnvec[3];
-    ts_uint i,j; //b;
+    ts_uint i,j,b;
+	ts_vertex *vtx;
+	//ts_bool retval;	
 //	ts_fprintf(stdout,"Thread thID=%d report for duty. My vtxes are in range from %d to %d.\n",thID,thID*partition_size, end-1);
     for(i=thID*partition_size;i<end;i++){
         rnvec[0]=drand48();
@@ -99,20 +101,45 @@
 	pthread_mutex_lock(&vesicle->mutex->vtx_untaint);
 	vertex_untaint(vesicle->vlist->vtx[i],1);
 	pthread_mutex_unlock(&vesicle->mutex->vtx_untaint);
-//		ts_fprintf(stdout, "Vertex %d should be untainted, level=%d.\n", i, vesicle->vlist->vtx[i]->locked);
     }
 
 //	ts_int cnt=0;
-/*
-    for(i=0;i<vesicle->vlist->n;i++){
+	
+    for(i=0;i<(ts_uint)((ts_double)(vesicle->vlist->n)/(ts_double)vesicle->threads);i++){
 	b=rand() % vesicle->blist->n;
         //find a bond and return a pointer to a bond...
         //call single_bondflip_timestep...
-        retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
+	vtx=vesicle->blist->bond[b]->vtx1;
+
+	/**** THREAD IS POTENTIALLY LOCKED ******/
+	pthread_mutex_lock(&vesicle->mutex->vtx_taint);
+        	while(vertex_tainted(vtx,2,1)){
+		ts_fprintf(stdout, "BF:: thID=%d Vertex %d is tainted. Amount=%d. BU(H)TELJ!\n       neigh. vtxs: ",thID, i, *(vesicle->vlist->vtx[i]->locked));
+		for(j=0; j<vesicle->vlist->vtx[i]->neigh_no; j++){
+			ts_fprintf(stdout, "%d(a=%d) ", vesicle->vlist->vtx[i]->neigh[j]->idx,  *(vesicle->vlist->vtx[i]->neigh[j]->locked));
+		}
+		ts_fprintf(stdout, ".\n"); 
+	}
+	
+	pthread_mutex_lock(&vesicle->mutex->vtx_untaint);
+	vertex_taint(vtx,2);
+	pthread_mutex_unlock(&vesicle->mutex->vtx_untaint);
+
+	pthread_mutex_unlock(&vesicle->mutex->vtx_taint);
+	/**** THREAD IS RELEASING MUTEX RESOURCES ******/
+
+	//retval=
+	single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
+	
+	pthread_mutex_lock(&vesicle->mutex->vtx_untaint);
+	vertex_untaint(vtx,2);
+	pthread_mutex_unlock(&vesicle->mutex->vtx_untaint);
+
+
 //	if(retval==TS_SUCCESS) cnt++;        
     } 
 //	printf("Bondflip success rate in one sweep: %d/%d=%e\n", cnt,vesicle->blist->n,(double)cnt/(double)vesicle->blist->n);
-*/
+
 /*	if(retval);
     return TS_SUCCESS;
 */
diff --git a/src/vertex.c b/src/vertex.c
index 30b294f..cd999df 100644
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -316,7 +316,7 @@
 
 ts_bool vertex_taint(ts_vertex *vtx, ts_uint level){
 	ts_uint i;
-	(*(vtx->locked))++; //lock current vertex
+	(*(vtx->locked))=1; //lock current vertex
 	if(level==0){ //if we reach last in recursion exit
 		return TS_SUCCESS;	
 	}	
@@ -327,7 +327,7 @@
 }
 
 ts_bool vertex_untaint(ts_vertex *vtx, ts_uint level){
-		(*(vtx->locked))--;
+		(*(vtx->locked))=0;
 	if(level==0){
 		return TS_SUCCESS;	
 	}	

--
Gitblit v1.9.3