* 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.
#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)
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;
/* 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)
{
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)
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;
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);
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);
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)
{
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)
{
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);