X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=moldyn.c;h=c27fc6215606df4d223290ea2e08e1798d64e95c;hb=4b18a09781c27d786c32a5ada98929c4c2e38f4b;hp=8d50a69c8a4f06b28d3a75ffcc57951c0281fbc5;hpb=452a348351ae8a2255809918a05683d2510655ce;p=physik%2Fposic.git diff --git a/moldyn.c b/moldyn.c index 8d50a69..c27fc62 100644 --- a/moldyn.c +++ b/moldyn.c @@ -47,6 +47,12 @@ #undef PSE_NAME #undef PSE_COL +#ifdef PTHREADS +/* global mutexes */ +pthread_mutex_t *amutex; +pthread_mutex_t emutex; +#endif + /* * the moldyn functions */ @@ -66,13 +72,27 @@ int moldyn_init(t_moldyn *moldyn,int argc,char **argv) { rand_init(&(moldyn->random),NULL,1); moldyn->random.status|=RAND_STAT_VERBOSE; +#ifdef PTHREADS + pthread_mutex_init(&emutex,NULL); +#endif + return 0; } int moldyn_shutdown(t_moldyn *moldyn) { +#ifdef PTHREADS + int i; +#endif + printf("[moldyn] shutdown\n"); +#ifdef PTHREADS + for(i=0;icount;i++) + pthread_mutex_destroy(&(amutex[i])); + pthread_mutex_destroy(&emutex); +#endif + moldyn_log_shutdown(moldyn); link_cell_shutdown(moldyn); rand_close(&(moldyn->random)); @@ -500,6 +520,9 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass, void *ptr; t_atom *atom; char name[16]; +#ifdef PTHREADS + pthread_mutex_t *mutex; +#endif new=a*b*c; count=moldyn->count; @@ -522,6 +545,16 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass, moldyn->atom=ptr; atom=&(moldyn->atom[count]); +#ifdef PTHREADS + ptr=realloc(amutex,(count+new)*sizeof(pthread_mutex_t)); + if(!ptr) { + perror("[moldyn] mutex realloc (add atom)"); + return -1; + } + amutex=ptr; + mutex=&(amutex[count]); +#endif + /* no atoms on the boundaries (only reason: it looks better!) */ if(!origin) { orig.x=0.5*lc; @@ -579,6 +612,9 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass, atom[ret].tag=count+ret; check_per_bound(moldyn,&(atom[ret].r)); atom[ret].r_0=atom[ret].r; +#ifdef PTHREADS + pthread_mutex_init(&(mutex[ret]),NULL); +#endif } /* update total system mass */ @@ -613,6 +649,16 @@ int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr, moldyn->lc.subcell->list=ptr; #endif +#ifdef PTHREADS + ptr=realloc(amutex,(count+1)*sizeof(pthread_mutex_t)); + if(!ptr) { + perror("[moldyn] mutex realloc (add atom)"); + return -1; + } + amutex=ptr; + pthread_mutex_init(&(amutex[count]),NULL); +#endif + atom=moldyn->atom; /* initialize new atom */ @@ -1951,11 +1997,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 +2005,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 +2173,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 +2212,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 +2229,7 @@ int potential_force_calc(t_moldyn *moldyn) { } -#ifndef PTHREADS } -#endif if(moldyn->func3b_j2) moldyn->func3b_j2(moldyn,