fixed signal handling in md_openmm
authorSzilard Pall <pszilard@cbr.su.se>
Wed, 12 May 2010 11:47:20 +0000 (13:47 +0200)
committerSzilard Pall <pszilard@cbr.su.se>
Wed, 12 May 2010 11:47:20 +0000 (13:47 +0200)
src/kernel/md_openmm.c

index 2db418795c4ac5c93b5f100a315a62ef982fd179..2e5035a92a574a8b91085826e542bef63d9413f7 100644 (file)
@@ -456,7 +456,7 @@ double do_md_openmm(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
         bLastStep = (step_rel == ir->nsteps);
         t = t0 + step*ir->delta_t;
 
-        if (gs.set[eglsSTOPCOND] != (int)gmx_stop_cond_none )
+        if (gs.set[eglsSTOPCOND] != 0)
         {
             bLastStep = TRUE;
         }
@@ -582,19 +582,27 @@ double do_md_openmm(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
         if (((int)gmx_get_stop_condition() > handled_stop_condition) &&
             MASTERTHREAD(cr))
         {
-            gs.sig[eglsSTOPCOND]=(int)gmx_get_stop_condition();
+           /* this is just make gs.sig compatible with the hack 
+               of sending signals around by MPI_Reduce with together with
+               other floats */
+            if ( gmx_get_stop_condition() == gmx_stop_cond_next_ns )
+                gs.set[eglsSTOPCOND]=1;
+            if ( gmx_get_stop_condition() == gmx_stop_cond_next )
+                gs.set[eglsSTOPCOND]=1;
+            /* < 0 means stop at next step, > 0 means stop at next NS step */
             if (fplog)
             {
                 fprintf(fplog,
                         "\n\nReceived the %s signal, stopping at the next %sstep\n\n",
                         gmx_get_signal_name(),
-                        gs.sig[eglsSTOPCOND]==gmx_stop_cond_next_ns ? "NS " :   "");
+                        gs.sig[eglsSTOPCOND]==1 ? "NS " : "");
                 fflush(fplog);
             }
             fprintf(stderr,
                     "\n\nReceived the %s signal, stopping at the next %sstep\n\n",
                     gmx_get_signal_name(),
-                    gs.sig[eglsSTOPCOND]==gmx_stop_cond_next_ns ? "NS " : "");
+                    gs.sig[eglsSTOPCOND]==1 ? "NS " : "");
+            fflush(stderr);
             handled_stop_condition=(int)gmx_get_stop_condition();
         }
         else if (MASTER(cr) &&
@@ -602,7 +610,7 @@ double do_md_openmm(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
                  gs.set[eglsSTOPCOND] == 0)
         {
             /* Signal to terminate the run */
-            gs.set[eglsSTOPCOND] = gmx_stop_cond_next;
+            gs.set[eglsSTOPCOND] = 1;
             if (fplog)
             {
                 fprintf(fplog,"\nStep %s: Run time exceeded %.3f hours, will terminate the run\n",gmx_step_str(step,sbuf),max_hours*0.99);