diff --git a/src/input.cpp b/src/input.cpp index e573b08f25..d843243c90 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -17,6 +17,7 @@ #include "string.h" #include "input.h" #include "system.h" +#include "universe.h" #include "atom.h" #include "comm.h" #include "group.h" @@ -786,13 +787,17 @@ void Input::log() if (logfile) fclose(logfile); if (strcmp(arg[0],"none") == 0) logfile = NULL; else { - logfile = fopen(arg[0],"w"); + char fname[128]; + if (universe->nworlds == 1) strcpy(fname,arg[0]); + else sprintf(fname,"%s.%d",arg[0],universe->iworld); + logfile = fopen(fname,"w"); if (logfile == NULL) { char str[128]; - sprintf(str,"Cannot open logfile %s",arg[0]); + sprintf(str,"Cannot open logfile %s",fname); error->one(str); } } + if (universe->nworlds == 1) universe->ulogfile = logfile; } } diff --git a/src/system.cpp b/src/system.cpp index 1ee3afc87f..874a10ef00 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -174,7 +174,7 @@ void System::open(int narg, char **arg, MPI_Comm communicator) } else if (strcmp(arg[screenflag],"none") == 0) screen = NULL; else { - char str[32]; + char str[128]; sprintf(str,"%s.%d",arg[screenflag],universe->iworld); screen = fopen(str,"w"); if (screen == NULL) error->one("Cannot open screen file"); @@ -190,7 +190,7 @@ void System::open(int narg, char **arg, MPI_Comm communicator) } else if (strcmp(arg[logflag],"none") == 0) logfile = NULL; else { - char str[32]; + char str[128]; sprintf(str,"%s.%d",arg[logflag],universe->iworld); logfile = fopen(str,"w"); if (logfile == NULL) error->one("Cannot open logfile"); @@ -307,11 +307,13 @@ void System::destroy() void System::close() { - if (universe->nworlds > 1) { + if (universe->nworlds == 1) { + if (logfile) fclose(logfile); + } else { if (screen && screen != stdout) fclose(screen); if (logfile) fclose(logfile); + if (universe->ulogfile) fclose(universe->ulogfile); } - if (universe->ulogfile) fclose(universe->ulogfile); if (world != universe->uworld) MPI_Comm_free(&world);