]> hackdaworld.org Git - physik/posic.git/commitdiff
pthredas working now (by partitioning atoms into count/#THREADS blocks)
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 16 Oct 2008 12:16:29 +0000 (14:16 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 16 Oct 2008 12:16:29 +0000 (14:16 +0200)
Makefile
moldyn.c
moldyn.h
potentials/albe_fast.c

index 2a74cb0981f73c8874d8852fc9ce9a567fe0dd97..1cc3779f5d42d8ab9a85e812735615937f074d95 100644 (file)
--- 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
index c27fc6215606df4d223290ea2e08e1798d64e95c..ed30815a6acb2b0d9cf151f990a18d3579067483 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -23,7 +23,7 @@
 #include <omp.h>
 #endif
 
-#ifdef PTHREADS
+#if defined PTHREADS || defined VISUAL_THREAD
 #include <pthread.h>
 #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);
 
 }
index 31794c898f2eed1e5faf5b4d0146a07892af706b..ee0a6dc87429495a99be906c7fbf8e409bb705aa 100644 (file)
--- 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);
index 952f1fe41d4dee5e69c816bee96f9906d44228de..603606e6b9ce081e108f64d7b33f544d009e35d9 100644 (file)
@@ -703,7 +703,7 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
 
 typedef struct s_pft_data {
        t_moldyn *moldyn;
-       int i;
+       int start,end;
 } t_pft_data;
 
 void *potential_force_thread(void *ptr) {
@@ -785,14 +785,12 @@ void *potential_force_thread(void *ptr) {
        // optimized
        params=moldyn->pot_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;i<count;i++) {
+       for(i=pft_data->start;i<pft_data->end;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->time<DEND) {
 #endif
                
                }
+
+       } // i loop
                
 #ifdef DEBUG
        //printf("\n\n");
@@ -1310,8 +1310,6 @@ if(moldyn->time>DSTART&&moldyn->time<DEND) {
        printf("\n\n");
 #endif
 
-       }
-
 #ifdef DEBUG
        //printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
        if(moldyn->time>DSTART&&moldyn->time<DEND) {
@@ -1365,49 +1363,37 @@ int albe_potential_force_calc(t_moldyn *moldyn) {
 
        }
 
-       i=0;
-       while(i<count) {
-
-               /* start threads */
-               for(j=0;j<MAX_THREADS;j++) {
-
-                       /* break if all atoms are processed */
-                       if(j+i==count)
-                               break;
-
-                       /* prepare thread data */
-                       pft_data[j].moldyn=moldyn;
-                       pft_data[j].i=j+i;
+       /* start threads */
+       for(j=0;j<MAX_THREADS;j++) {
 
-                       ret=pthread_create(&(pft_thread[j]),NULL,
-                                           potential_force_thread,
-                                           &(pft_data[j]));
-                       if(ret)  {
-                               perror("[albe fast] pf thread create");
-                               return ret;
-                       }
+               /* prepare thread data */
+               pft_data[j].moldyn=moldyn;
+               pft_data[j].start=j*count/MAX_THREADS;
+               if(j==MAX_THREADS-1) {
+                       pft_data[j].end=count;
                }
-
-               //printf("threads created! %d\n",j);
-
-               /* join threads */
-               for(j=0;j<MAX_THREADS;j++) {
-
-                       if(j+i==count)
-                               break;
-
-                       ret=pthread_join(pft_thread[j],NULL);
-                       if(ret) {
-                               perror("[albe fast] pf thread join");
-                               return ret;
-                       }
+               else {
+                       pft_data[j].end=pft_data[j].start;
+                       pft_data[j].end+=count/MAX_THREADS;
                }
 
-               /* increment counter */
-               i+=MAX_THREADS;
+               ret=pthread_create(&(pft_thread[j]),NULL,
+                                   potential_force_thread,
+                                   &(pft_data[j]));
+               if(ret)  {
+                       perror("[albe fast] pf thread create");
+                       return ret;
+               }
+       }
 
-               //printf("threads joined! -> %d\n",i);
+       /* join threads */
+       for(j=0;j<MAX_THREADS;j++) {
 
+               ret=pthread_join(pft_thread[j],NULL);
+               if(ret) {
+                       perror("[albe fast] pf thread join");
+                       return ret;
+               }
        }
 
        /* some postprocessing */
@@ -1427,8 +1413,6 @@ int albe_potential_force_calc(t_moldyn *moldyn) {
                               i);
        }
 
-       pthread_exit(NULL);
-
        return 0;
 }