]> hackdaworld.org Git - physik/posic.git/commitdiff
pthreads -> albe fast (beginning)
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 2 Oct 2008 13:34:14 +0000 (15:34 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 2 Oct 2008 13:34:14 +0000 (15:34 +0200)
moldyn.c
moldyn.h
potentials/albe.c
potentials/albe.h
potentials/albe_fast.c

index 8d50a69c8a4f06b28d3a75ffcc57951c0281fbc5..d7d89bc2328506715a1d5d82e439267ce41281fa 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -1951,11 +1951,6 @@ int potential_force_calc(t_moldyn *moldyn) {
 #endif
        u8 bc_ij,bc_ik;
        int dnlc;
-#ifdef PTHREADS
-       int ret;
-       pthread_t kthread[27];
-       t_kdata kdata[27];
-#endif
 
        count=moldyn->count;
        itom=moldyn->atom;
@@ -1964,10 +1959,6 @@ int potential_force_calc(t_moldyn *moldyn) {
        atom=moldyn->atom;
 #endif
 
-#ifdef PTHREADS
-       memset(kdata,0,27*sizeof(t_kdata));
-#endif
-
        /* reset energy */
        moldyn->energy=0.0;
 
@@ -2136,9 +2127,7 @@ int potential_force_calc(t_moldyn *moldyn) {
                                        continue;
                        
                                /* first loop over atoms k */
-#ifndef PTHREADS
                                if(moldyn->func3b_k1) {
-#endif
 
                                for(k=0;k<27;k++) {
 
@@ -2177,24 +2166,11 @@ int potential_force_calc(t_moldyn *moldyn) {
                                                if(ktom==&(itom[i]))
                                                        continue;
 
-#ifdef PTHREADS
-                                               kdata[k].moldyn=moldyn;
-                                               kdata[k].ai=&(itom[i]);
-                                               kdata[k].aj=jtom;
-                                               kdata[k].ak=ktom;
-                                               kdata[k].bc=bc_ik;
-       ret=pthread_create(&(kthread[k]),NULL,moldyn->func3b_k1,&(kdata[k]));
-       if(ret) {
-               perror("[moldyn] create k1 thread");
-               return ret;
-       }
-#else
                                                moldyn->func3b_k1(moldyn,
                                                                  &(itom[i]),
                                                                  jtom,
                                                                  ktom,
                                                                  bc_ik|bc_ij);
-#endif
 
 #ifdef STATIC_LISTS
                                        }
@@ -2207,9 +2183,7 @@ int potential_force_calc(t_moldyn *moldyn) {
 
                                }
 
-#ifndef PTHREADS
                                }
-#endif
 
                                if(moldyn->func3b_j2)
                                        moldyn->func3b_j2(moldyn,
index 6fda9ceef79e9853c0967c31004a59240e83c820..31794c898f2eed1e5faf5b4d0146a07892af706b 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -117,12 +117,8 @@ typedef struct s_moldyn {
        int (*func3b_j1)(struct s_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
        int (*func3b_j2)(struct s_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
        int (*func3b_j3)(struct s_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
-#ifdef PTHREADS
-       void *(*func3b_k1)(void *ptr);
-#else
        int (*func3b_k1)(struct s_moldyn *moldyn,
                         t_atom *ai,t_atom *aj,t_atom *ak,u8 bck);
-#endif
        int (*func3b_k2)(struct s_moldyn *moldyn,
                         t_atom *ai,t_atom *aj,t_atom *ak,u8 bck);
        void *pot_params;
index b00e173757e0b4bb3d538b110c610cb8bb46d891..08ce4faf70518302c84462bba793370b74a0fcd2 100644 (file)
@@ -176,12 +176,8 @@ int albe_mult_3bp_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
 }
 
 /* albe 3 body potential function (first k loop) */
-#ifdef PTHREADS
-void *albe_mult_3bp_k1(void *ptr) {
-#else
 int albe_mult_3bp_k1(t_moldyn *moldyn,
                      t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
-#endif
 
        t_albe_mult_params *params;
        t_albe_exchange *exchange;
@@ -192,19 +188,6 @@ int albe_mult_3bp_k1(t_moldyn *moldyn,
        double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
        double f_c_ik,df_c_ik;
        int kcount;
-#ifdef PTHREADS
-       t_kdata *kdata;
-       t_moldyn *moldyn;
-       t_atom *ai,*aj,*ak;
-       u8 bc;
-
-       kdata=ptr;
-       moldyn=kdata->moldyn;
-       ai=kdata->ai;
-       aj=kdata->aj;
-       ak=kdata->ak;
-       bc=kdata->bc;
-#endif
 
        params=moldyn->pot_params;
        exchange=&(params->exchange);
@@ -298,12 +281,8 @@ int albe_mult_3bp_k1(t_moldyn *moldyn,
        /* increase k counter */
        exchange->kcount++;
 
-#ifdef PTHREADS
-}
-#else
        return 0;
 }
-#endif
 
 int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
 
index 3d0d7e5b7394e885be9117f23f6889f4b9f71b81..87f45a08247e952c0cda7bbb5b93567c595faf45 100644 (file)
@@ -80,23 +80,11 @@ typedef struct s_albe_mult_params {
        t_albe_exchange exchange;       /* exchange between 2bp and 3bp calc */
 } t_albe_mult_params;
 
-#ifdef PTHREADS
-typedef struct s_kdata {
-       t_moldyn *moldyn;
-       t_atom *ai,*aj,*ak;
-       unsigned char bc;
-} t_kdata;
-#endif
-
 /* function prototypes */
 int albe_mult_set_params(t_moldyn *moldyn,int element1,int elemnt2);
 int albe_mult_3bp_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
-#ifdef PTHREADS
-void *albe_mult_3bp_k1(void *ptr);
-#else
 int albe_mult_3bp_k1(t_moldyn *moldyn,
                         t_atom *ai,t_atom *aj,t_atom *ak,u8 bc);
-#endif
 int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
 int albe_mult_3bp_k2(t_moldyn *moldyn,
                         t_atom *ai,t_atom *aj,t_atom *ak,u8 bc);
index 46102303d364ca038496753053a16a056c0403eb..05502c603f0d41da1aa7a612e387c77c8415ebfc 100644 (file)
 #include "../math/math.h"
 #include "albe.h"
 
+#ifdef PTHREADS
+typedef struct s_kdata {
+       t_moldyn *moldyn;
+       t_atom *itom,*jtom;
+} t_kdata;
+#endif
+
 /*
  * virial calculation
  */
@@ -169,6 +176,11 @@ int albe_potential_force_calc(t_moldyn *moldyn) {
 #endif
        u8 bc_ij,bc_ik;
        int dnlc;
+#ifdef PTHREADS
+       int ret;
+       t_kdata kdata[27];
+       pthread_t kthread[27];
+#endif
 
        // needed to work
        t_atom *ai;
@@ -354,6 +366,17 @@ int albe_potential_force_calc(t_moldyn *moldyn) {
                                /* first loop over atoms k */
                                for(k=0;k<27;k++) {
 
+#ifdef PTHREADS
+       // create threads
+       kdata.moldyn=moldyn;
+       kdata.jtom=jtom;
+       kdata.itom=&(itom[i]);
+       ret=pthread_create(&(kthread[k]),NULL,k1_thread,&(kdata[k]));
+       if(ret) {
+               perror("[albe fast] thread create");
+               return ret;
+       }
+#else
                                        bc_ik=(k<dnlc)?0:1;
 #ifdef STATIC_LISTS
                                        q=0;
@@ -494,8 +517,6 @@ int albe_potential_force_calc(t_moldyn *moldyn) {
        /* increase k counter */
        kcount++;
 
-#endif // PTHREADS
-
 #ifdef STATIC_LISTS
                                        }
 #elif LOWMEM_LISTS
@@ -505,8 +526,21 @@ int albe_potential_force_calc(t_moldyn *moldyn) {
                                                L_NO_NEXT_ELEMENT);
 #endif
 
+#endif // PTHREADS
+
                                }
 
+#ifdef PTHREADS
+       // join threads
+       for(k=0;k<27;k++) {
+               ret=pthread_join(kthread[k],NULL);
+               if(ret) {
+                       perror("[albe fast] join thread");
+                       return ret;
+               }
+       }
+#endif
+
 
 /* j2 func here ... */