Manually sort some includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / gmxlib / main.cpp
index c56df9da5747c1fa4f67f0bfd732d4b89781aeae..a91b41e2e4e54f0147e9397c53aaac320071aaa7 100644 (file)
@@ -1,82 +1,81 @@
-/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+/*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *
- *                This source code is part of
- *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
- *
- *                        VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * For more info, check our website at http://www.gromacs.org
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
- * And Hey:
- * GROningen Mixture of Alchemy and Childrens' Stories
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
+
+#include "gromacs/legacyheaders/main.h"
 
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <limits.h>
 #include <time.h>
 
+#include "config.h"
+
+#ifdef GMX_NATIVE_WINDOWS
+#include <process.h>
+#endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
-#include "smalloc.h"
-#include "gmx_fatal.h"
-#include "network.h"
-#include "main.h"
-#include "macros.h"
-#include "gromacs/fileio/futil.h"
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/gmxfio.h"
-#include "string2.h"
-#include "copyrite.h"
-
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/utility/basenetwork.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxmpi.h"
-#include "gromacs/utility/programinfo.h"
+#include "gromacs/utility/programcontext.h"
+#include "gromacs/utility/smalloc.h"
 
 /* The source code in this file should be thread-safe.
          Please keep it that way. */
 
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef GMX_NATIVE_WINDOWS
-#include <process.h>
-#endif
-
 #define BUFSIZE 1024
 
-
 static void par_fn(char *base, int ftp, const t_commrec *cr,
                    gmx_bool bAppendSimId, gmx_bool bAppendNodeId,
                    char buf[], int bufsize)
@@ -96,16 +95,16 @@ static void par_fn(char *base, int ftp, const t_commrec *cr,
     }
     if (bAppendNodeId)
     {
-        strcat(buf, "_node");
+        strcat(buf, "_rank");
         sprintf(buf+strlen(buf), "%d", cr->nodeid);
     }
     strcat(buf, ".");
 
     /* Add extension again */
-    strcat(buf, (ftp == efTPX) ? "tpr" : (ftp == efEDR) ? "edr" : ftp2ext(ftp));
+    strcat(buf, (ftp == efTPR) ? "tpr" : (ftp == efEDR) ? "edr" : ftp2ext(ftp));
     if (debug)
     {
-        fprintf(debug, "node %d par_fn '%s'\n", cr->nodeid, buf);
+        fprintf(debug, "rank %d par_fn '%s'\n", cr->nodeid, buf);
         if (fn2ftp(buf) == efLOG)
         {
             fprintf(debug, "log\n");
@@ -164,11 +163,11 @@ void check_multi_int(FILE *log, const gmx_multisim_t *ms, int val,
     sfree(ibuf);
 }
 
-void check_multi_large_int(FILE *log, const gmx_multisim_t *ms,
-                           gmx_large_int_t val, const char *name,
-                           gmx_bool bQuiet)
+void check_multi_int64(FILE *log, const gmx_multisim_t *ms,
+                       gmx_int64_t val, const char *name,
+                       gmx_bool bQuiet)
 {
-    gmx_large_int_t  *ibuf;
+    gmx_int64_t      *ibuf;
     int               p;
     gmx_bool          bCompatible;
 
@@ -210,7 +209,7 @@ void check_multi_large_int(FILE *log, const gmx_multisim_t *ms,
                 char strbuf[255];
                 /* first make the format string */
                 snprintf(strbuf, 255, "  subsystem %%d: %s\n",
-                         gmx_large_int_pfmt);
+                         "%" GMX_PRId64);
                 fprintf(log, strbuf, p, ibuf[p]);
             }
         }
@@ -221,81 +220,21 @@ void check_multi_large_int(FILE *log, const gmx_multisim_t *ms,
 }
 
 
-char *gmx_gethostname(char *name, size_t len)
-{
-    if (len < 8)
-    {
-        gmx_incons("gmx_gethostname called with len<8");
-    }
-#ifdef HAVE_UNISTD_H
-    if (gethostname(name, len-1) != 0)
-    {
-        strncpy(name, "unknown", 8);
-    }
-#else
-    strncpy(name, "unknown", 8);
-#endif
-
-    return name;
-}
-
-
-void gmx_log_open(const char *lognm, const t_commrec *cr, gmx_bool bMasterOnly,
+void gmx_log_open(const char *lognm, const t_commrec *cr,
                   gmx_bool bAppendFiles, FILE** fplog)
 {
-    int    len, pid;
-    char   buf[256], host[256];
+    int    pid;
+    char   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))
+    if (!bAppendFiles)
     {
-        /* 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+" );
+        fp = gmx_fio_fopen(lognm, bAppendFiles ? "a+" : "w+" );
     }
-    else if (!bAppendFiles)
-    {
-        fp = gmx_fio_fopen(tmpnm, bAppendFiles ? "a+" : "w+" );
-    }
-
-    sfree(tmpnm);
 
     gmx_fatal_set_log_file(fp);
 
@@ -329,14 +268,14 @@ void gmx_log_open(const char *lognm, const t_commrec *cr, gmx_bool bMasterOnly,
 
     fprintf(fp,
             "Log file opened on %s"
-            "Host: %s  pid: %d  nodeid: %d  nnodes:  %d\n",
+            "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::ProgramInfo::getInstance(), settings);
+        gmx::printBinaryInformation(fp, gmx::getProgramContext(), settings);
     }
     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
     fprintf(fp, "\n\n");
@@ -377,7 +316,7 @@ void init_multisystem(t_commrec *cr, int nsim, char **multidirs,
     nnodes  = cr->nnodes;
     if (nnodes % nsim != 0)
     {
-        gmx_fatal(FARGS, "The number of nodes (%d) is not a multiple of the number of simulations (%d)", nnodes, nsim);
+        gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%d)", nnodes, nsim);
     }
 
     nnodpersim = nnodes/nsim;
@@ -385,7 +324,7 @@ void init_multisystem(t_commrec *cr, int nsim, char **multidirs,
 
     if (debug)
     {
-        fprintf(debug, "We have %d simulations, %d nodes per simulation, local simulation is %d\n", nsim, nnodpersim, sim);
+        fprintf(debug, "We have %d simulations, %d ranks per simulation, local simulation is %d\n", nsim, nnodpersim, sim);
     }
 
     snew(ms, 1);
@@ -434,7 +373,7 @@ void init_multisystem(t_commrec *cr, int nsim, char **multidirs,
         fprintf(debug, "This is simulation %d", cr->ms->sim);
         if (PAR(cr))
         {
-            fprintf(debug, ", local number of nodes %d, local nodeid %d",
+            fprintf(debug, ", local number of ranks %d, local rank ID %d",
                     cr->nnodes, cr->sim_nodeid);
         }
         fprintf(debug, "\n\n");
@@ -457,7 +396,7 @@ void init_multisystem(t_commrec *cr, int nsim, char **multidirs,
              * at the actual file name
              */
             if (is_output(&fnm[i]) ||
-                fnm[i].ftp == efTPX || fnm[i].ftp == efCPT ||
+                fnm[i].ftp == efTPR || fnm[i].ftp == efCPT ||
                 strcmp(fnm[i].opt, "-rerun") == 0)
             {
                 ftp = fn2ftp(fnm[i].fns[0]);