]> hackdaworld.org Git - physik/posic.git/commitdiff
io thread needed for visual atom call! changed.
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Fri, 26 Sep 2008 09:11:52 +0000 (11:11 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Fri, 26 Sep 2008 09:11:52 +0000 (11:11 +0200)
moldyn.c
moldyn.h

index 4788a81e1d4303b35b54fa4b27a267bce6a6d53f..e936b11d0ce5a977330d9989bc7c156cfc25e014 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -1608,33 +1608,6 @@ 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) {
@@ -1644,10 +1617,8 @@ 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;
@@ -1806,6 +1777,21 @@ int moldyn_integrate(t_moldyn *moldyn) {
                }
                if(s) {
                        if(!(moldyn->total_steps%s)) {
+                               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);
+                       }       
+               }
+               if(a) {
+                       if(!(moldyn->total_steps%a)) {
 #ifdef PTHREADS
        /* check whether thread has not terminated yet */
        if(!first) {
@@ -1828,29 +1814,14 @@ int moldyn_integrate(t_moldyn *moldyn) {
        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);
+       ret=pthread_create(&io_thread,NULL,visual_atoms,&md_copy);
        if(ret) {
-               perror("[moldyn] create save file thread\n");
+               perror("[moldyn] create visual atoms 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);
-                               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);
-#endif
-                       }       
-               }
-               if(a) {
-                       if(!(moldyn->total_steps%a)) {
                                visual_atoms(moldyn);
+#endif
                        }
                }
 
@@ -3002,7 +2973,11 @@ int visual_bonds_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
        return 0;
 }
 
+#ifdef PTHREADS
+void *visual_atoms(void *ptr) {
+#else
 int visual_atoms(t_moldyn *moldyn) {
+#endif
 
        int i;
        char file[128+64];
@@ -3011,6 +2986,11 @@ int visual_atoms(t_moldyn *moldyn) {
        t_visual *v;
        t_atom *atom;
        t_vb vb;
+#ifdef PTHREADS
+       t_moldyn *moldyn;
+
+       moldyn=ptr;
+#endif
 
        v=&(moldyn->vis);
        dim.x=v->dim.x;
@@ -3024,7 +3004,9 @@ 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
                return -1;
+#endif
        }
 
        /* write the actual data file */
@@ -3090,8 +3072,15 @@ int visual_atoms(t_moldyn *moldyn) {
 
        close(vb.fd);
 
+#ifdef PTHREADS
+       pthread_exit(NULL);
+
+}
+#else
+
        return 0;
 }
+#endif
 
 /*
  * fpu cntrol functions
index 87c89483cd362e4cfd32fc4dcc8677a4398d39d0..31794c898f2eed1e5faf5b4d0146a07892af706b 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -481,7 +481,11 @@ 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
+void *visual_atoms(void *ptr);
+#else
 int visual_atoms(t_moldyn *moldyn);
+#endif
 
 int fpu_set_rtd(void);