void gmx_log_close(FILE *fp) { if (fp) { gmx_fatal_set_log_file(NULL); gmx_fio_fclose(fp); } }
void gmx_log_open(const char *lognm, const t_commrec *cr, gmx_bool bAppendFiles, FILE** fplog) { int pid; char host[256]; char timebuf[STRLEN]; FILE *fp = *fplog; debug_gmx(); if (!bAppendFiles) { fp = gmx_fio_fopen(lognm, bAppendFiles ? "a+" : "w+" ); } gmx_fatal_set_log_file(fp); /* Get some machine parameters */ gmx_gethostname(host, 256); pid = gmx_getpid(); gmx_format_current_time(timebuf, STRLEN); if (bAppendFiles) { fprintf(fp, "\n" "\n" "-----------------------------------------------------------\n" "Restarting from checkpoint, appending to previous log file.\n" "\n" ); } fprintf(fp, "Log file opened on %s" "Host: %s pid: %d rank ID: %d number of ranks: %d\n", timebuf, host, pid, cr->nodeid, cr->nnodes); try { gmx::BinaryInformationSettings settings; settings.extendedInfo(true); settings.copyright(!bAppendFiles); gmx::printBinaryInformation(fp, gmx::getProgramContext(), settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; fprintf(fp, "\n"); fflush(fp); debug_gmx(); *fplog = fp; }
void gmx_log_open(const char *lognm, const t_commrec *cr, gmx_bool bMasterOnly, gmx_bool bAppendFiles, FILE** fplog) { int len, pid; char buf[256], host[256]; time_t t; char timebuf[STRLEN]; FILE *fp = *fplog; char *tmpnm; debug_gmx(); /* Communicate the filename for logfile */ if (cr->nnodes > 1 && !bMasterOnly #ifdef GMX_THREAD_MPI /* With thread MPI the non-master log files are opened later * when the files names are already known on all nodes. */ && FALSE #endif ) { if (MASTER(cr)) { len = strlen(lognm) + 1; } gmx_bcast(sizeof(len), &len, cr); if (!MASTER(cr)) { snew(tmpnm, len+8); } else { tmpnm = gmx_strdup(lognm); } gmx_bcast(len*sizeof(*tmpnm), tmpnm, cr); } else { tmpnm = gmx_strdup(lognm); } debug_gmx(); if (!bMasterOnly && !MASTER(cr)) { /* Since log always ends with '.log' let's use this info */ par_fn(tmpnm, efLOG, cr, FALSE, !bMasterOnly, buf, 255); fp = gmx_fio_fopen(buf, bAppendFiles ? "a+" : "w+" ); } else if (!bAppendFiles) { fp = gmx_fio_fopen(tmpnm, bAppendFiles ? "a+" : "w+" ); } sfree(tmpnm); gmx_fatal_set_log_file(fp); /* Get some machine parameters */ gmx_gethostname(host, 256); time(&t); #ifndef NO_GETPID # ifdef GMX_NATIVE_WINDOWS pid = _getpid(); # else pid = getpid(); # endif #else pid = 0; #endif if (bAppendFiles) { fprintf(fp, "\n" "\n" "-----------------------------------------------------------\n" "Restarting from checkpoint, appending to previous log file.\n" "\n" ); } gmx_ctime_r(&t, timebuf, STRLEN); fprintf(fp, "Log file opened on %s" "Host: %s pid: %d rank ID: %d number of ranks: %d\n", timebuf, host, pid, cr->nodeid, cr->nnodes); try { gmx::BinaryInformationSettings settings; settings.extendedInfo(true); settings.copyright(!bAppendFiles); gmx::printBinaryInformation(fp, gmx::getProgramContext(), settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; fprintf(fp, "\n\n"); fflush(fp); debug_gmx(); *fplog = fp; }
FILE *gmx_log_open(char *lognm,const t_commrec *cr,bool bMasterOnly, unsigned long Flags) { int len,testlen,pid; char buf[256],host[256]; time_t t; FILE *fp; bool bAppend = Flags & MD_APPENDFILES; debug_gmx(); /* Communicate the filename for logfile */ if (cr->nnodes > 1 && !bMasterOnly) { if (MASTER(cr)) len = strlen(lognm)+1; gmx_bcast(sizeof(len),&len,cr); if (!MASTER(cr)) snew(lognm,len+8); gmx_bcast(len*sizeof(*lognm),lognm,cr); } debug_gmx(); if (PAR(cr) && !bMasterOnly) { /* Since log always ends with '.log' let's use this info */ par_fn(lognm,efLOG,cr,cr->ms!=NULL,buf,255); fp = gmx_fio_fopen(buf, bAppend ? "a" : "w" ); } else { fp = gmx_fio_fopen(lognm, bAppend ? "a" : "w" ); } gmx_fatal_set_log_file(fp); /* Get some machine parameters */ #ifdef HAVE_UNISTD_H if( gethostname(host,255) != 0) sprintf(host,"unknown"); #else sprintf(host,"unknown"); #endif time(&t); #ifndef NO_GETPID # if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__) pid = _getpid(); # else pid = getpid(); # endif #else pid = 0; #endif if(bAppend) { fprintf(fp, "\n\n" "-----------------------------------------------------------\n" "Restarting from checkpoint, appending to previous log file.\n\n" ); } fprintf(fp, "Log file opened on %s" "Host: %s pid: %d nodeid: %d nnodes: %d\n", ctime(&t),host,pid,cr->nodeid,cr->nnodes); #if (defined BUILD_MACHINE && defined BUILD_TIME && defined BUILD_USER) fprintf(fp, "The Gromacs distribution was built %s by\n" "%s (%s)\n\n\n",BUILD_TIME,BUILD_USER,BUILD_MACHINE); #endif fflush(fp); debug_gmx(); return fp; }