]> hackdaworld.org Git - physik/posic.git/commitdiff
PTHREADS printf, made neighbour index thread safe, check of mutex
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Tue, 4 Nov 2008 18:29:47 +0000 (19:29 +0100)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Tue, 4 Nov 2008 18:29:47 +0000 (19:29 +0100)
(un)lock return values

moldyn.c
potentials/albe_fast.c

index bcc78c011a41a646623a6191ca091f18899ed302..13d7e5d60384039160b3be934952858c8859ade6 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -1740,6 +1740,11 @@ int moldyn_integrate(t_moldyn *moldyn) {
        }
 #endif
 
+#ifdef PTHREADS
+       printf("##################\n");
+       printf("# USING PTHREADS #\n");
+       printf("##################\n");
+#endif
        /* tell the world */
        printf("[moldyn] integration start, go get a coffee ...\n");
 
index 9fc362ed140c7b48126b91d43d1467d719d3a192..79162b1f31c62b2d95d01cded216e9a2ffc1584d 100644 (file)
@@ -804,14 +804,13 @@ void *potential_force_thread(void *ptr) {
                if(!(itom[i].attr&ATOM_ATTR_3BP))
                        return 0;
 
-               link_cell_neighbour_index(moldyn,
+               // thread safe this way!
+               dnlc=link_cell_neighbour_index(moldyn,
                                          (itom[i].r.x+moldyn->dim.x/2)/lc->x,
                                          (itom[i].r.y+moldyn->dim.y/2)/lc->y,
                                          (itom[i].r.z+moldyn->dim.z/2)/lc->z,
                                          neighbour_i);
 
-               dnlc=lc->dnlc;
-
                /* copy the neighbour lists */
 #ifdef STATIC_LISTS
 #elif LOWMEM_LISTS
@@ -839,7 +838,7 @@ void *potential_force_thread(void *ptr) {
                        while(p!=-1) {
 
                                jtom=&(itom[p]);
-                               p=lc->subcell->list[p];
+                               p=lc->subcell->list[p]; // thread safe!
 #else
                        this=&(neighbour_i[j]);
                        list_reset_f(this);
@@ -1098,21 +1097,27 @@ void *potential_force_thread(void *ptr) {
        scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
 #endif
        v3_scale(&force,&(dist_ij),scale);
-       pthread_mutex_lock(&(amutex[ai->tag])); 
+       if(pthread_mutex_lock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex lock (1)\n");
        v3_add(&(ai->f),&(ai->f),&force);
-       pthread_mutex_unlock(&(amutex[ai->tag]));       
+       if(pthread_mutex_unlock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex unlock (1)\n");
 
        /* force contribution for atom j */
        v3_scale(&force,&force,-1.0); // dri rij = - drj rij
-       pthread_mutex_lock(&(amutex[jtom->tag]));       
+       if(pthread_mutex_lock(&(amutex[jtom->tag])))
+               perror("[albe fast] mutex lock (2)\n");
        v3_add(&(jtom->f),&(jtom->f),&force);
-       pthread_mutex_unlock(&(amutex[jtom->tag]));     
+       if(pthread_mutex_unlock(&(amutex[jtom->tag])))
+               perror("[albe fast] mutex unlock (2)\n");
 
        /* virial */
-       pthread_mutex_lock(&(amutex[ai->tag])); 
+       if(pthread_mutex_lock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex lock (3)\n");
        albe_v_calc(ai,&force,&(dist_ij));
        //virial_calc(ai,&force,&(dist_ij));
-       pthread_mutex_unlock(&(amutex[ai->tag]));       
+       if(pthread_mutex_unlock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex unlock (3)\n");
 
 #ifdef DEBUG
 if(moldyn->time>DSTART&&moldyn->time<DEND) {
@@ -1135,12 +1140,16 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
 
        /* energy contribution */
        energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
-       pthread_mutex_lock(&emutex);
+       if(pthread_mutex_lock(&emutex))
+               perror("[albe fast] mutex lock (energy)\n");
        moldyn->energy+=energy;
-       pthread_mutex_unlock(&emutex);
-       pthread_mutex_lock(&(amutex[ai->tag])); 
+       if(pthread_mutex_unlock(&emutex))
+               perror("[albe fast] mutex unlock (energy)\n");
+       if(pthread_mutex_lock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex lock (4)\n");
        ai->e+=energy;
-       pthread_mutex_unlock(&(amutex[ai->tag]));       
+       if(pthread_mutex_unlock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex unlock (4)\n");
 
        /* reset k counter for second k loop */
        kcount=0;
@@ -1235,9 +1244,11 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
        v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
 
        /* force contribution */
-       pthread_mutex_lock(&(amutex[jtom->tag]));       
+       if(pthread_mutex_lock(&(amutex[jtom->tag])))
+               perror("[albe fast] mutex lock (5)\n");
        v3_add(&(jtom->f),&(jtom->f),&force);
-       pthread_mutex_unlock(&(amutex[jtom->tag]));     
+       if(pthread_mutex_unlock(&(amutex[jtom->tag])))
+               perror("[albe fast] mutex unlock (5)\n");
 
 #ifdef DEBUG
 if(moldyn->time>DSTART&&moldyn->time<DEND) {
@@ -1252,14 +1263,16 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
 #endif
 
        /* virial */
-       pthread_mutex_lock(&(amutex[ai->tag])); 
+       if(pthread_mutex_lock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex lock (6)\n");
        albe_v_calc(ai,&force,&dist_ij);
        //virial_calc(ai,&force,&dist_ij);
 
        /* force contribution to atom i */
        v3_scale(&force,&force,-1.0);
        v3_add(&(ai->f),&(ai->f),&force);
-       pthread_mutex_unlock(&(amutex[ai->tag]));       
+       if(pthread_mutex_unlock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex unlock (6)\n");
 
        /* derivative wrt k */
 #ifdef MATTONI
@@ -1273,9 +1286,11 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
 #endif
 
        /* force contribution */
-       pthread_mutex_lock(&(amutex[ktom->tag]));       
+       if(pthread_mutex_lock(&(amutex[ktom->tag])))
+               perror("[albe fast] mutex lock (7)\n");
        v3_add(&(ktom->f),&(ktom->f),&force);
-       pthread_mutex_unlock(&(amutex[ktom->tag]));     
+       if(pthread_mutex_unlock(&(amutex[ktom->tag])))
+               perror("[albe fast] mutex unlock (7)\n");
 
 #ifdef DEBUG
 if(moldyn->time>DSTART&&moldyn->time<DEND) {
@@ -1290,14 +1305,16 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
 #endif
 
        /* virial */
-       pthread_mutex_lock(&(amutex[ai->tag])); 
+       if(pthread_mutex_lock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex lock (8)\n");
        albe_v_calc(ai,&force,&dist_ik);
        //virial_calc(ai,&force,&dist_ik);
        
        /* force contribution to atom i */
        v3_scale(&force,&force,-1.0);
        v3_add(&(ai->f),&(ai->f),&force);
-       pthread_mutex_unlock(&(amutex[ai->tag]));       
+       if(pthread_mutex_unlock(&(amutex[ai->tag])))
+               perror("[albe fast] mutex unlock (8)\n");
 
        /* increase k counter */
        kcount++;