]> hackdaworld.org Git - physik/posic.git/commitdiff
added pthreads (for io only by now) + refresh screen for i count +
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 25 Sep 2008 12:45:15 +0000 (14:45 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 25 Sep 2008 12:45:15 +0000 (14:45 +0200)
longer save file names

Makefile
moldyn.c

index 462a9b7f4e5b53e90d7938bba6050e34df3d0a3a..2a74cb0981f73c8874d8852fc9ce9a567fe0dd97 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ CFLAGS += -g
 #CFLAGS += -ffloat-store
 
 #CFLAGS+= -DPARALLEL -fopenmp
+CFLAGS+= -DPTHREADS -lpthread
 
 CFLAGS += -DALBE
 CFLAGS += -DALBE_FAST
index 3ac0a2d46b67c915bce1188b9707ead8aedd13b1..4788a81e1d4303b35b54fa4b27a267bce6a6d53f 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
 #include <omp.h>
 #endif
 
+#ifdef PTHREADS
+#include <pthread.h>
+#endif
+
 #include "moldyn.h"
 #include "report/report.h"
 
@@ -1604,6 +1608,33 @@ int moldyn_set_schedule_hook(t_moldyn *moldyn,set_hook hook,void *hook_params) {
  *
  */
 
+/* helper / special functions */
+
+#ifdef PTHREADS
+void *write_save_file(void *ptr) {
+
+       int fd;
+       char dir[128];
+       t_moldyn *moldyn;
+
+       moldyn=ptr;
+
+       snprintf(dir,128,"%s/s-%08.f.save",moldyn->vlsdir,moldyn->time);
+       fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,S_IRUSR|S_IWUSR);
+       if(fd<0) perror("[moldyn] save fd open");
+       else {
+               write(fd,moldyn,sizeof(t_moldyn));
+               write(fd,moldyn->atom,moldyn->count*sizeof(t_atom));
+       }
+
+       close(fd);
+
+       pthread_exit(NULL);
+
+       return 0;
+}
+#endif
+
 /* start the integration */
 
 int moldyn_integrate(t_moldyn *moldyn) {
@@ -1613,13 +1644,26 @@ int moldyn_integrate(t_moldyn *moldyn) {
        t_3dvec momentum;
        t_moldyn_schedule *sched;
        t_atom *atom;
+#ifndef PTHREADS
        int fd;
        char dir[128];
+#endif
        double ds;
        double energy_scale;
        struct timeval t1,t2;
        //double tp;
 
+#ifdef PTHREADS
+       u8 first,change;
+       pthread_t io_thread;
+       int ret;
+       t_moldyn md_copy;
+       t_atom *atom_copy;
+
+       first=1;
+       change=0;
+#endif
+
        sched=&(moldyn->schedule);
        atom=moldyn->atom;
 
@@ -1668,6 +1712,16 @@ int moldyn_integrate(t_moldyn *moldyn) {
        /* debugging, ignore */
        moldyn->debug=0;
 
+       /* zero & init moldyn copy */
+#ifdef PTHREADS
+       memset(&md_copy,0,sizeof(t_moldyn));
+       atom_copy=malloc(moldyn->count*sizeof(t_atom));
+       if(atom_copy==NULL) {
+               perror("[moldyn] malloc atom copy (init)");
+               return -1;
+       }
+#endif
+
        /* tell the world */
        printf("[moldyn] integration start, go get a coffee ...\n");
 
@@ -1752,7 +1806,35 @@ int moldyn_integrate(t_moldyn *moldyn) {
                }
                if(s) {
                        if(!(moldyn->total_steps%s)) {
-                               snprintf(dir,128,"%s/s-%07.f.save",
+#ifdef PTHREADS
+       /* check whether thread has not terminated yet */
+       if(!first) {
+               ret=pthread_join(io_thread,NULL);
+       }
+       first=0;
+       /* prepare and start thread */
+       if(moldyn->count!=md_copy.count) {
+               free(atom_copy);
+               change=1;
+       }
+       memcpy(&md_copy,moldyn,sizeof(t_moldyn));
+       if(change) {
+               atom_copy=malloc(moldyn->count*sizeof(t_atom));
+               if(atom_copy==NULL) {
+                       perror("[moldyn] malloc atom copy (change)");
+                       return -1;
+               }
+       }
+       md_copy.atom=atom_copy;
+       memcpy(atom_copy,moldyn->atom,moldyn->count*sizeof(t_atom));
+       change=0;
+       ret=pthread_create(&io_thread,NULL,write_save_file,&md_copy);
+       if(ret) {
+               perror("[moldyn] create save file thread\n");
+               return -1;
+       }
+#else
+                               snprintf(dir,128,"%s/s-%08.f.save",
                                         moldyn->vlsdir,moldyn->time);
                                fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,
                                        S_IRUSR|S_IWUSR);
@@ -1763,6 +1845,7 @@ int moldyn_integrate(t_moldyn *moldyn) {
                                              moldyn->count*sizeof(t_atom));
                                }
                                close(fd);
+#endif
                        }       
                }
                if(a) {
@@ -1772,7 +1855,7 @@ int moldyn_integrate(t_moldyn *moldyn) {
                }
 
                /* display progress */
-               if(!(moldyn->total_steps%10)) {
+               if(!(i%10)) {
                        /* get current time */
                        gettimeofday(&t2,NULL);
 
@@ -2937,7 +3020,7 @@ int visual_atoms(t_moldyn *moldyn) {
 
        help=(dim.x+dim.y);
 
-       sprintf(file,"%s/atomic_conf_%07.f.xyz",v->fb,moldyn->time);
+       sprintf(file,"%s/atomic_conf_%08.f.xyz",v->fb,moldyn->time);
        vb.fd=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
        if(vb.fd<0) {
                perror("open visual save file fd");
@@ -2947,7 +3030,7 @@ int visual_atoms(t_moldyn *moldyn) {
        /* write the actual data file */
 
        // povray header
-       dprintf(vb.fd,"# [P] %d %07.f <%f,%f,%f>\n",
+       dprintf(vb.fd,"# [P] %d %08.f <%f,%f,%f>\n",
                moldyn->count,moldyn->time,help/40.0,help/40.0,-0.8*help);
 
        // atomic configuration