allow -append to overrule unsupported file locking
authorBerk Hess <hess@kth.se>
Wed, 18 Apr 2012 08:28:54 +0000 (10:28 +0200)
committerBerk Hess <hess@kth.se>
Wed, 18 Apr 2012 08:49:12 +0000 (10:49 +0200)
This is a change to the previous change to let mdrun append anyhow
when file locking is not supported. Now a fatal error is generated,
unless -append is specified explicitly.
This commit refs #924

Change-Id: I98fa201fb5bd62c0de58c3c2d7e17e8b3f727c2f

include/checkpoint.h
include/mdrun.h
src/gmxlib/checkpoint.c
src/kernel/mdrun.c
src/kernel/runner.c
src/tools/gmx_membed.c

index 9dcac9461b509eaec2713b5da9a02fec231dd9d9..d1f1ce48dc25d410cce6517e37c3f0db33f11cc9 100644 (file)
@@ -62,12 +62,16 @@ void write_checkpoint(const char *fn,gmx_bool bNumberAndKeep,
  * The master node reads the file
  * and communicates all the modified number of steps and the parallel setup,
  * but not the state itself.
+ * When bAppend is set, lock the log file and truncate the existing output
+ * files so they can be appended.
+ * With bAppend and bForceAppend: truncate anyhow if the system does not
+ * support file locking.
  */
 void load_checkpoint(const char *fn,FILE **fplog,
                            t_commrec *cr,gmx_bool bPartDecomp,ivec dd_nc,
                            t_inputrec *ir,t_state *state,gmx_bool *bReadRNG, 
                            gmx_bool *bReadEkin,
-                           gmx_bool bTruncateOutputFiles);
+                    gmx_bool bAppend,gmx_bool bForceAppend);
 
 /* Read the state from checkpoint file.
  * Arrays in state that are NULL are allocated.
index d30fb0c952ce819e71853191778f9c1ffd4aea62..83789b5945a131ea757e9681e54b4a9706178239 100644 (file)
@@ -68,6 +68,7 @@ extern "C" {
 #define MD_REPRODUCIBLE   (1<<13)
 #define MD_READ_RNG       (1<<14)
 #define MD_APPENDFILES    (1<<15)
+#define MD_APPENDFILESSET (1<<21)
 #define MD_KEEPANDNUMCPT  (1<<16)
 #define MD_READ_EKIN      (1<<17)
 #define MD_STARTFROMCPT   (1<<18)
index 0185893d0af2a2f631c03fabc276b4400e75b53e..0f7c8c71f0993b18e673649359091aa8b98e5d7d 100644 (file)
@@ -1450,7 +1450,8 @@ static void read_checkpoint(const char *fn,FILE **pfplog,
                             t_commrec *cr,gmx_bool bPartDecomp,ivec dd_nc,
                             int eIntegrator,gmx_large_int_t *step,double *t,
                             t_state *state,gmx_bool *bReadRNG,gmx_bool *bReadEkin,
-                            int *simulation_part,gmx_bool bAppendOutputFiles)
+                            int *simulation_part,
+                            gmx_bool bAppendOutputFiles,gmx_bool bForceAppend)
 {
     t_fileio *fp;
     int  i,j,rc;
@@ -1745,6 +1746,10 @@ static void read_checkpoint(const char *fn,FILE **pfplog,
             /* lock log file */                
             if (i==0)
             {
+                /* Note that there are systems where the lock operation
+                 * will succeed, but a second process can also lock the file.
+                 * We should probably try to detect this.
+                 */
 #if !((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__) 
                 if (fcntl(fileno(gmx_fio_getfp(chksum_file)), F_SETLK, &fl)
                     ==-1)
@@ -1754,10 +1759,17 @@ static void read_checkpoint(const char *fn,FILE **pfplog,
                 {
                     if (errno == ENOSYS)
                     {
-                        fprintf(stderr,"\nNOTE: File locking is not supported on this system, will not lock %s\n\n",outputfiles[i].filename);
-                        if (fplog)
+                        if (!bForceAppend)
+                        {
+                            gmx_fatal(FARGS,"File locking is not supported on this system. Use -noappend or specify -append explicitly to append anyhow.");
+                        }
+                        else
                         {
-                            fprintf(fplog,"\nNOTE: File locking not supported on this system, will not lock %s\n\n",outputfiles[i].filename);
+                            fprintf(stderr,"\nNOTE: File locking is not supported on this system, will not lock %s\n\n",outputfiles[i].filename);
+                            if (fplog)
+                            {
+                                fprintf(fplog,"\nNOTE: File locking not supported on this system, will not lock %s\n\n",outputfiles[i].filename);
+                            }
                         }
                     }
                     else if (errno == EACCES || errno == EAGAIN)
@@ -1844,7 +1856,8 @@ static void read_checkpoint(const char *fn,FILE **pfplog,
 void load_checkpoint(const char *fn,FILE **fplog,
                      t_commrec *cr,gmx_bool bPartDecomp,ivec dd_nc,
                      t_inputrec *ir,t_state *state,
-                     gmx_bool *bReadRNG,gmx_bool *bReadEkin,gmx_bool bAppend)
+                     gmx_bool *bReadRNG,gmx_bool *bReadEkin,
+                     gmx_bool bAppend,gmx_bool bForceAppend)
 {
     gmx_large_int_t step;
     double t;
@@ -1854,7 +1867,7 @@ void load_checkpoint(const char *fn,FILE **fplog,
       read_checkpoint(fn,fplog,
                       cr,bPartDecomp,dd_nc,
                       ir->eI,&step,&t,state,bReadRNG,bReadEkin,
-                      &ir->simulation_part,bAppend);
+                      &ir->simulation_part,bAppend,bForceAppend);
     }
     if (PAR(cr)) {
       gmx_bcast(sizeof(cr->npmenodes),&cr->npmenodes,cr);
index 085e35020fb3d2e86e5878ed770def40bea88a13..9b6464dd5fc668e438632edc22c5b211fc3644b7 100644 (file)
@@ -634,6 +634,7 @@ int main(int argc,char *argv[])
   Flags = Flags | (bRerunVSite   ? MD_RERUN_VSITE  : 0);
   Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
   Flags = Flags | (bAppendFiles  ? MD_APPENDFILES  : 0); 
+  Flags = Flags | (opt2parg_bSet("-append", asize(pa),pa) ? MD_APPENDFILESSET : 0); 
   Flags = Flags | (bKeepAndNumCPT ? MD_KEEPANDNUMCPT : 0); 
   Flags = Flags | (sim_part>1    ? MD_STARTFROMCPT : 0); 
   Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
index 0db72cb64d489d469c8d1d344ef683baf4d99d44..b215a8409fb3c32c85d7052fd170266c2c48d7c2 100644 (file)
@@ -530,7 +530,8 @@ int mdrunner(int nthreads_requested, FILE *fplog,t_commrec *cr,int nfile,
             load_checkpoint(opt2fn_master("-cpi",nfile,fnm,cr),&fplog,
                             cr,Flags & MD_PARTDEC,ddxyz,
                             inputrec,state,&bReadRNG,&bReadEkin,
-                            (Flags & MD_APPENDFILES));
+                            (Flags & MD_APPENDFILES),
+                            (Flags & MD_APPENDFILESSET));
             
             if (bReadRNG)
             {
index 91aeb2b7b761d146aaeaad1e3c8e7ff6c3fefc80..e3d4c671ff9bc2557e7c33c71250bba0e2ac80d9 100644 (file)
@@ -3087,7 +3087,8 @@ int mdrunner_membed(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
             load_checkpoint(opt2fn_master("-cpi",nfile,fnm,cr),&fplog,
                             cr,Flags & MD_PARTDEC,ddxyz,
                             inputrec,state,&bReadRNG,&bReadEkin,
-                            (Flags & MD_APPENDFILES));
+                            (Flags & MD_APPENDFILES),
+                           (Flags & MD_APPENDFILESSET));
 
             if (bReadRNG)
             {
@@ -3759,6 +3760,7 @@ int gmx_membed(int argc,char *argv[])
        Flags = Flags | (bRerunVSite   ? MD_RERUN_VSITE  : 0);
        Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
        Flags = Flags | (bAppendFiles  ? MD_APPENDFILES  : 0);
+       Flags = Flags | (opt2parg_bSet("-append", asize(pa),pa) ? MD_APPENDFILESSET : 0); 
        Flags = Flags | (sim_part>1    ? MD_STARTFROMCPT : 0);
        Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);