Trisurf Monte Carlo simulator
Samo Penic
2013-11-24 84af719f37b54185ddd7daf0627421143874905c
src/timestep.c
@@ -22,16 +22,14 @@
   pthread_t *tid=(pthread_t *)malloc(sizeof(pthread_t)*vesicle->threads);
   thdata *data=(thdata *)malloc(sizeof(thdata)*vesicle->threads);
   pthread_mutex_t mutex_taint, mutex_untaint;
   pthread_mutex_init(&mutex_taint,NULL);
   pthread_mutex_init(&mutex_untaint,NULL);
   pthread_mutex_init(&(vesicle->mutex->vtx_taint),NULL);
   pthread_mutex_init(&(vesicle->mutex->vtx_untaint),NULL);
   pthread_mutex_init(&(vesicle->mutex->cell_modify),NULL);
   for(i=0;i<vesicle->threads;i++){
      data[i].thread_no=i;
      data[i].vesicle=vesicle;
      data[i].threads=vesicle->threads;
      data[i].vtx_tainting_lock=&mutex_taint;
      data[i].vtx_untainting_lock=&mutex_untaint;
   }
    for(i=0;i<inititer+iterations;i++){
@@ -51,8 +49,8 @@
      }
   }
   pthread_mutex_destroy(&mutex_taint);
   pthread_mutex_destroy(&mutex_untaint);
   pthread_mutex_destroy(&(vesicle->mutex->vtx_taint));
   pthread_mutex_destroy(&(vesicle->mutex->vtx_untaint));
   pthread_exit(NULL);
   return TS_SUCCESS;
}
@@ -79,7 +77,7 @@
//TODO: you only need to taint (lock) vertices, that could be shared with another partition. You can leave out the rest. How can you test for that? Well, if any of vtx neighbours are in other partition, then you need to lock vertex and that neighbor. Otherwise not!
   /**** THREAD IS POTENTIALLY LOCKED ******/
   pthread_mutex_lock(data->vtx_tainting_lock); //taint if no other process is tainting or wait until you can taint
   pthread_mutex_lock(&vesicle->mutex->vtx_taint); //taint if no other process is tainting or wait until you can taint
   //   ts_fprintf(stdout, "thID=%d:: Tainting vertex %d, level=%d. Waiting....\n",thID, i, vesicle->vlist->vtx[i]->locked);
   while(vertex_tainted(vesicle->vlist->vtx[i],1,1)){
@@ -90,17 +88,17 @@
      ts_fprintf(stdout, ".\n"); 
   }
   
   pthread_mutex_lock(data->vtx_untainting_lock);
   pthread_mutex_lock(&vesicle->mutex->vtx_untaint);
   vertex_taint(vesicle->vlist->vtx[i],1);
   pthread_mutex_unlock(data->vtx_untainting_lock);
   pthread_mutex_unlock(&vesicle->mutex->vtx_untaint);
   pthread_mutex_unlock(data->vtx_tainting_lock);
   pthread_mutex_unlock(&vesicle->mutex->vtx_taint);
   /**** THREAD IS RELEASING MUTEX RESOURCES ******/
        single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
   pthread_mutex_lock(data->vtx_untainting_lock);
   pthread_mutex_lock(&vesicle->mutex->vtx_untaint);
   vertex_untaint(vesicle->vlist->vtx[i],1);
   pthread_mutex_unlock(data->vtx_untainting_lock);
   pthread_mutex_unlock(&vesicle->mutex->vtx_untaint);
//      ts_fprintf(stdout, "Vertex %d should be untainted, level=%d.\n", i, vesicle->vlist->vtx[i]->locked);
    }