From: hackbard Date: Thu, 2 Oct 2008 13:34:14 +0000 (+0200) Subject: pthreads -> albe fast (beginning) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=b4628acf6967b179451bd36f74c2ba312590ecbf;p=physik%2Fposic.git pthreads -> albe fast (beginning) --- diff --git a/moldyn.c b/moldyn.c index 8d50a69..d7d89bc 100644 --- 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, diff --git a/moldyn.h b/moldyn.h index 6fda9ce..31794c8 100644 --- 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; diff --git a/potentials/albe.c b/potentials/albe.c index b00e173..08ce4fa 100644 --- a/potentials/albe.c +++ b/potentials/albe.c @@ -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) { diff --git a/potentials/albe.h b/potentials/albe.h index 3d0d7e5..87f45a0 100644 --- a/potentials/albe.h +++ b/potentials/albe.h @@ -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); diff --git a/potentials/albe_fast.c b/potentials/albe_fast.c index 4610230..05502c6 100644 --- a/potentials/albe_fast.c +++ b/potentials/albe_fast.c @@ -29,6 +29,13 @@ #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