From 815b8841eb76564b2f90421d4eae180253453106 Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 16 Oct 2008 14:16:29 +0200 Subject: [PATCH] pthredas working now (by partitioning atoms into count/#THREADS blocks) --- Makefile | 6 ++-- moldyn.c | 20 ++++++----- moldyn.h | 2 +- potentials/albe_fast.c | 78 +++++++++++++++++------------------------- 4 files changed, 47 insertions(+), 59 deletions(-) diff --git a/Makefile b/Makefile index 2a74cb0..1cc3779 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,10 @@ CFLAGS += -O3 -march=native -msse2 -mfpmath=sse CFLAGS += -g #CFLAGS += -ffloat-store -#CFLAGS+= -DPARALLEL -fopenmp -CFLAGS+= -DPTHREADS -lpthread +#CFLAGS += -DPARALLEL -fopenmp +#CFLAGS += -DPTHREADS -lpthread +#CFLAGS += -DVISUAL_THREAD -lpthread +CFLAGS += -DPTHREADS -DVISUAL_THREAD -lpthread CFLAGS += -DALBE CFLAGS += -DALBE_FAST diff --git a/moldyn.c b/moldyn.c index c27fc62..ed30815 100644 --- a/moldyn.c +++ b/moldyn.c @@ -23,7 +23,7 @@ #include #endif -#ifdef PTHREADS +#if defined PTHREADS || defined VISUAL_THREAD #include #endif @@ -1670,7 +1670,7 @@ int moldyn_integrate(t_moldyn *moldyn) { struct timeval t1,t2; //double tp; -#ifdef PTHREADS +#ifdef VISUAL_THREAD u8 first,change; pthread_t io_thread; int ret; @@ -1730,7 +1730,7 @@ int moldyn_integrate(t_moldyn *moldyn) { moldyn->debug=0; /* zero & init moldyn copy */ -#ifdef PTHREADS +#ifdef VISUAL_THREAD memset(&md_copy,0,sizeof(t_moldyn)); atom_copy=malloc(moldyn->count*sizeof(t_atom)); if(atom_copy==NULL) { @@ -1838,7 +1838,7 @@ int moldyn_integrate(t_moldyn *moldyn) { } if(a) { if(!(moldyn->total_steps%a)) { -#ifdef PTHREADS +#ifdef VISUAL_THREAD /* check whether thread has not terminated yet */ if(!first) { ret=pthread_join(io_thread,NULL); @@ -1876,7 +1876,7 @@ int moldyn_integrate(t_moldyn *moldyn) { /* get current time */ gettimeofday(&t2,NULL); -printf("\rsched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)", +printf("sched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)\n", sched->count,i,moldyn->total_steps, moldyn->t,moldyn->t_avg, moldyn->p/BAR,moldyn->p_avg/BAR, @@ -3020,7 +3020,7 @@ int visual_bonds_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom, return 0; } -#ifdef PTHREADS +#ifdef VISUAL_THREAD void *visual_atoms(void *ptr) { #else int visual_atoms(t_moldyn *moldyn) { @@ -3033,7 +3033,7 @@ int visual_atoms(t_moldyn *moldyn) { t_visual *v; t_atom *atom; t_vb vb; -#ifdef PTHREADS +#ifdef VISUAL_THREAD t_moldyn *moldyn; moldyn=ptr; @@ -3051,7 +3051,7 @@ int visual_atoms(t_moldyn *moldyn) { vb.fd=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); if(vb.fd<0) { perror("open visual save file fd"); -#ifndef PTHREADS +#ifndef VISUAL_THREAD return -1; #endif } @@ -3073,7 +3073,9 @@ int visual_atoms(t_moldyn *moldyn) { atom[i].ekin); // bonds between atoms +#ifndef VISUAL_THREAD process_2b_bonds(moldyn,&vb,visual_bonds_process); +#endif // boundaries if(dim.x) { @@ -3119,7 +3121,7 @@ int visual_atoms(t_moldyn *moldyn) { close(vb.fd); -#ifdef PTHREADS +#ifdef VISUAL_THREAD pthread_exit(NULL); } diff --git a/moldyn.h b/moldyn.h index 31794c8..ee0a6dc 100644 --- a/moldyn.h +++ b/moldyn.h @@ -481,7 +481,7 @@ int bond_analyze(t_moldyn *moldyn,double *quality); int visual_init(t_moldyn *moldyn,char *filebase); int visual_bonds_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom, void *data,u8 bc); -#ifdef PTHREADS +#ifdef VISUAL_THREAD void *visual_atoms(void *ptr); #else int visual_atoms(t_moldyn *moldyn); diff --git a/potentials/albe_fast.c b/potentials/albe_fast.c index 952f1fe..603606e 100644 --- a/potentials/albe_fast.c +++ b/potentials/albe_fast.c @@ -703,7 +703,7 @@ if(moldyn->time>DSTART&&moldyn->timepot_params; + /* get energy, force and virial for atoms */ - /* get energy, force and virial of every atom */ - - /* first (and only) loop over atoms i */ - for(i=0;istart;iend;i++) { if(!(itom[i].attr&ATOM_ATTR_3BP)) - continue; + return 0; link_cell_neighbour_index(moldyn, (itom[i].r.x+moldyn->dim.x/2)/lc->x, @@ -1302,6 +1300,8 @@ if(moldyn->time>DSTART&&moldyn->timetime>DSTART&&moldyn->timef.x,itom->f.y,itom->f.z); if(moldyn->time>DSTART&&moldyn->time %d\n",i); + /* join threads */ + for(j=0;j