pthreads -> albe fast (beginning)
[physik/posic.git] / potentials / albe_fast.c
index 4610230..05502c6 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 ... */