Merge release-5-0 into master
authorRoland Schulz <roland@utk.edu>
Wed, 18 Jun 2014 14:06:23 +0000 (10:06 -0400)
committerRoland Schulz <roland@utk.edu>
Wed, 18 Jun 2014 14:25:37 +0000 (10:25 -0400)
Conflicts:
- src/gromacs/legacyheaders/types/simple.h
  moved changes into src/gromacs/utility/real.h
- src/gromacs/gmxlib/network.c &
  src/gromacs/utility/basenetwork.cpp
  changes to network.c partially applied to itself
  and paritally to basenetwork.
- src/gromacs/legacyheaders/network.h (trivial)
- src/programs/mdrun/md.cpp (trivial)

Change-Id: Iaeae5bcc691a3fa84978ee261ceb4a5d2aeb4f62

27 files changed:
1  2 
CMakeLists.txt
src/contrib/do_shift.c
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_eneconv.c
src/gromacs/gmxana/gmx_energy.c
src/gromacs/gmxana/gmx_genion.c
src/gromacs/gmxana/gmx_make_ndx.c
src/gromacs/gmxana/gmx_principal.c
src/gromacs/gmxana/gmx_sham.c
src/gromacs/gmxlib/gmx_thread_affinity.c
src/gromacs/gmxlib/network.c
src/gromacs/gmxlib/nrnb.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxlib/viewit.c
src/gromacs/gmxpreprocess/readir.c
src/gromacs/mdlib/forcerec.c
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_file_generator/nbnxn_kernel_simd_template.c.pre
src/gromacs/mdlib/nbnxn_kernels/simd_4xn/nbnxn_kernel_simd_4xn.c
src/gromacs/mdlib/qm_gaussian.c
src/gromacs/mdlib/qm_orca.c
src/gromacs/utility/basenetwork.cpp
src/gromacs/utility/fatalerror.cpp
src/gromacs/utility/futil.cpp
src/gromacs/utility/real.h
src/programs/mdrun/md.cpp
src/programs/view/logo.cpp
src/programs/view/x11.cpp

diff --combined CMakeLists.txt
index 4a07b24e2d29dc0396cb9ce1b1f7e95f991cc6a4,27e23ff1c41d6a23333de8ec461bb01e363450e8..a7fd59e5f18fd15885ce89817ce3abbdc301f432
@@@ -54,7 -54,7 +54,7 @@@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CM
  # NOTE: when releasing the "-dev" suffix needs to be stripped off!
  # REGRESSIONTEST_VERSION and REGRESSIONTEST_BRANCH should always be
  # defined.
 -set(PROJECT_VERSION "5.0-rc1-dev")
 +set(PROJECT_VERSION "5.1-dev")
  # If this is a released tarball, "-dev" will not be present in
  # PROJECT_VERSION, and REGRESSIONTEST_VERSION specifies the version
  # number of the regressiontest tarball against which the code tarball
@@@ -64,7 -64,7 +64,7 @@@ set(REGRESSIONTEST_VERSION "5.0-rc1"
  # PROJECT_VERSION, and REGRESSIONTEST_BRANCH specifies the name of the
  # gerrit.gromacs.org branch whose HEAD can test this code, *if* this
  # code contains all recent fixes from the corresponding code branch.
 -set(REGRESSIONTEST_BRANCH "refs/heads/release-5-0")
 +set(REGRESSIONTEST_BRANCH "refs/heads/master")
  
  set(CUSTOM_VERSION_STRING ""
      CACHE STRING "Custom version string (if empty, use hard-coded default)")
@@@ -76,7 -76,7 +76,7 @@@ set(LIBRARY_SOVERSION 0
  set(LIBRARY_VERSION ${LIBRARY_SOVERSION}.0.0)
  # It is a bit irritating, but this has to be set separately for now!
  SET(CPACK_PACKAGE_VERSION_MAJOR "5")
 -SET(CPACK_PACKAGE_VERSION_MINOR "0")
 +SET(CPACK_PACKAGE_VERSION_MINOR "1")
  #SET(CPACK_PACKAGE_VERSION_PATCH "0")
  
  # The numerical gromacs version. It is 40600 for 4.6.0.
@@@ -103,17 -103,15 +103,17 @@@ set(GMX_INSTALL_PREFIX "" CACHE STRING 
  mark_as_advanced(GMX_INSTALL_PREFIX)
  
  include(gmxBuildTypeReference)
 -include(gmxBuildTypeThreadSanitizer)
 +include(gmxBuildTypeProfile)
 +include(gmxBuildTypeTSAN)
 +include(gmxBuildTypeASAN)
  include(gmxBuildTypeReleaseWithAssert)
  
  if(NOT CMAKE_BUILD_TYPE)
 -    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert." FORCE)
 +    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert Profile." FORCE)
      # There's no need to offer a user the choice of ThreadSanitizer
      # Set the possible values of build type for cmake-gui
      set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
 -        "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert")
 +        "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert" "Profile")
  endif()
  if(CMAKE_CONFIGURATION_TYPES)
      # Add appropriate GROMACS-specific build types for the Visual
          "List of configuration types"
          FORCE)
  endif()
 -set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL)
 +set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL PROFILE)
  
  enable_language(C)
  enable_language(CXX)
@@@ -782,8 -780,11 +782,11 @@@ set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_
  ########################################################################
  # Specify install locations
  ########################################################################
- set(GMX_LIB_INSTALL_DIR lib CACHE STRING
-     "Library installation directory (default: lib)")
+ # Use GNUInstallDirst to set paths on multiarch systems
+ include(GNUInstallDirs)
+ set(GMX_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING
+     "Library installation directory (default: ${CMAKE_INSTALL_LIBDIR})")
  set(GMX_DATA_INSTALL_DIR gromacs CACHE STRING
      "Data installation directory under share/ (default: gromacs)")
  mark_as_advanced(GMX_LIB_INSTALL_DIR GMX_DATA_INSTALL_DIR)
diff --combined src/contrib/do_shift.c
index fd20a5ada9c29ecd67821986cc96676e6d8eb13f,5bea7c5fea22ac165ce693f6a8221f040f794897..60c21642e1763c5a91dc0b00ec118c7c97b95f8a
  
  #include <stdlib.h>
  #include "errno.h"
 -#include "sysstuff.h"
  #include "typedefs.h"
  #include "gromacs/utility/cstringutil.h"
  #include "macros.h"
  #include "gromacs/utility/smalloc.h"
 -#include "mshift.h"
  #include "gromacs/commandline/pargs.h"
  #include "copyrite.h"
  #include "gromacs/fileio/confio.h"
 -#include "gmx_fatal.h"
 -#include "xvgr.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/fileio/xvgr.h"
  #include "gstat.h"
 -#include "index.h"
 +#include "gromacs/topology/index.h"
  #include "gromacs/fileio/pdbio.h"
  
  void cat(FILE *out,char *fn,real t)
@@@ -80,8 -82,8 +80,8 @@@ int main(int argc,char *argv[]
      "calling the 'total' program. If you do not have the total program,",
      "get it. do_shift assumes that the total executable is in",
      "[TT]/home/mdgroup/total/total[tt]. If that is not the case, then you should",
-     "set an environment variable [BB]TOTAL[bb] as in: [PAR]",
-     "[TT]setenv TOTAL /usr/local/bin/total[tt][PAR]",
+     "set an environment variable [BB]GMX_TOTAL[bb] as in: [PAR]",
+     "[TT]setenv GMX_TOTAL /usr/local/bin/total[tt][PAR]",
      "where the right hand side should point to the total executable.[PAR]",
      "Output is printed in files [TT]shift.out[tt] where t is the time of the frame.[PAR]",
      "The program also needs an input file called [BB]random.dat[bb] which",
    gmx_tmpnam(tmpfile);
    fprintf(stderr,"pdbfile = %s\ntmpfile = %s\n",pdbfile,tmpfile);
    
-   if ((dptr=getenv("TOTAL")) == NULL)
+   if ((dptr=getenv("GMX_TOTAL")) == NULL)
      dptr="/home/mdgroup/total/total";
    sprintf(total,"%s > /dev/null",dptr);
    fprintf(stderr,"total cmd='%s'\n",total);
index 2a0ef2cc0757672aac3238b1dff9dd453ca536d9,d2ff55801d0e586006721e0ebfdaca1033f3afb5..ba31730f9113ed966b18003a2d268b421186f876
  #include <algorithm>
  
  #include "macros.h"
 -#include "gromacs/commandline/pargs.h"
 -#include "sysstuff.h"
 -#include "gromacs/utility/smalloc.h"
 -#include "vec.h"
 -#include "pbc.h"
 +#include "gromacs/pbcutil/pbc.h"
  #include "bondf.h"
 -#include "gromacs/fileio/futil.h"
 -#include "xvgr.h"
 +#include "gromacs/utility/futil.h"
 +#include "viewit.h"
  #include "txtdump.h"
  #include "gromacs/statistics/statistics.h"
  #include "gstat.h"
 -#include "index.h"
 +#include "gromacs/topology/index.h"
  #include "gromacs/random/random.h"
  #include "names.h"
 -#include "physics.h"
 +#include "gromacs/math/units.h"
  #include "calcmu.h"
  #include "gromacs/fileio/enxio.h"
 -#include "gromacs/fileio/matio.h"
  #include "gmx_ana.h"
  #include "copyrite.h"
  #include "gromacs/fileio/trxio.h"
  
 +#include "gromacs/commandline/pargs.h"
 +#include "gromacs/fileio/matio.h"
 +#include "gromacs/fileio/xvgr.h"
  #include "gromacs/linearalgebra/nrjac.h"
 +#include "gromacs/math/vec.h"
 +#include "gromacs/pbcutil/rmpbc.h"
  #include "gromacs/utility/exceptions.h"
 -#include "gromacs/legacyheaders/gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  #include "gromacs/utility/programcontext.h"
 +#include "gromacs/utility/smalloc.h"
  
  #define e2d(x) ENM2DEBYE*(x)
  #define EANG2CM  E_CHARGE*1.0e-10       /* e Angstrom to Coulomb meter */
@@@ -93,7 -92,7 +93,7 @@@ static t_gkrbin *mk_gkrbin(real radius
  
      snew(gb, 1);
  
-     if ((ptr = getenv("GKRWIDTH")) != NULL)
+     if ((ptr = getenv("GMX_DIPOLE_SPACING")) != NULL)
      {
          double bw = strtod(ptr, NULL);
          gb->spacing = bw;
index 3e87f0dbd4ad54e1de85339fdee034dba69e2fcb,a521f90facd3c3133256b0e862b7587bbb7dc0fd..b4a542197b26e3239d84cd2ce93259232c2fb5f6
  #ifdef HAVE_CONFIG_H
  #include <config.h>
  #endif
 -#include <string.h>
 +
  #include <math.h>
 +#include <stdlib.h>
 +#include <string.h>
  
  #include "typedefs.h"
  #include "gromacs/utility/smalloc.h"
@@@ -48,9 -46,9 +48,9 @@@
  #include "disre.h"
  #include "names.h"
  #include "macros.h"
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  #include "gromacs/fileio/enxio.h"
 -#include "vec.h"
 +#include "gromacs/math/vec.h"
  #include "gmx_ana.h"
  #include "gromacs/fileio/trxio.h"
  
@@@ -68,7 -66,7 +68,7 @@@ static int *select_it(int nre, gmx_enxn
      int      *set;
      gmx_bool  bVerbose = TRUE;
  
-     if ((getenv("VERBOSE")) != NULL)
+     if ((getenv("GMX_ENER_VERBOSE")) != NULL)
      {
          bVerbose = FALSE;
      }
@@@ -583,6 -581,7 +583,6 @@@ int gmx_eneconv(int argc, char *argv[]
      nset     = 0;
      timestep = 0.0;
      snew(fnms, argc);
 -    nfile        = 0;
      lastfilestep = 0;
      laststep     = startstep = 0;
  
index a0ddbfb1604f94754fa26a136a04df21a0f43fa2,884c45d7f5331866006890c2b07577fc97d5d9d4..4ffec6be5d7f73780a1508b15fdd1e463cc4c3c3
  #endif
  
  #include <math.h>
 +#include <stdlib.h>
  #include <string.h>
  
  #include "typedefs.h"
 -#include "gmx_fatal.h"
 -#include "vec.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/math/vec.h"
  #include "gromacs/utility/cstringutil.h"
  #include "gromacs/utility/smalloc.h"
  #include "gromacs/fileio/enxio.h"
  #include "names.h"
  #include "copyrite.h"
  #include "macros.h"
 -#include "xvgr.h"
 +#include "gromacs/fileio/xvgr.h"
  #include "gstat.h"
 -#include "physics.h"
 +#include "gromacs/math/units.h"
  #include "gromacs/fileio/tpxio.h"
  #include "gromacs/fileio/trxio.h"
  #include "viewit.h"
 -#include "mtop_util.h"
 +#include "gromacs/topology/mtop_util.h"
  #include "gmx_ana.h"
  #include "mdebin.h"
  
@@@ -108,7 -107,7 +108,7 @@@ static int *select_it(int nre, char *nm
      int      *set;
      gmx_bool  bVerbose = TRUE;
  
-     if ((getenv("VERBOSE")) != NULL)
+     if ((getenv("GMX_ENER_VERBOSE")) != NULL)
      {
          bVerbose = FALSE;
      }
@@@ -178,7 -177,7 +178,7 @@@ static int *select_by_name(int nre, gmx
      const char *fm2   = "%3d  %-34s";
      char      **newnm = NULL;
  
-     if ((getenv("VERBOSE")) != NULL)
+     if ((getenv("GMX_ENER_VERBOSE")) != NULL)
      {
          bVerbose = FALSE;
      }
index 7699f36f8dc407765fe905de618920452d8771a3,6abf410904ad2a55ba02072435b4cea8e27c86a6..9456e4825a73acd90ad5391fcf439083fce43eb7
  #endif
  
  #include <ctype.h>
 +#include <stdlib.h>
  #include <string.h>
  
  #include "gromacs/utility/cstringutil.h"
  #include "gromacs/utility/smalloc.h"
 -#include "sysstuff.h"
  #include "gromacs/fileio/confio.h"
  #include "gromacs/commandline/pargs.h"
 -#include "pbc.h"
 +#include "gromacs/pbcutil/pbc.h"
  #include "force.h"
 -#include "gmx_fatal.h"
 -#include "gromacs/fileio/futil.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/futil.h"
  #include "gromacs/math/utilities.h"
  #include "macros.h"
 -#include "vec.h"
 +#include "gromacs/math/vec.h"
  #include "gromacs/fileio/tpxio.h"
  #include "mdrun.h"
 -#include "main.h"
  #include "gromacs/random/random.h"
 -#include "index.h"
 -#include "mtop_util.h"
 +#include "gromacs/topology/index.h"
  #include "gmx_ana.h"
  
  static void insert_ion(int nsa, int *nwater,
@@@ -472,8 -474,7 +472,7 @@@ int gmx_genion(int argc, char *argv[]
  
      if ((p_num == 0) && (n_num == 0))
      {
-         fprintf(stderr, "No ions to add.\n");
-         exit(0);
+         fprintf(stderr, "No ions to add, will just copy input configuration.\n");
      }
      else
      {
          {
              gmx_fatal(FARGS, "Not enough solvent for adding ions");
          }
-     }
  
-     if (opt2bSet("-p", NFILE, fnm))
-     {
-         update_topol(opt2fn("-p", NFILE, fnm), p_num, n_num, p_name, n_name, grpname);
-     }
+         if (opt2bSet("-p", NFILE, fnm))
+         {
+             update_topol(opt2fn("-p", NFILE, fnm), p_num, n_num, p_name, n_name, grpname);
+         }
  
-     snew(bSet, nw);
-     snew(repl, nw);
+         snew(bSet, nw);
+         snew(repl, nw);
  
-     snew(v, atoms.nr);
-     snew(atoms.pdbinfo, atoms.nr);
+         snew(v, atoms.nr);
+         snew(atoms.pdbinfo, atoms.nr);
  
-     set_pbc(&pbc, ePBC, box);
+         set_pbc(&pbc, ePBC, box);
  
-     if (seed == 0)
-     {
-         rng = gmx_rng_init(gmx_rng_make_seed());
-     }
-     else
-     {
-         rng = gmx_rng_init(seed);
-     }
-     /* Now loop over the ions that have to be placed */
-     while (p_num-- > 0)
-     {
-         insert_ion(nsa, &nw, bSet, repl, index, x, &pbc,
-                    1, p_q, p_name, &atoms, rmin, rng);
-     }
-     while (n_num-- > 0)
-     {
-         insert_ion(nsa, &nw, bSet, repl, index, x, &pbc,
-                    -1, n_q, n_name, &atoms, rmin, rng);
-     }
-     gmx_rng_destroy(rng);
-     fprintf(stderr, "\n");
+         if (seed == 0)
+         {
+             rng = gmx_rng_init(gmx_rng_make_seed());
+         }
+         else
+         {
+             rng = gmx_rng_init(seed);
+         }
+         /* Now loop over the ions that have to be placed */
+         while (p_num-- > 0)
+         {
+             insert_ion(nsa, &nw, bSet, repl, index, x, &pbc,
+                        1, p_q, p_name, &atoms, rmin, rng);
+         }
+         while (n_num-- > 0)
+         {
+             insert_ion(nsa, &nw, bSet, repl, index, x, &pbc,
+                        -1, n_q, n_name, &atoms, rmin, rng);
+         }
+         gmx_rng_destroy(rng);
+         fprintf(stderr, "\n");
  
-     if (nw)
-     {
-         sort_ions(nsa, nw, repl, index, &atoms, x, p_name, n_name);
-     }
+         if (nw)
+         {
+             sort_ions(nsa, nw, repl, index, &atoms, x, p_name, n_name);
+         }
  
-     sfree(atoms.pdbinfo);
-     atoms.pdbinfo = NULL;
-     write_sto_conf(ftp2fn(efSTO, NFILE, fnm), *top.name, &atoms, x, NULL, ePBC,
-                    box);
+         sfree(atoms.pdbinfo);
+         atoms.pdbinfo = NULL;
+     }
+     write_sto_conf(ftp2fn(efSTO, NFILE, fnm), *top.name, &atoms, x, NULL, ePBC, box);
  
      return 0;
  }
index 3e48c99a264628710de5ffb8ea09286ef045fbaa,686ee49aaa59611fee725941e93d7eeb7159aac9..7bdccbefff8c4cf25f7fbfa4eecc912779abbf97
  #include <ctype.h>
  #include <string.h>
  
 -#include "sysstuff.h"
 -#include "gromacs/fileio/futil.h"
 +#include "gromacs/utility/futil.h"
  #include "macros.h"
 -#include "gromacs/utility/cstringutil.h"
 -#include "gromacs/commandline/pargs.h"
  #include "gromacs/fileio/confio.h"
  #include "typedefs.h"
 -#include "index.h"
 -#include "gromacs/utility/smalloc.h"
 -#include "vec.h"
 -#include "index.h"
 +#include "gromacs/topology/index.h"
 +#include "gromacs/math/vec.h"
  
 -#include "gromacs/legacyheaders/gmx_fatal.h"
 +#include "gromacs/commandline/pargs.h"
 +#include "gromacs/topology/block.h"
 +#include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/smalloc.h"
  
- #define MAXNAMES 30
- #define NAME_LEN 30
+ /* It's not nice to have size limits, but we should not spend more time
+  * on this ancient tool, but instead use the new selection library.
+  */
+ #define MAXNAMES 1024
+ #define NAME_LEN 1024
  
  gmx_bool bCase = FALSE;
  
@@@ -846,12 -850,8 +849,12 @@@ static int split_chain(t_atoms *atoms, 
                  {
                      rvec_sub(x[ca_end], x[i], vec);
                  }
 +                else
 +                {
 +                    break;
 +                }
              }
 -            while ((i < natoms) && (norm(vec) < 0.45));
 +            while (norm(vec) < 0.45);
  
              end[nchain] = ca_end;
              while ((end[nchain]+1 < natoms) &&
index 72db5d6ba57262164977fc3bb4e252b85f49aa07,9b82d19eb0a493366ac8c71d9858199be21dfbc9..8e9a2d46299b51c0cb7271d092e2121fc17422ec
  #include <string.h>
  
  #include "gromacs/commandline/pargs.h"
 -#include "sysstuff.h"
  #include "typedefs.h"
  #include "gromacs/utility/smalloc.h"
  #include "macros.h"
 -#include "vec.h"
 -#include "pbc.h"
 -#include "gromacs/fileio/futil.h"
 -#include "index.h"
 -#include "mshift.h"
 -#include "xvgr.h"
 +#include "gromacs/math/vec.h"
 +#include "gromacs/utility/futil.h"
 +#include "gromacs/topology/index.h"
  #include "princ.h"
 -#include "rmpbc.h"
 +#include "gromacs/pbcutil/rmpbc.h"
  #include "txtdump.h"
  #include "gromacs/fileio/tpxio.h"
  #include "gromacs/fileio/trxio.h"
@@@ -75,7 -79,11 +75,11 @@@ int gmx_principal(int argc, char *argv[
  {
      const char     *desc[] = {
          "[THISMODULE] calculates the three principal axes of inertia for a group",
-         "of atoms.",
+         "of atoms. NOTE: Old versions of Gromacs wrote the output data in a",
+         "strange transposed way. As of Gromacs-5.0, the output file paxis1.dat",
+         "contains the x/y/z components of the first (major) principal axis for",
+         "each frame, and similarly for the middle and minor axes in paxis2.dat",
+         "and paxis3.dat."
      };
      static gmx_bool foo = FALSE;
  
          { efTRX, "-f",   NULL,       ffREAD },
          { efTPS, NULL,   NULL,       ffREAD },
          { efNDX, NULL,   NULL,       ffOPTRD },
-         { efDAT, "-a1",  "axis1",    ffWRITE },
-         { efDAT, "-a2",  "axis2",    ffWRITE },
-         { efDAT, "-a3",  "axis3",    ffWRITE },
+         { efDAT, "-a1",  "paxis1",   ffWRITE },
+         { efDAT, "-a2",  "paxis2",   ffWRITE },
+         { efDAT, "-a3",  "paxis3",   ffWRITE },
          { efDAT, "-om",  "moi",      ffWRITE }
      };
  #define NFILE asize(fnm)
  
          calc_principal_axes(&top, x, index, gnx, axes, moi);
  
-         fprintf(axis1, "%15.10f     %15.10f  %15.10f  %15.10f\n", t, axes[XX][XX], axes[YY][XX], axes[ZZ][XX]);
-         fprintf(axis2, "%15.10f     %15.10f  %15.10f  %15.10f\n", t, axes[XX][YY], axes[YY][YY], axes[ZZ][YY]);
-         fprintf(axis3, "%15.10f     %15.10f  %15.10f  %15.10f\n", t, axes[XX][ZZ], axes[YY][ZZ], axes[ZZ][ZZ]);
+         fprintf(axis1, "%15.10f     %15.10f  %15.10f  %15.10f\n", t, axes[XX][XX], axes[XX][YY], axes[XX][ZZ]);
+         fprintf(axis2, "%15.10f     %15.10f  %15.10f  %15.10f\n", t, axes[YY][XX], axes[YY][YY], axes[YY][ZZ]);
+         fprintf(axis3, "%15.10f     %15.10f  %15.10f  %15.10f\n", t, axes[ZZ][XX], axes[ZZ][YY], axes[ZZ][ZZ]);
          fprintf(fmoi,  "%15.10f     %15.10f  %15.10f  %15.10f\n", t, moi[XX], moi[YY], moi[ZZ]);
      }
      while (read_next_x(oenv, status, &t, x, box));
index c0193996177ecd719a22ba06fedce0b7cd0bdfc7,911fdbff0f4af502a695b6d4e9e5576bb8eb6a29..8e367e082e6e38501e4dcf715a67cfa12fcde7e8
  #ifdef HAVE_CONFIG_H
  #include <config.h>
  #endif
 +
  #include <math.h>
 +#include <stdlib.h>
  #include <string.h>
 +
  #include "gromacs/commandline/pargs.h"
 -#include "sysstuff.h"
  #include "typedefs.h"
  #include "gromacs/utility/smalloc.h"
  #include "macros.h"
 -#include "gmx_fatal.h"
 -#include "vec.h"
 -#include "gromacs/fileio/futil.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/math/vec.h"
 +#include "gromacs/utility/futil.h"
  #include "readinp.h"
  #include "txtdump.h"
  #include "gstat.h"
 -#include "xvgr.h"
 -#include "physics.h"
 +#include "gromacs/fileio/xvgr.h"
 +#include "gromacs/math/units.h"
  #include "gromacs/fileio/pdbio.h"
  #include "gromacs/fileio/matio.h"
  #include "gmx_ana.h"
@@@ -413,25 -411,24 +413,24 @@@ static void pick_minima(const char *log
  
  static void do_sham(const char *fn, const char *ndx,
                      const char *xpmP, const char *xpm, const char *xpm2,
-                     const char *xpm3, const char *xpm4, const char *pdb,
+                     const char *xpm3, const char *pdb,
                      const char *logf,
                      int n, int neig, real **eig,
                      gmx_bool bGE, int nenerT, real **enerT,
-                     int nmap, real *mapindex, real **map,
                      real Tref,
                      real pmax, real gmax,
                      real *emin, real *emax, int nlevels, real pmin,
-                     const char *mname, int *idim, int *ibox,
+                     int *idim, int *ibox,
                      gmx_bool bXmin, real *xmin, gmx_bool bXmax, real *xmax)
  {
      FILE        *fp;
      real        *min_eig, *max_eig;
      real        *axis_x, *axis_y, *axis_z, *axis = NULL;
      double      *P;
-     real       **PP, *W, *E, **WW, **EE, *S, **SS, *M, **MM, *bE;
+     real       **PP, *W, *E, **WW, **EE, *S, **SS, *M, *bE;
      rvec         xxx;
      char        *buf;
-     double      *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf, Mmin, Mmax, Minf;
+     double      *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf, Mmin, Mmax;
      real        *delta;
      int          i, j, k, imin, len, index, d, *nbin, *bindex, bi;
      int         *nxyz, maxbox;
              axis[j] = min_eig[i] + j/bfac[i];
          }
      }
-     if (map)
-     {
-         snew(M, len);
-         snew(MM, maxbox*maxbox);
-         for (i = 0; (i < ibox[0]); i++)
-         {
-             MM[i] = &(M[i*ibox[1]]);
-         }
-         Mmin = 1e8;
-         Mmax = -1e8;
-         for (i = 0; (i < nmap); i++)
-         {
-             Mmin = min(Mmin, map[0][i]);
-             Mmax = max(Mmax, map[0][i]);
-         }
-         Minf = Mmax*1.05;
-         for (i = 0; (i < len); i++)
-         {
-             M[i] = Minf;
-         }
-         for (i = 0; (i < nmap); i++)
-         {
-             index = gmx_nint(mapindex[i]);
-             if (index >= len)
-             {
-                 gmx_fatal(FARGS, "Number of bins in file from -mdata option does not correspond to current analysis");
-             }
  
-             if (P[index] != 0)
-             {
-                 M[index] = map[0][i];
-             }
-         }
-     }
-     else
-     {
-         MM   = NULL;
-         Minf = NOTSET;
-     }
      pick_minima(logf, ibox, neig, len, W);
      if (gmax <= 0)
      {
          write_xpm(fp, flags, "Entropy Landscape", "TDS (kJ/mol)", "PC1", "PC2",
                    ibox[0], ibox[1], axis_x, axis_y, SS, 0, Sinf, rlo, rhi, &nlevels);
          gmx_ffclose(fp);
-         if (map)
-         {
-             fp = gmx_ffopen(xpm4, "w");
-             write_xpm(fp, flags, "Custom Landscape", mname, "PC1", "PC2",
-                       ibox[0], ibox[1], axis_x, axis_y, MM, 0, Minf, rlo, rhi, &nlevels);
-             gmx_ffclose(fp);
-         }
      }
      else if (neig == 3)
      {
          }
          gmx_ffclose(fp);
          write_xplor("out.xplor", W, ibox, min_eig, max_eig);
-         if (map)
-         {
-             write_xplor("user.xplor", M, ibox, min_eig, max_eig);
-         }
          nxyz[XX] = imin/(ibox[1]*ibox[2]);
          nxyz[YY] = (imin-nxyz[XX]*ibox[1]*ibox[2])/ibox[2];
          nxyz[ZZ] = imin % ibox[2];
          gmx_ffclose(fp);
          sfree(buf);
      }
-     if (map)
-     {
-         sfree(MM);
-         sfree(M);
-     }
  }
  
  static void ehisto(const char *fh, int n, real **enerT, const output_env_t oenv)
@@@ -977,7 -920,6 +922,6 @@@ int gmx_sham(int argc, char *argv[]
      static rvec        nrbox     = {32, 32, 32};
      static rvec        xmin      = {0, 0, 0}, xmax = {1, 1, 1};
      static int         nsets_in  = 1, nb_min = 4, resol = 10, nlevels = 25;
-     static const char *mname     = "";
      t_pargs            pa[]      = {
          { "-time",    FALSE, etBOOL, {&bHaveT},
            "Expect a time in the input" },
            "Maximum enthalpy in output, default is calculate" },
          { "-nlevels", FALSE, etINT,  {&nlevels},
            "Number of levels for energy landscape" },
-         { "-mname",   FALSE, etSTR,  {&mname},
-           "Legend label for the custom landscape" },
      };
  #define NPA asize(pa)
  
      FILE           *out;
-     int             n, e_n, d_n, nlast, s, nset, e_nset, d_nset, i, j = 0, *idim, *ibox;
-     real          **val, **et_val, **dt_val, *t, *e_t, e_dt, d_dt, *d_t, dt, tot, error;
+     int             n, e_n, nlast, s, nset, e_nset, d_nset, i, j = 0, *idim, *ibox;
+     real          **val, **et_val, *t, *e_t, e_dt, d_dt, dt, tot, error;
      real           *rmin, *rmax;
      double         *av, *sig, cum1, cum2, cum3, cum4, db;
      const char     *fn_ge, *fn_ene;
          { efXPM, "-ls",   "gibbs",    ffOPTWR  },
          { efXPM, "-lsh",  "enthalpy", ffOPTWR  },
          { efXPM, "-lss",  "entropy",  ffOPTWR  },
-         { efXPM, "-map",  "map",      ffOPTWR  },
          { efPDB, "-ls3",  "gibbs3",   ffOPTWR  },
-         { efXVG, "-mdata", "mapdata",  ffOPTRD  },
          { efLOG, "-g",    "shamlog",  ffOPTWR  }
      };
  #define NFILE asize(fnm)
          et_val = NULL;
      }
  
-     if (opt2fn_null("-mdata", NFILE, fnm) != NULL)
-     {
-         dt_val = read_xvg_time(opt2fn("-mdata", NFILE, fnm), bHaveT,
-                                FALSE, tb, FALSE, te,
-                                nsets_in, &d_nset, &d_n, &d_dt, &d_t);
-         if (d_nset != 1)
-         {
-             gmx_fatal(FARGS, "Can only handle one mapping data column in %s",
-                       opt2fn("-mdata", NFILE, fnm));
-         }
-     }
-     else
-     {
-         dt_val = NULL;
-     }
      if (fn_ene && et_val)
      {
          ehisto(opt2fn("-histo", NFILE, fnm), e_n, et_val, oenv);
      do_sham(opt2fn("-dist", NFILE, fnm), opt2fn("-bin", NFILE, fnm),
              opt2fn("-lp", NFILE, fnm),
              opt2fn("-ls", NFILE, fnm), opt2fn("-lsh", NFILE, fnm),
-             opt2fn("-lss", NFILE, fnm), opt2fn("-map", NFILE, fnm),
+             opt2fn("-lss", NFILE, fnm),
              opt2fn("-ls3", NFILE, fnm), opt2fn("-g", NFILE, fnm),
-             n, nset, val, fn_ge != NULL, e_nset, et_val, d_n, d_t, dt_val, Tref,
+             n, nset, val, fn_ge != NULL, e_nset, et_val, Tref,
              pmax, gmax,
              opt2parg_bSet("-emin", NPA, pa) ? &emin : NULL,
              opt2parg_bSet("-emax", NPA, pa) ? &emax : NULL,
              nlevels, pmin,
-             mname, idim, ibox,
+             idim, ibox,
              opt2parg_bSet("-xmin", NPA, pa), rmin,
              opt2parg_bSet("-xmax", NPA, pa), rmax);
  
index 02363e230502374b1088b3dca026a22c8fe0a731,03bf0db93f384d55a11d29e7bdfc8648b3618356..8814ec410f72b9c3bb89b871ba7bb76d995063a5
  #include "md_logging.h"
  #include "gmx_thread_affinity.h"
  
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/basenetwork.h"
 +#include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/fatalerror.h"
  #include "gromacs/utility/gmxomp.h"
 +#include "gromacs/utility/smalloc.h"
  
  static int
  get_thread_affinity_layout(FILE *fplog,
@@@ -239,7 -236,8 +239,8 @@@ gmx_set_thread_affinity(FIL
           */
          MPI_Comm comm_intra;
  
-         MPI_Comm_split(MPI_COMM_WORLD, gmx_hostname_num(), cr->rank_intranode,
+         MPI_Comm_split(MPI_COMM_WORLD,
+                        gmx_physicalnode_id_hash(), cr->rank_intranode,
                         &comm_intra);
          MPI_Scan(&nthread_local, &thread0_id_node, 1, MPI_INT, MPI_SUM, comm_intra);
          /* MPI_Scan is inclusive, but here we need exclusive */
   * Note that this will only work on Linux as we use a GNU feature.
   */
  void
 -gmx_check_thread_affinity_set(FILE            gmx_unused *fplog,
 -                              const t_commrec gmx_unused *cr,
 -                              gmx_hw_opt_t    gmx_unused *hw_opt,
 -                              int             gmx_unused  ncpus,
 -                              gmx_bool        gmx_unused  bAfterOpenmpInit)
 +gmx_check_thread_affinity_set(FILE            *fplog,
 +                              const t_commrec *cr,
 +                              gmx_hw_opt_t    *hw_opt,
 +                              int  gmx_unused  ncpus,
 +                              gmx_bool         bAfterOpenmpInit)
  {
  #ifdef HAVE_SCHED_GETAFFINITY
      cpu_set_t mask_current;
      int       i, ret, cpu_count, cpu_set;
      gmx_bool  bAllSet;
 +#endif
  
      assert(hw_opt);
 +    if (!bAfterOpenmpInit)
 +    {
 +        /* Check for externally set OpenMP affinity and turn off internal
 +         * pinning if any is found. We need to do this check early to tell
 +         * thread-MPI whether it should do pinning when spawning threads.
 +         * TODO: the above no longer holds, we should move these checks later
 +         */
 +        if (hw_opt->thread_affinity != threadaffOFF)
 +        {
 +            char *message;
 +            if (!gmx_omp_check_thread_affinity(&message))
 +            {
 +                /* TODO: with -pin auto we should only warn when using all cores */
 +                md_print_warn(cr, fplog, "%s", message);
 +                sfree(message);
 +                hw_opt->thread_affinity = threadaffOFF;
 +            }
 +        }
 +
 +        /* With thread-MPI this is needed as pinning might get turned off,
 +         * which needs to be known before starting thread-MPI.
 +         * With thread-MPI hw_opt is processed here on the master rank
 +         * and passed to the other ranks later, so we only do this on master.
 +         */
 +        if (!SIMMASTER(cr))
 +        {
 +            return;
 +        }
 +#ifndef GMX_THREAD_MPI
 +        return;
 +#endif
 +    }
 +
 +#ifdef HAVE_SCHED_GETAFFINITY
      if (hw_opt->thread_affinity == threadaffOFF)
      {
          /* internal affinity setting is off, don't bother checking process affinity */
index b683c97ec459bc03d33cdffdf5d6636c476a1e97,a5b7828a1d576f37b292f25fc98409286737c474..3cbcf33c4eb3cd210a99de5239b3887b944cd4f1
   * To help us fund GROMACS development, we humbly ask that you cite
   * the research papers on the package. Check out http://www.gromacs.org.
   */
 +#include "network.h"
 +
  #ifdef HAVE_CONFIG_H
  #include <config.h>
  #endif
  
 +#include <ctype.h>
 +#include <stdarg.h>
 +#include <stdlib.h>
  #include <string.h>
 -#include "gmx_fatal.h"
 -#include "main.h"
 -#include "gromacs/utility/smalloc.h"
 +
  #include "types/commrec.h"
 -#include "network.h"
  #include "copyrite.h"
 -#include <ctype.h>
  #include "macros.h"
 -#include "gromacs/utility/cstringutil.h"
  
 +#include "gromacs/utility/basenetwork.h"
 +#include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/futil.h"
  #include "gromacs/utility/gmxmpi.h"
 -
 +#include "gromacs/utility/smalloc.h"
  
  /* The source code in this file should be thread-safe.
        Please keep it that way. */
  
 -gmx_bool gmx_mpi_initialized(void)
 -{
 -    int n;
 -#ifndef GMX_MPI
 -    return 0;
 -#else
 -    MPI_Initialized(&n);
 -
 -    return n;
 -#endif
 -}
 -
  void gmx_fill_commrec_from_mpi(t_commrec gmx_unused *cr)
  {
  #ifndef GMX_MPI
@@@ -136,10 -144,148 +136,10 @@@ t_commrec *reinitialize_commrec_for_thi
  #endif
  }
  
 -int  gmx_node_num(void)
 -{
 -#ifndef GMX_MPI
 -    return 1;
 -#else
 -    int i;
 -    (void) MPI_Comm_size(MPI_COMM_WORLD, &i);
 -    return i;
 -#endif
 -}
 -
 -int gmx_node_rank(void)
 -{
 -#ifndef GMX_MPI
 -    return 0;
 -#else
 -    int i;
 -    (void) MPI_Comm_rank(MPI_COMM_WORLD, &i);
 -    return i;
 -#endif
 -}
 -
 -static int mpi_hostname_hash(void)
 -{
 -    int hash_int;
 -
 -#ifndef GMX_LIB_MPI
 -    /* We have a single physical node */
 -    hash_int = 0;
 -#else
 -    int  resultlen;
 -    char mpi_hostname[MPI_MAX_PROCESSOR_NAME];
 -
 -    /* This procedure can only differentiate nodes with different names.
 -     * Architectures where different physical nodes have identical names,
 -     * such as IBM Blue Gene, should use an architecture specific solution.
 -     */
 -    MPI_Get_processor_name(mpi_hostname, &resultlen);
 -
 -    /* The string hash function returns an unsigned int. We cast to an int.
 -     * Negative numbers are converted to positive by setting the sign bit to 0.
 -     * This makes the hash one bit smaller.
 -     * A 63-bit hash (with 64-bit int) should be enough for unique node hashes,
 -     * even on a million node machine. 31 bits might not be enough though!
 -     */
 -    hash_int =
 -        (int)gmx_string_fullhash_func(mpi_hostname, gmx_string_hash_init);
 -    if (hash_int < 0)
 -    {
 -        hash_int -= INT_MIN;
 -    }
 -#endif
 -
 -    return hash_int;
 -}
 -
 -#if defined GMX_LIB_MPI && defined GMX_TARGET_BGQ
 -#include <spi/include/kernel/location.h>
 -
 -static int bgq_nodenum(void)
 -{
 -    int           hostnum;
 -    Personality_t personality;
 -    Kernel_GetPersonality(&personality, sizeof(personality));
 -    /* Each MPI rank has a unique coordinate in a 6-dimensional space
 -       (A,B,C,D,E,T), with dimensions A-E corresponding to different
 -       physical nodes, and T within each node. Each node has sixteen
 -       physical cores, each of which can have up to four hardware
 -       threads, so 0 <= T <= 63 (but the maximum value of T depends on
 -       the confituration of ranks and OpenMP threads per
 -       node). However, T is irrelevant for computing a suitable return
 -       value for gmx_hostname_num().
 -     */
 -    hostnum  = personality.Network_Config.Acoord;
 -    hostnum *= personality.Network_Config.Bnodes;
 -    hostnum += personality.Network_Config.Bcoord;
 -    hostnum *= personality.Network_Config.Cnodes;
 -    hostnum += personality.Network_Config.Ccoord;
 -    hostnum *= personality.Network_Config.Dnodes;
 -    hostnum += personality.Network_Config.Dcoord;
 -    hostnum *= personality.Network_Config.Enodes;
 -    hostnum += personality.Network_Config.Ecoord;
 -
 -    if (debug)
 -    {
 -        fprintf(debug,
 -                "Torus ID A: %d / %d B: %d / %d C: %d / %d D: %d / %d E: %d / %d\nNode ID T: %d / %d core: %d / %d hardware thread: %d / %d\n",
 -                personality.Network_Config.Acoord,
 -                personality.Network_Config.Anodes,
 -                personality.Network_Config.Bcoord,
 -                personality.Network_Config.Bnodes,
 -                personality.Network_Config.Ccoord,
 -                personality.Network_Config.Cnodes,
 -                personality.Network_Config.Dcoord,
 -                personality.Network_Config.Dnodes,
 -                personality.Network_Config.Ecoord,
 -                personality.Network_Config.Enodes,
 -                Kernel_ProcessorCoreID(),
 -                16,
 -                Kernel_ProcessorID(),
 -                64,
 -                Kernel_ProcessorThreadID(),
 -                4);
 -    }
 -    return hostnum;
 -}
 -#endif
 -
 -int gmx_physicalnode_id_hash(void)
 -{
 -    int hash;
 -
 -#ifndef GMX_MPI
 -    hash = 0;
 -#else
 -#ifdef GMX_THREAD_MPI
 -    /* thread-MPI currently puts the thread number in the process name,
 -     * we might want to change this, as this is inconsistent with what
 -     * most MPI implementations would do when running on a single node.
 -     */
 -    hash = 0;
 -#else
 -#ifdef GMX_TARGET_BGQ
 -    hash = bgq_nodenum();
 -#else
 -    hash = mpi_hostname_hash();
 -#endif
 -#endif
 -#endif
 -
 -    if (debug)
 -    {
 -        fprintf(debug, "In gmx_physicalnode_id_hash: hash %d\n", hash);
 -    }
 -
 -    return hash;
 -}
 -
  void gmx_setup_nodecomm(FILE gmx_unused *fplog, t_commrec *cr)
  {
      gmx_nodecomm_t *nc;
-     int             n, rank, hostnum, ng, ni;
+     int             n, rank, nodehash, ng, ni;
  
      /* Many MPI implementations do not optimize MPI_Allreduce
       * (and probably also other global communication calls)
      MPI_Comm_size(cr->mpi_comm_mygroup, &n);
      MPI_Comm_rank(cr->mpi_comm_mygroup, &rank);
  
-     hostnum = gmx_hostname_num();
+     nodehash = gmx_physicalnode_id_hash();
  
      if (debug)
      {
  
  
      /* The intra-node communicator, split on node number */
-     MPI_Comm_split(cr->mpi_comm_mygroup, hostnum, rank, &nc->comm_intra);
+     MPI_Comm_split(cr->mpi_comm_mygroup, nodehash, rank, &nc->comm_intra);
      MPI_Comm_rank(nc->comm_intra, &nc->rank_intra);
      if (debug)
      {
@@@ -229,25 -375,25 +229,25 @@@ void gmx_init_intranode_counters(t_comm
      /* thread-MPI is not initialized when not running in parallel */
  #if defined GMX_MPI && !defined GMX_THREAD_MPI
      int nrank_world, rank_world;
-     int i, mynum, *num, *num_s, *num_pp, *num_pp_s;
+     int i, myhash, *hash, *hash_s, *hash_pp, *hash_pp_s;
  
      MPI_Comm_size(MPI_COMM_WORLD, &nrank_world);
      MPI_Comm_rank(MPI_COMM_WORLD, &rank_world);
  
-     /* Get the node number from the hostname to identify the nodes */
-     mynum = gmx_hostname_num();
+     /* Get a (hopefully unique) hash that identifies our physical node */
+     myhash = gmx_physicalnode_id_hash();
  
      /* We can't rely on MPI_IN_PLACE, so we need send and receive buffers */
-     snew(num,   nrank_world);
-     snew(num_s, nrank_world);
-     snew(num_pp,   nrank_world);
-     snew(num_pp_s, nrank_world);
+     snew(hash,   nrank_world);
+     snew(hash_s, nrank_world);
+     snew(hash_pp,   nrank_world);
+     snew(hash_pp_s, nrank_world);
  
-     num_s[rank_world]    = mynum;
-     num_pp_s[rank_world] = (cr->duty & DUTY_PP) ? mynum : -1;
+     hash_s[rank_world]    = myhash;
+     hash_pp_s[rank_world] = (cr->duty & DUTY_PP) ? myhash : -1;
  
-     MPI_Allreduce(num_s,    num,    nrank_world, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
-     MPI_Allreduce(num_pp_s, num_pp, nrank_world, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
+     MPI_Allreduce(hash_s,    hash,    nrank_world, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
+     MPI_Allreduce(hash_pp_s, hash_pp, nrank_world, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
  
      nrank_intranode    = 0;
      rank_intranode     = 0;
      rank_pp_intranode  = 0;
      for (i = 0; i < nrank_world; i++)
      {
-         if (num[i] == mynum)
+         if (hash[i] == myhash)
          {
              nrank_intranode++;
              if (i < rank_world)
                  rank_intranode++;
              }
          }
-         if (num_pp[i] == mynum)
+         if (hash_pp[i] == myhash)
          {
              nrank_pp_intranode++;
              if ((cr->duty & DUTY_PP) && i < rank_world)
              }
          }
      }
-     sfree(num);
-     sfree(num_s);
-     sfree(num_pp);
-     sfree(num_pp_s);
+     sfree(hash);
+     sfree(hash_s);
+     sfree(hash_pp);
+     sfree(hash_pp_s);
  #else
      /* Serial or thread-MPI code: we run within a single physical node */
      nrank_intranode    = cr->nnodes;
@@@ -318,6 -464,33 +318,6 @@@ void gmx_barrier(const t_commrec gmx_un
  #endif
  }
  
 -void gmx_abort(int gmx_unused noderank, int gmx_unused nnodes, int gmx_unused errorno)
 -{
 -#ifndef GMX_MPI
 -    gmx_call("gmx_abort");
 -#else
 -#ifdef GMX_THREAD_MPI
 -    fprintf(stderr, "Halting program %s\n", ShortProgram());
 -    gmx_thanx(stderr);
 -    exit(1);
 -#else
 -    if (nnodes > 1)
 -    {
 -        fprintf(stderr, "Halting parallel program %s on CPU %d out of %d\n",
 -                ShortProgram(), noderank, nnodes);
 -    }
 -    else
 -    {
 -        fprintf(stderr, "Halting program %s\n", ShortProgram());
 -    }
 -
 -    gmx_thanx(stderr);
 -    MPI_Abort(MPI_COMM_WORLD, errorno);
 -    exit(1);
 -#endif
 -#endif
 -}
 -
  void gmx_bcast(int gmx_unused nbytes, void gmx_unused *b, const t_commrec gmx_unused *cr)
  {
  #ifndef GMX_MPI
@@@ -699,47 -872,3 +699,47 @@@ void gmx_sumli_sim(int gmx_unused nr, g
  #endif
  #endif
  }
 +
 +gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr)
 +{
 +    gmx_bool bExist;
 +
 +    if (SIMMASTER(cr))
 +    {
 +        bExist = gmx_fexist(fname);
 +    }
 +    if (PAR(cr))
 +    {
 +        gmx_bcast(sizeof(bExist), &bExist, cr);
 +    }
 +    return bExist;
 +}
 +
 +void gmx_fatal_collective(int f_errno, const char *file, int line,
 +                          const t_commrec *cr, gmx_domdec_t *dd,
 +                          const char *fmt, ...)
 +{
 +    va_list  ap;
 +    gmx_bool bMaster, bFinalize;
 +#ifdef GMX_MPI
 +    int      result;
 +    /* Check if we are calling on all processes in MPI_COMM_WORLD */
 +    if (cr != NULL)
 +    {
 +        MPI_Comm_compare(cr->mpi_comm_mysim, MPI_COMM_WORLD, &result);
 +    }
 +    else
 +    {
 +        MPI_Comm_compare(dd->mpi_comm_all, MPI_COMM_WORLD, &result);
 +    }
 +    /* Any result except MPI_UNEQUAL allows us to call MPI_Finalize */
 +    bFinalize = (result != MPI_UNEQUAL);
 +#else
 +    bFinalize = TRUE;
 +#endif
 +    bMaster = (cr != NULL && MASTER(cr)) || (dd != NULL && DDMASTER(dd));
 +
 +    va_start(ap, fmt);
 +    gmx_fatal_mpi_va(f_errno, file, line, bMaster, bFinalize, fmt, ap);
 +    va_end(ap);
 +}
index afa12f55c8e10619d5df49dc4c9668885a2a97f1,2fc17779590a6a28ad22ce86429eae99e3a50348..f1def42efb7784d3e0a1b6ec250385211e818adf
  #include <config.h>
  #endif
  
 +#include <stdlib.h>
  #include <string.h>
 +
  #include "types/commrec.h"
 -#include "sysstuff.h"
  #include "names.h"
  #include "macros.h"
  #include "nrnb.h"
 -#include "main.h"
  #include "gromacs/utility/smalloc.h"
  
  typedef struct {
@@@ -425,6 -425,15 +425,15 @@@ void print_flop(FILE *out, t_nrnb *nrnb
          fprintf(out, " %-32s %16s %15.3f  %6.1f\n",
                  "Total", "", *mflop, tfrac);
          fprintf(out, "%s\n\n", myline);
+         if (nrnb->n[eNR_NBKERNEL_GENERIC] > 0)
+         {
+             fprintf(out,
+                     "WARNING: Using the slow generic C kernel. This is fine if you are\n"
+                     "comparing different implementations or MD software. Routine\n"
+                     "simulations should use a different non-bonded setup for much better\n"
+                     "performance.\n\n");
+         }
      }
  }
  
index d0dbca8405c0985b605b537b77b45a103f3d9b68,ff9966f70a0147839d2dab5d3e260680a5728f0c..2d45b2754606959545ffbbba894d764ad4c81383
  /* This file is completely threadsafe - please keep it that way! */
  
  #include <stdio.h>
 +#include <stdlib.h>
 +
  #include "typedefs.h"
  #include "types/commrec.h"
  #include "names.h"
  #include "txtdump.h"
 -#include "vec.h"
 +#include "gromacs/math/vec.h"
  #include "macros.h"
  
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  #include "gromacs/utility/smalloc.h"
  
  int pr_indent(FILE *fp, int n)
@@@ -271,7 -269,7 +271,7 @@@ void pr_rvecs(FILE *fp, int indent, con
      const char *format;
      int         i, j;
  
-     if (getenv("LONGFORMAT") != NULL)
+     if (getenv("GMX_PRINT_LONGFORMAT") != NULL)
      {
          format = flong;
      }
@@@ -308,7 -306,7 +308,7 @@@ void pr_rvecs_of_dim(FILE *fp, int inde
      const char *format;
      int         i, j;
  
-     if (getenv("LONGFORMAT") != NULL)
+     if (getenv("GMX_PRINT_LONGFORMAT") != NULL)
      {
          format = flong;
      }
@@@ -376,7 -374,7 +376,7 @@@ void pr_reals_of_dim(FILE *fp, int inde
      const char *flong  = "%15.8e";
      const char *format;
  
-     if (getenv("LONGFORMAT") != NULL)
+     if (getenv("GMX_PRINT_LONGFORMAT") != NULL)
      {
          format = flong;
      }
@@@ -1518,13 -1516,13 +1518,13 @@@ static void low_pr_blocka(FILE *fp, in
          for (i = 0; i <= block->nr; i++)
          {
              (void) pr_indent(fp, indent+INDENT);
 -            (void) fprintf(fp, "%s->index[%d]=%u\n",
 +            (void) fprintf(fp, "%s->index[%d]=%d\n",
                             title, bShowNumbers ? i : -1, block->index[i]);
          }
          for (i = 0; i < block->nra; i++)
          {
              (void) pr_indent(fp, indent+INDENT);
 -            (void) fprintf(fp, "%s->a[%d]=%u\n",
 +            (void) fprintf(fp, "%s->a[%d]=%d\n",
                             title, bShowNumbers ? i : -1, block->a[i]);
          }
      }
@@@ -1605,7 -1603,7 +1605,7 @@@ void pr_blocka(FILE *fp, int indent, co
                          (void) fprintf(fp, "\n");
                          size = pr_indent(fp, indent+INDENT);
                      }
 -                    size += fprintf(fp, "%u", block->a[j]);
 +                    size += fprintf(fp, "%d", block->a[j]);
                  }
                  (void) fprintf(fp, "}\n");
                  start = end;
index beace19aac008b226cafd2859334fa273ed7864f,0384bc921f0253c2a7305258879b27bcc5669f23..794dc8c63387efde491146825349276c05b57c16
   * the research papers on the package. Check out http://www.gromacs.org.
   */
  /* This file is completely threadsafe - keep it that way! */
 +#include "viewit.h"
 +
  #ifdef HAVE_CONFIG_H
  #include <config.h>
  #endif
  
 +#include <stdlib.h>
  #include <string.h>
  
  #include "oenv.h"
 -#include "viewit.h"
 -#include "gromacs/utility/cstringutil.h"
 -#include "gromacs/fileio/filenm.h"
  #include "macros.h"
 -#include "gmx_fatal.h"
 +#include "gromacs/fileio/filenm.h"
 +#include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/fatalerror.h"
  
  static const int   can_view_ftp[] = {
      0,
@@@ -60,7 -58,7 +60,7 @@@ static const char* view_program[] = 
      "ghostview",    "display",      NULL,           "xterm -e rasmol"
  };
  
 -int can_view(int ftp)
 +static int can_view(int ftp)
  {
      int i;
  
@@@ -97,7 -95,7 +97,7 @@@ void do_view(const output_env_t oenv, c
                  case efXVG:
                      if (!(cmd = getenv(env)) )
                      {
-                         if (getenv("XMGR") )
+                         if (getenv("GMX_USE_XMGR") )
                          {
                              cmd = "xmgr";
                          }
index b8e9e6d9b8bb623b11a16a5a12be482f2c834c3c,b2d19cd75df263ecd553ef716a9dd7fa3cace9e4..24710003bc11ceaf89e4e1a6db2cecca56c0f186
  #endif
  
  #include <ctype.h>
 -#include <stdlib.h>
  #include <limits.h>
 -#include "sysstuff.h"
 -#include "gromacs/utility/smalloc.h"
 +#include <stdlib.h>
 +
  #include "typedefs.h"
 -#include "physics.h"
 +#include "gromacs/math/units.h"
  #include "names.h"
 -#include "gmx_fatal.h"
  #include "macros.h"
 -#include "index.h"
 -#include "symtab.h"
 +#include "gromacs/topology/index.h"
  #include "gromacs/utility/cstringutil.h"
  #include "readinp.h"
  #include "warninp.h"
  #include "readir.h"
  #include "toputil.h"
 -#include "index.h"
  #include "network.h"
 -#include "vec.h"
 -#include "pbc.h"
 -#include "mtop_util.h"
 +#include "gromacs/math/vec.h"
 +#include "gromacs/pbcutil/pbc.h"
 +#include "gromacs/topology/mtop_util.h"
  #include "chargegroup.h"
  #include "inputrec.h"
  #include "calc_verletbuf.h"
  
 +#include "gromacs/topology/block.h"
 +#include "gromacs/topology/symtab.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/smalloc.h"
 +
  #define MAXPTR 254
  #define NOGID  255
  
@@@ -1072,7 -1071,7 +1072,7 @@@ void check_ir(const char *mdparin, t_in
          ir->epsilon_r  = 1.0;
      }
  
-     if (getenv("GALACTIC_DYNAMICS") == NULL)
+     if (getenv("GMX_DO_GALACTIC_DYNAMICS") == NULL)
      {
          sprintf(err_buf, "epsilon-r must be >= 0 instead of %g\n", ir->epsilon_r);
          CHECK(ir->epsilon_r < 0);
@@@ -3086,7 -3085,7 +3086,7 @@@ static void make_swap_groups
  
  void make_IMD_group(t_IMD *IMDgroup, char *IMDgname, t_blocka *grps, char **gnames)
  {
 -    int      ig = -1, i;
 +    int      ig, i;
  
  
      ig            = search_string(IMDgname, grps->nr, gnames);
index e3fe4cbd9a637bc861775fa54d83dbf20b015eb2,165a1243d27201af1d4efbcb463b2a6848e07185..c1caca163df069ed4ab2978b657aec2552306d79
  #include <config.h>
  #endif
  
 +#include <assert.h>
  #include <math.h>
  #include <string.h>
 -#include <assert.h>
 -#include "sysstuff.h"
 +
  #include "typedefs.h"
  #include "types/commrec.h"
 -#include "vec.h"
 +#include "gromacs/math/vec.h"
  #include "gromacs/math/utilities.h"
  #include "macros.h"
 -#include "gromacs/utility/smalloc.h"
  #include "macros.h"
 -#include "gmx_fatal.h"
 -#include "physics.h"
 +#include "gromacs/math/units.h"
  #include "force.h"
  #include "tables.h"
  #include "nonbonded.h"
 -#include "invblock.h"
  #include "names.h"
  #include "network.h"
 -#include "pbc.h"
  #include "ns.h"
 -#include "mshift.h"
  #include "txtdump.h"
  #include "coulomb.h"
  #include "md_support.h"
@@@ -62,7 -67,7 +62,7 @@@
  #include "domdec.h"
  #include "qmmm.h"
  #include "copyrite.h"
 -#include "mtop_util.h"
 +#include "gromacs/topology/mtop_util.h"
  #include "nbnxn_simd.h"
  #include "nbnxn_search.h"
  #include "nbnxn_atomdata.h"
  #include "gmx_detect_hardware.h"
  #include "inputrec.h"
  
 +#include "gromacs/pbcutil/ishift.h"
 +#include "gromacs/pbcutil/pbc.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/smalloc.h"
 +
  #include "types/nbnxn_cuda_types_ext.h"
  #include "gpu_utils.h"
  #include "nbnxn_cuda_data_mgmt.h"
@@@ -1775,6 -1775,15 +1775,15 @@@ static void pick_nbnxn_kernel(FIL
                  lookup_nbnxn_kernel_name(*kernel_type),
                  nbnxn_kernel_pairlist_simple(*kernel_type) ? NBNXN_CPU_CLUSTER_I_SIZE : NBNXN_GPU_CLUSTER_SIZE,
                  nbnxn_kernel_to_cj_size(*kernel_type));
+         if (nbnxnk4x4_PlainC == *kernel_type ||
+             nbnxnk8x8x8_PlainC == *kernel_type)
+         {
+             md_print_warn(cr, fp,
+                           "WARNING: Using the slow %s kernels. This should\n"
+                           "not happen during routine usage on supported platforms.\n\n",
+                           lookup_nbnxn_kernel_name(*kernel_type));
+         }
      }
  }
  
index ed2ffcdc22e14c3f0cff8e089013c8e19eacd69b,a3ede7190f921840e851d48b81fb5554c8bb5365..666bd705a2bc4273e86d6611f212567cba1d9d57
  
  #include "typedefs.h"
  
+ #include "gromacs/mdlib/nbnxn_simd.h"
  #ifdef {0}
  
- {1}
- #include "gromacs/simd/macros.h"
- #include "gromacs/simd/vector_operations.h"
+ {1}#include "gromacs/simd/vector_operations.h"
  {2}
  #define GMX_SIMD_J_UNROLL_SIZE {3}
  #include "{4}"
  #include "../nbnxn_kernel_common.h"
  #include "gmx_omp_nthreads.h"
  #include "types/force_flags.h"
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  
  /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels
   */
@@@ -116,7 -117,7 +117,7 @@@ reduce_group_energies(int ng, int ng_2l
  
  #else /* {0} */
  
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  
  #endif /* {0} */
  
index 3cd1cce93b74de3f91a4e0b3c6041d780f2b7a30,0684149bad85f093838e42c941c8593d7aa05567..f48af3b006ffd11f4b75f5507ad807a25347739d
@@@ -48,6 -48,7 +48,7 @@@
  #ifdef GMX_NBNXN_SIMD_4XN
  
  #include "gromacs/simd/vector_operations.h"
  #if !(GMX_SIMD_REAL_WIDTH == 2 || GMX_SIMD_REAL_WIDTH == 4 || GMX_SIMD_REAL_WIDTH == 8)
  #error "unsupported SIMD width"
  #endif
@@@ -57,7 -58,7 +58,7 @@@
  #include "../nbnxn_kernel_common.h"
  #include "gmx_omp_nthreads.h"
  #include "types/force_flags.h"
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  
  /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels
   */
@@@ -250,7 -251,7 +251,7 @@@ reduce_group_energies(int ng, int ng_2l
  
  #else /* GMX_NBNXN_SIMD_4XN */
  
 -#include "gmx_fatal.h"
 +#include "gromacs/utility/fatalerror.h"
  
  #endif /* GMX_NBNXN_SIMD_4XN */
  
index f24c538d3f51856501cd121de0f02d4a83decbff,e7422941aed503572f6d2900777cb609aeaf63a3..61a97056385b1db361cb69ffd6178a1138298685
  #ifdef GMX_QMMM_GAUSSIAN
  
  #include <math.h>
 -#include "sysstuff.h"
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
  #include "typedefs.h"
  #include "macros.h"
  #include "gromacs/utility/smalloc.h"
 -#include "physics.h"
 -#include "macros.h"
 -#include "vec.h"
 +#include "gromacs/math/units.h"
 +#include "gromacs/math/vec.h"
  #include "force.h"
 -#include "invblock.h"
  #include "gromacs/fileio/confio.h"
  #include "names.h"
  #include "network.h"
 -#include "pbc.h"
  #include "ns.h"
  #include "nrnb.h"
  #include "bondf.h"
 -#include "mshift.h"
  #include "txtdump.h"
  #include "qmmm.h"
 -#include <stdio.h>
 -#include <string.h>
 -#include "gmx_fatal.h"
 -#include "typedefs.h"
 -#include <stdlib.h>
 +#include "gromacs/utility/fatalerror.h"
  
  
  /* TODO: this should be made thread-safe */
@@@ -113,7 -118,7 +113,7 @@@ void init_gaussian(t_commrec *cr, t_QMr
          /* we read the number of cpus and environment from the environment
           * if set.
           */
-         buf = getenv("NCPUS");
+         buf = getenv("GMX_QM_GAUSSIAN_NCPUS");
          if (buf)
          {
              sscanf(buf, "%d", &qm->nQMcpus);
              qm->nQMcpus = 1;
          }
          fprintf(stderr, "number of CPUs for gaussian = %d\n", qm->nQMcpus);
-         buf = getenv("MEM");
+         buf = getenv("GMX_QM_GAUSSIAN_MEMORY");
          if (buf)
          {
              sscanf(buf, "%d", &qm->QMmem);
              qm->QMmem = 50000000;
          }
          fprintf(stderr, "memory for gaussian = %d\n", qm->QMmem);
-         buf = getenv("ACC");
+         buf = getenv("GMX_QM_ACCURACY");
          if (buf)
          {
              sscanf(buf, "%d", &qm->accuracy);
          }
          fprintf(stderr, "accuracy in l510 = %d\n", qm->accuracy);
  
-         buf = getenv("CPMCSCF");
+         buf = getenv("GMX_QM_CPMCSCF");
          if (buf)
          {
              sscanf(buf, "%d", &i);
          {
              fprintf(stderr, "NOT using cp-mcscf in l1003\n");
          }
-         buf = getenv("SASTEP");
+         buf = getenv("GMX_QM_SA_STEP");
          if (buf)
          {
              sscanf(buf, "%d", &qm->SAstep);
              fclose(out);
          }
          /* gaussian settings on the system */
-         buf = getenv("GAUSS_DIR");
+         buf = getenv("GMX_QM_GAUSS_DIR");
          fprintf(stderr, "%s", buf);
  
          if (buf)
          }
          else
          {
-             gmx_fatal(FARGS, "no $GAUSS_DIR, check gaussian manual\n");
+             gmx_fatal(FARGS, "no $GMX_QM_GAUSS_DIR, check gaussian manual\n");
          }
  
-         buf = getenv("GAUSS_EXE");
+         buf = getenv("GMX_QM_GAUSS_EXE");
          if (buf)
          {
              qm->gauss_exe = strdup(buf);
          }
          else
          {
-             gmx_fatal(FARGS, "no $GAUSS_EXE, check gaussian manual\n");
+             gmx_fatal(FARGS, "no $GMX_QM_GAUSS_EXE set, check gaussian manual\n");
          }
-         buf = getenv("DEVEL_DIR");
+         buf = getenv("GMX_QM_MODIFIED_LINKS_DIR");
          if (buf)
          {
              qm->devel_dir = strdup (buf);
          }
          else
          {
-             gmx_fatal(FARGS, "no $DEVEL_DIR, this is were the modified links reside.\n");
+             gmx_fatal(FARGS, "no $GMX_QM_MODIFIED_LINKS_DIR, this is were the modified links reside.\n");
          }
  
          /*  if(fr->bRF){*/
@@@ -1107,7 -1112,7 +1107,7 @@@ real call_gaussian_SH(t_commrec *cr, t_
      if (!step)
      {
          snew(buf, 20);
-         buf = getenv("STATE");
+         buf = getenv("GMX_QM_GROUND_STATE");
          if (buf)
          {
              sscanf(buf, "%d", &state);
index a8860d679fd5bb84f49e429168445b0d6fdb261c,7dbee944afdbf4dc7ee22bf097f5bb460a42f581..2b4912d073168ae873f0f04a2a862ad23f8e1793
  #endif
  
  #include <math.h>
 -#include "sysstuff.h"
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
  #include "typedefs.h"
  #include "macros.h"
  #include "gromacs/utility/smalloc.h"
 -#include "physics.h"
 -#include "macros.h"
 -#include "vec.h"
 +#include "gromacs/math/units.h"
 +#include "gromacs/math/vec.h"
  #include "force.h"
 -#include "invblock.h"
  #include "gromacs/fileio/confio.h"
  #include "names.h"
  #include "network.h"
 -#include "pbc.h"
  #include "ns.h"
  #include "nrnb.h"
  #include "bondf.h"
 -#include "mshift.h"
  #include "txtdump.h"
  #include "qmmm.h"
 -#include <stdio.h>
 -#include <string.h>
 -#include "gmx_fatal.h"
 -#include "typedefs.h"
 -#include <stdlib.h>
 +#include "gromacs/utility/fatalerror.h"
  
  /* ORCA interface routines */
  
@@@ -67,7 -72,7 +67,7 @@@ void init_orca(t_QMrec *qm
      snew(buf, 200);
  
      /* ORCA settings on the system */
-     buf = getenv("BASENAME");
+     buf = getenv("GMX_QM_ORCA_BASENAME");
      if (buf)
      {
          snew(qm->orca_basename, 200);
      }
      else
      {
-         gmx_fatal(FARGS, "$BASENAME not set\n");
+         gmx_fatal(FARGS, "$GMX_QM_ORCA_BASENAME is not set\n");
      }
  
      /* ORCA directory on the system */
      snew(buf, 200);
-     buf = getenv("ORCA_PATH");
+     buf = getenv("GMX_ORCA_PATH");
  
      if (buf)
      {
@@@ -89,7 -94,7 +89,7 @@@
      }
      else
      {
-         gmx_fatal(FARGS, "$ORCA_PATH not set, check manual\n");
+         gmx_fatal(FARGS, "$GMX_ORCA_PATH not set, check manual\n");
      }
  
      fprintf(stderr, "Setting ORCA path to: %s...\n", qm->orca_dir);
index d4adc345a8dfb72cca9202d837921d272b2d4c80,0000000000000000000000000000000000000000..8e74d6bf82da1c18ee0590abcdf385a8a58f18d5
mode 100644,000000..100644
--- /dev/null
@@@ -1,270 -1,0 +1,254 @@@
- #if defined GMX_LIB_MPI && defined GMX_TARGET_BGQ
- #include <spi/include/kernel/location.h>
- #endif
- int gmx_physicalnode_id_hash(void)
 +/*
 + * This file is part of the GROMACS molecular simulation package.
 + *
 + * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
 + * 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.
 + *
 + * 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.
 + *
 + * 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.
 + *
 + * 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.
 + *
 + * To help us fund GROMACS development, we humbly ask that you cite
 + * the research papers on the package. Check out http://www.gromacs.org.
 + */
 +#include "basenetwork.h"
 +
 +#include "config.h"
 +
 +#include <cctype>
 +#include <cstdio>
 +#include <cstdlib>
 +#include <cstring>
 +
 +#include <algorithm>
 +#include <exception>
 +
 +#ifdef HAVE_UNISTD_H
 +#include <unistd.h>
 +#endif
 +
 +#include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/gmxmpi.h"
 +#include "gromacs/utility/programcontext.h"
 +
 +int gmx_gethostname(char *name, size_t len)
 +{
 +    if (len < 8)
 +    {
 +        gmx_incons("gmx_gethostname called with len<8");
 +    }
 +#if defined(HAVE_UNISTD_H) && !defined(__native_client__)
 +    if (gethostname(name, len-1) != 0)
 +    {
 +        std::strncpy(name, "unknown", 8);
 +        return -1;
 +    }
 +    return 0;
 +#else
 +    std::strncpy(name, "unknown", 8);
 +    return -1;
 +#endif
 +}
 +
 +gmx_bool gmx_mpi_initialized(void)
 +{
 +#ifndef GMX_MPI
 +    return 0;
 +#else
 +    int n;
 +    MPI_Initialized(&n);
 +
 +    return n;
 +#endif
 +}
 +
 +int gmx_node_num(void)
 +{
 +#ifndef GMX_MPI
 +    return 1;
 +#else
 +    int i;
 +    (void) MPI_Comm_size(MPI_COMM_WORLD, &i);
 +    return i;
 +#endif
 +}
 +
 +int gmx_node_rank(void)
 +{
 +#ifndef GMX_MPI
 +    return 0;
 +#else
 +    int i;
 +    (void) MPI_Comm_rank(MPI_COMM_WORLD, &i);
 +    return i;
 +#endif
 +}
 +
- int gmx_hostname_num()
- {
- #ifndef GMX_MPI
-     return 0;
- #else
- #ifdef GMX_THREAD_MPI
-     /* thread-MPI currently puts the thread number in the process name,
-      * we might want to change this, as this is inconsistent with what
-      * most MPI implementations would do when running on a single node.
-      */
-     return 0;
- #else
-     int  resultlen, hostnum, i, j;
-     char mpi_hostname[MPI_MAX_PROCESSOR_NAME], hostnum_str[MPI_MAX_PROCESSOR_NAME];
++static int mpi_hostname_hash(void)
 +{
 +    int hash_int;
 +
 +#ifndef GMX_LIB_MPI
 +    /* We have a single physical node */
 +    hash_int = 0;
 +#else
 +    int  resultlen;
 +    char mpi_hostname[MPI_MAX_PROCESSOR_NAME];
 +
 +    /* This procedure can only differentiate nodes with different names.
 +     * Architectures where different physical nodes have identical names,
 +     * such as IBM Blue Gene, should use an architecture specific solution.
 +     */
 +    MPI_Get_processor_name(mpi_hostname, &resultlen);
 +
 +    /* The string hash function returns an unsigned int. We cast to an int.
 +     * Negative numbers are converted to positive by setting the sign bit to 0.
 +     * This makes the hash one bit smaller.
 +     * A 63-bit hash (with 64-bit int) should be enough for unique node hashes,
 +     * even on a million node machine. 31 bits might not be enough though!
 +     */
 +    hash_int =
 +        (int)gmx_string_fullhash_func(mpi_hostname, gmx_string_hash_init);
 +    if (hash_int < 0)
 +    {
 +        hash_int -= INT_MIN;
 +    }
 +#endif
 +
 +    return hash_int;
 +}
 +
-     MPI_Get_processor_name(mpi_hostname, &resultlen);
- #ifdef GMX_TARGET_BGQ
++#if defined GMX_LIB_MPI && defined GMX_TARGET_BGQ
++#include <spi/include/kernel/location.h>
 +
- #else
-     /* This procedure can only differentiate nodes with host names
-      * that end on unique numbers.
-      */
-     i = 0;
-     j = 0;
-     /* Only parse the host name up to the first dot */
-     while (i < resultlen && mpi_hostname[i] != '.')
-     {
-         if (std::isdigit(mpi_hostname[i]))
-         {
-             hostnum_str[j++] = mpi_hostname[i];
-         }
-         i++;
-     }
-     hostnum_str[j] = '\0';
-     if (j == 0)
-     {
-         hostnum = 0;
-     }
-     else
-     {
-         /* Use only the last 9 decimals, so we don't overflow an int */
-         hostnum = std::strtol(hostnum_str + std::max(0, j-9), NULL, 10);
-     }
- #endif
++static int bgq_nodenum(void)
++{
++    int           hostnum;
 +    Personality_t personality;
 +    Kernel_GetPersonality(&personality, sizeof(personality));
 +    /* Each MPI rank has a unique coordinate in a 6-dimensional space
 +       (A,B,C,D,E,T), with dimensions A-E corresponding to different
 +       physical nodes, and T within each node. Each node has sixteen
 +       physical cores, each of which can have up to four hardware
 +       threads, so 0 <= T <= 63 (but the maximum value of T depends on
 +       the confituration of ranks and OpenMP threads per
 +       node). However, T is irrelevant for computing a suitable return
 +       value for gmx_hostname_num().
 +     */
 +    hostnum  = personality.Network_Config.Acoord;
 +    hostnum *= personality.Network_Config.Bnodes;
 +    hostnum += personality.Network_Config.Bcoord;
 +    hostnum *= personality.Network_Config.Cnodes;
 +    hostnum += personality.Network_Config.Ccoord;
 +    hostnum *= personality.Network_Config.Dnodes;
 +    hostnum += personality.Network_Config.Dcoord;
 +    hostnum *= personality.Network_Config.Enodes;
 +    hostnum += personality.Network_Config.Ecoord;
-         std::fprintf(debug, "In gmx_hostname_num: hostname '%s', hostnum %d\n",
-                      mpi_hostname, hostnum);
- #ifdef GMX_TARGET_BGQ
 +
 +    if (debug)
 +    {
- #endif
 +        std::fprintf(debug,
 +                     "Torus ID A: %d / %d B: %d / %d C: %d / %d D: %d / %d E: %d / %d\n"
 +                     "Node ID T: %d / %d core: %d / %d hardware thread: %d / %d\n",
 +                     personality.Network_Config.Acoord,
 +                     personality.Network_Config.Anodes,
 +                     personality.Network_Config.Bcoord,
 +                     personality.Network_Config.Bnodes,
 +                     personality.Network_Config.Ccoord,
 +                     personality.Network_Config.Cnodes,
 +                     personality.Network_Config.Dcoord,
 +                     personality.Network_Config.Dnodes,
 +                     personality.Network_Config.Ecoord,
 +                     personality.Network_Config.Enodes,
 +                     Kernel_ProcessorCoreID(),
 +                     16,
 +                     Kernel_ProcessorID(),
 +                     64,
 +                     Kernel_ProcessorThreadID(),
 +                     4);
 +    }
 +    return hostnum;
++}
++#endif
++
++int gmx_physicalnode_id_hash(void)
++{
++    int hash;
++
++#ifndef GMX_MPI
++    hash = 0;
++#else
++#ifdef GMX_THREAD_MPI
++    /* thread-MPI currently puts the thread number in the process name,
++     * we might want to change this, as this is inconsistent with what
++     * most MPI implementations would do when running on a single node.
++     */
++    hash = 0;
++#else
++#ifdef GMX_TARGET_BGQ
++    hash = bgq_nodenum();
++#else
++    hash = mpi_hostname_hash();
 +#endif
 +#endif
++#endif
++
++    if (debug)
++    {
++        fprintf(debug, "In gmx_physicalnode_id_hash: hash %d\n", hash);
++    }
++
++    return hash;
 +}
 +
 +#ifdef GMX_LIB_MPI
 +void gmx_abort(int errorno)
 +{
 +    const char *programName = "GROMACS";
 +    try
 +    {
 +        programName = gmx::getProgramContext().displayName();
 +    }
 +    catch (const std::exception &)
 +    {
 +    }
 +    const int nnodes   = gmx_node_num();
 +    const int noderank = gmx_node_rank();
 +    if (nnodes > 1)
 +    {
 +        std::fprintf(stderr, "Halting parallel program %s on node %d out of %d\n",
 +                     programName, noderank, nnodes);
 +    }
 +    else
 +    {
 +        std::fprintf(stderr, "Halting program %s\n", programName);
 +    }
 +
 +    MPI_Abort(MPI_COMM_WORLD, errorno);
 +    std::exit(errorno);
 +}
 +#endif
index a14a2a18337db775b2c4383f5fe1377a874c7590,002fb2d200af04246aa667eff1cef31eb54d1033..179b91005e48762966a0dac588b517b63fd3c0eb
   * To help us fund GROMACS development, we humbly ask that you cite
   * the research papers on the package. Check out http://www.gromacs.org.
   */
 -#include "gmx_fatal.h"
 -#include "gmx_fatal_collective.h"
 +#include "fatalerror.h"
  
  #ifdef HAVE_CONFIG_H
  #include <config.h>
  #endif
  
 -#include <ctype.h>
 -#include <errno.h>
 -#include <stdarg.h>
 -#include <string.h>
 +#include <cerrno>
 +#include <cstdarg>
 +#include <cstdlib>
 +#include <cstring>
  
 -#include "thread_mpi/threads.h"
 +#include <exception>
  
 -#include "main.h"
 -#include "types/commrec.h"
 -#include "network.h"
 -#include "copyrite.h"
 -#include "macros.h"
 +#include "thread_mpi/threads.h"
  
 -#include "gromacs/fileio/futil.h"
 -#include "gromacs/fileio/gmxfio.h"
 +#include "gromacs/utility/basenetwork.h"
 +#include "gromacs/utility/baseversion.h"
 +#include "gromacs/utility/common.h"
  #include "gromacs/utility/cstringutil.h"
 +#include "gromacs/utility/futil.h"
  #include "gromacs/utility/gmxmpi.h"
 +#include "gromacs/utility/programcontext.h"
  #include "gromacs/utility/smalloc.h"
  
  static gmx_bool            bDebug         = FALSE;
  static FILE               *log_file       = NULL;
  
 -static tMPI_Thread_mutex_t debug_mutex     = TMPI_THREAD_MUTEX_INITIALIZER;
 -static tMPI_Thread_mutex_t where_mutex     = TMPI_THREAD_MUTEX_INITIALIZER;
 +static tMPI_Thread_mutex_t debug_mutex    = TMPI_THREAD_MUTEX_INITIALIZER;
 +static tMPI_Thread_mutex_t where_mutex    = TMPI_THREAD_MUTEX_INITIALIZER;
 +
 +static const char *const   gmxuser
 +    = "Please report this to the mailing list (gmx-users@gromacs.org)";
  
  gmx_bool bDebugMode(void)
  {
 -    gmx_bool ret;
 -#if 0
 -    tMPI_Thread_mutex_lock(&debug_mutex);
 -#endif
 -    ret = bDebug;
 -#if 0
 -    tMPI_Thread_mutex_unlock(&debug_mutex);
 -#endif
      return bDebug;
  }
  
@@@ -91,7 -98,7 +91,7 @@@ void _where(const char *file, int line
          if (bFirst) /* we repeat the check in the locked section because things
                         might have changed */
          {
-             if ((temp = getenv("WHERE")) != NULL)
+             if ((temp = getenv("GMX_PRINT_DEBUG_LINES")) != NULL)
              {
                  nskip = strtol(temp, NULL, 10);
              }
  
  static int fatal_errno = 0;
  
 -static void quit_gmx(const char *msg)
 +static void default_error_handler(const char *msg)
  {
      tMPI_Thread_mutex_lock(&debug_mutex);
      if (fatal_errno == 0)
          }
          perror(msg);
      }
 +    tMPI_Thread_mutex_unlock(&debug_mutex);
 +}
  
 -#ifdef GMX_LIB_MPI
 -    if (gmx_mpi_initialized())
 -    {
 -        int  nnodes;
 -        int  noderank;
 +static void (*gmx_error_handler)(const char *msg) = default_error_handler;
  
 -        nnodes   = gmx_node_num();
 -        noderank = gmx_node_rank();
 +void set_gmx_error_handler(void (*func)(const char *msg))
 +{
 +    // TODO: Either this is unnecessary, or also reads to the handler should be
 +    // protected by a mutex.
 +    tMPI_Thread_mutex_lock(&debug_mutex);
 +    gmx_error_handler = func;
 +    tMPI_Thread_mutex_unlock(&debug_mutex);
 +}
  
 -        if (nnodes > 1)
 -        {
 -            fprintf(stderr, "Error on node %d, will try to stop all the nodes\n",
 -                    noderank);
 -        }
 -        gmx_abort(noderank, nnodes, -1);
 -    }
 -#endif
 +static void call_error_handler(const char *key, const char *file, int line, const char *msg)
 +{
 +    char        buf[10240], errerrbuf[1024];
 +    const char *llines = "-------------------------------------------------------";
 +    char       *strerr;
  
 -    if (debug)
 +    if (msg == NULL)
      {
 -        fflush(debug);
 +        sprintf(errerrbuf, "Empty fatal_error message. %s", gmxuser);
      }
 -    if (bDebugMode())
 +    // In case ProgramInfo is not initialized and there is an issue with the
 +    // initialization, fall back to "GROMACS".
 +    const char *programName = "GROMACS";
 +    try
 +    {
 +        programName = gmx::getProgramContext().displayName();
 +    }
 +    catch (const std::exception &)
      {
 -        fprintf(stderr, "dump core (y/n):");
 -        fflush(stderr);
 -        if (toupper(getc(stdin)) != 'N')
 -        {
 -            (void) abort();
 -        }
      }
  
 -    exit(fatal_errno);
 -    tMPI_Thread_mutex_unlock(&debug_mutex);
 +    strerr = gmx_strerror(key);
 +    sprintf(buf, "\n%s\nProgram %s, %s\n"
 +            "Source code file: %s, line: %d\n\n"
 +            "%s:\n%s\nFor more information and tips for troubleshooting, please check the GROMACS\n"
 +            "website at http://www.gromacs.org/Documentation/Errors\n%s\n",
 +            llines, programName, gmx_version(), file, line,
 +            strerr, msg ? msg : errerrbuf, llines);
 +    free(strerr);
 +
 +    gmx_error_handler(buf);
  }
  
 -/* The function below should be identical to quit_gmx,
 - * except that is does not actually quit and call gmx_abort.
 - */
 -static void quit_gmx_noquit(const char *msg)
 +GMX_ATTRIBUTE_NORETURN static void do_exit(bool bMaster, bool bFinalize)
  {
 -    tMPI_Thread_mutex_lock(&debug_mutex);
 -    if (!fatal_errno)
 -    {
 -        if (log_file)
 -        {
 -            fprintf(log_file, "%s\n", msg);
 -        }
 -        fprintf(stderr, "%s\n", msg);
 -        /* we set it to no-zero because if this function is called, something
 -           has gone wrong */
 -        fatal_errno = 255;
 -    }
 -    else
 -    {
 -        if (fatal_errno != -1)
 -        {
 -            errno = fatal_errno;
 -        }
 -        perror(msg);
 -    }
 -
 -#ifndef GMX_LIB_MPI
      if (debug)
      {
          fflush(debug);
      }
 -    if (bDebugMode())
 +
 +#ifdef GMX_MPI
 +    if (gmx_mpi_initialized())
      {
 -        fprintf(stderr, "dump core (y/n):");
 -        fflush(stderr);
 -        if (toupper(getc(stdin)) != 'N')
 +        if (bFinalize)
          {
 -            (void) abort();
 +            /* Broadcast the fatal error number possibly modified
 +             * on the master process, in case the user would like
 +             * to use the return status on a non-master process.
 +             * The master process in cr and dd always has global rank 0.
 +             */
 +            MPI_Bcast(&fatal_errno, sizeof(fatal_errno), MPI_BYTE,
 +                      0, MPI_COMM_WORLD);
 +
 +            /* Finalize nicely instead of aborting */
 +            MPI_Finalize();
          }
 -    }
 +        else if (bMaster)
 +        {
 +#ifdef GMX_LIB_MPI
 +            gmx_abort(1);
  #endif
 -
 -    tMPI_Thread_mutex_unlock(&debug_mutex);
 -}
 -
 -void gmx_fatal(int f_errno, const char *file, int line, const char *fmt, ...)
 -{
 -    va_list ap;
 -    char    msg[STRLEN];
 -
 -    va_start(ap, fmt);
 -    vsprintf(msg, fmt, ap);
 -    va_end(ap);
 -
 -    tMPI_Thread_mutex_lock(&debug_mutex);
 -    fatal_errno = f_errno;
 -    tMPI_Thread_mutex_unlock(&debug_mutex);
 -
 -    _gmx_error("fatal", msg, file, line);
 -}
 -
 -void gmx_fatal_collective(int f_errno, const char *file, int line,
 -                          const t_commrec *cr, gmx_domdec_t *dd,
 -                          const char *fmt, ...)
 -{
 -    gmx_bool    bFinalize;
 -    va_list     ap;
 -    char        msg[STRLEN];
 -#ifdef GMX_MPI
 -    int         result;
 +        }
 +        else
 +        {
 +            /* Let all other processes wait till the master has printed
 +             * the error message and issued MPI_Abort.
 +             */
 +            MPI_Barrier(MPI_COMM_WORLD);
 +        }
 +    }
 +#else
 +    GMX_UNUSED_VALUE(bMaster);
 +    GMX_UNUSED_VALUE(bFinalize);
  #endif
  
 -    bFinalize = TRUE;
 -
 -#ifdef GMX_MPI
 -    /* Check if we are calling on all processes in MPI_COMM_WORLD */
 -    if (cr != NULL)
 -    {
 -        MPI_Comm_compare(cr->mpi_comm_mysim, MPI_COMM_WORLD, &result);
 -    }
 -    else
 +    if (bDebugMode())
      {
 -        MPI_Comm_compare(dd->mpi_comm_all, MPI_COMM_WORLD, &result);
 +        std::abort();
      }
 -    /* Any result except MPI_UNEQUAL allows us to call MPI_Finalize */
 -    bFinalize = (result != MPI_UNEQUAL);
 -#endif
 +    std::exit(1);
 +}
  
 -    if ((cr != NULL && MASTER(cr)  ) ||
 -        (dd != NULL && DDMASTER(dd)))
 +void gmx_fatal_mpi_va(int f_errno, const char *file, int line,
 +                      gmx_bool bMaster, gmx_bool bFinalize,
 +                      const char *fmt, va_list ap)
 +{
 +    if (bMaster)
      {
 -        va_start(ap, fmt);
 +        char msg[STRLEN];
          vsprintf(msg, fmt, ap);
 -        va_end(ap);
  
          tMPI_Thread_mutex_lock(&debug_mutex);
          fatal_errno = f_errno;
          tMPI_Thread_mutex_unlock(&debug_mutex);
  
 -        if (bFinalize)
 -        {
 -            /* Use an error handler that does not quit */
 -            set_gmx_error_handler(quit_gmx_noquit);
 -        }
 -
 -        _gmx_error("fatal", msg, file, line);
 +        call_error_handler("fatal", file, line, msg);
      }
  
 -#ifdef GMX_MPI
 -    if (bFinalize)
 -    {
 -        /* Broadcast the fatal error number possibly modified
 -         * on the master process, in case the user would like
 -         * to use the return status on a non-master process.
 -         * The master process in cr and dd always has global rank 0.
 -         */
 -        MPI_Bcast(&fatal_errno, sizeof(fatal_errno), MPI_BYTE,
 -                  0, MPI_COMM_WORLD);
 -
 -        /* Finalize nicely instead of aborting */
 -        MPI_Finalize();
 -    }
 -    else
 -    {
 -        /* Let all other processes wait till the master has printed
 -         * the error message and issued MPI_Abort.
 -         */
 -        MPI_Barrier(MPI_COMM_WORLD);
 -    }
 -#endif
 +    do_exit(bMaster, bFinalize);
 +}
  
 -    exit(fatal_errno);
 +void gmx_fatal(int f_errno, const char *file, int line, const char *fmt, ...)
 +{
 +    va_list ap;
 +    va_start(ap, fmt);
 +    gmx_fatal_mpi_va(f_errno, file, line, TRUE, FALSE, fmt, ap);
 +    va_end(ap);
  }
  
  /*
@@@ -282,7 -337,7 +282,7 @@@ void init_debug(const int dbglevel, con
      if (!bDebug) /* another thread hasn't already run this*/
      {
          no_buffers();
 -        debug  = gmx_fio_fopen(dbgfile, "w+");
 +        debug  = gmx_ffopen(dbgfile, "w+");
          bDebug = TRUE;
          if (dbglevel >= 2)
          {
      tMPI_Thread_mutex_unlock(&debug_mutex);
  }
  
 -static const char *gmxuser = "Please report this to the mailing list (gmx-users@gromacs.org)";
 -
 -static void        (*gmx_error_handler)(const char *msg) = quit_gmx;
 -
 -void set_gmx_error_handler(void (*func)(const char *msg))
 -{
 -    tMPI_Thread_mutex_lock(&debug_mutex);
 -    gmx_error_handler = func;
 -    tMPI_Thread_mutex_unlock(&debug_mutex);
 -}
 -
  char *gmx_strerror(const char *key)
  {
      typedef struct {
          { "input",  "Input error or input inconsistency" },
          { "mem",    "Memory allocation/freeing error" },
          { "open",   "Can not open file" },
 -        { "range",  "Range checking error" }
 +        { "range",  "Range checking error" },
 +        { NULL,     NULL}
      };
 -#define NMSG asize(msg)
 -    char        buf[1024];
 -    size_t      i;
  
      if (key == NULL)
      {
      }
      else
      {
 -        for (i = 0; (i < NMSG); i++)
 +        for (size_t i = 0; msg[i].key != NULL; ++i)
          {
              if (strcmp(key, msg[i].key) == 0)
              {
 -                break;
 +                return strdup(msg[i].msg);
              }
          }
 -        if (i == NMSG)
 -        {
 -            sprintf(buf, "No error message associated with key %s\n%s", key, gmxuser);
 -            return strdup(buf);
 -        }
 -        else
 -        {
 -            return strdup(msg[i].msg);
 -        }
 +        char buf[1024];
 +        sprintf(buf, "No error message associated with key %s\n%s", key, gmxuser);
 +        return strdup(buf);
      }
  }
  
  
  void _gmx_error(const char *key, const char *msg, const char *file, int line)
  {
 -    char        buf[10240], errerrbuf[1024];
 -    const char *llines = "-------------------------------------------------------";
 -    char       *strerr;
 -
 -    /* protect the audience from suggestive discussions */
 -
 -    if (msg == NULL)
 -    {
 -        sprintf(errerrbuf, "Empty fatal_error message. %s", gmxuser);
 -    }
 -
 -    strerr = gmx_strerror(key);
 -    sprintf(buf, "\n%s\nProgram %s, %s\n"
 -            "Source code file: %s, line: %d\n\n"
 -            "%s:\n%s\nFor more information and tips for troubleshooting, please check the GROMACS\n"
 -            "website at http://www.gromacs.org/Documentation/Errors\n%s\n",
 -            llines, ShortProgram(), GromacsVersion(), file, line,
 -            strerr, msg ? msg : errerrbuf, llines);
 -    free(strerr);
 -
 -    gmx_error_handler(buf);
 +    call_error_handler(key, file, line, msg);
 +    do_exit(true, false);
  }
  
  void _range_check(int n, int n_min, int n_max, const char *warn_str,
index 312d6a4a8e03ebc57ba6b5c307f35c846bde66cc,f81f4dcbdab70c45a04edd2037e2cbbfcddf7077..81f9c77d8c670a4215178fcddeae2fe204b95561
@@@ -34,8 -34,6 +34,8 @@@
   * To help us fund GROMACS development, we humbly ask that you cite
   * the research papers on the package. Check out http://www.gromacs.org.
   */
 +#include "gromacs/utility/futil.h"
 +
  #ifdef HAVE_CONFIG_H
  #include "config.h"
  #endif
  
  #include "thread_mpi/threads.h"
  
 -#include "gromacs/legacyheaders/gmx_fatal.h"
 -#include "gromacs/legacyheaders/types/commrec.h"
 -#include "gromacs/legacyheaders/network.h"
 -
 -#include "gromacs/fileio/futil.h"
 -#include "gromacs/fileio/path.h"
  #include "gromacs/utility/cstringutil.h"
  #include "gromacs/utility/exceptions.h"
 +#include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/path.h"
  #include "gromacs/utility/programcontext.h"
  #include "gromacs/utility/smalloc.h"
  #include "gromacs/utility/stringutil.h"
@@@ -196,6 -198,10 +196,6 @@@ int gmx_ffclose(FILE *fp
  }
  
  
 -#ifdef rewind
 -#undef rewind
 -#endif
 -
  void frewind(FILE *fp)
  {
      tMPI_Thread_mutex_lock(&pstack_mutex);
@@@ -241,6 -247,26 +241,6 @@@ gmx_off_t gmx_ftell(FILE *stream
  #endif
  }
  
 -
 -gmx_bool is_pipe(FILE *fp)
 -{
 -    tMPI_Thread_mutex_lock(&pstack_mutex);
 -
 -    t_pstack *ps = pstack;
 -    while (ps != NULL)
 -    {
 -        if (ps->fp == fp)
 -        {
 -            tMPI_Thread_mutex_unlock(&pstack_mutex);
 -            return TRUE;
 -        }
 -        ps = ps->prev;
 -    }
 -    tMPI_Thread_mutex_unlock(&pstack_mutex);
 -    return FALSE;
 -}
 -
 -
  static FILE *uncompress(const char *fn, const char *mode)
  {
      FILE *fp;
@@@ -299,6 -325,41 +299,6 @@@ gmx_bool gmx_fexist(const char *fname
      }
  }
  
 -
 -gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr)
 -{
 -    gmx_bool bExist;
 -
 -    if (SIMMASTER(cr))
 -    {
 -        bExist = gmx_fexist(fname);
 -    }
 -    if (PAR(cr))
 -    {
 -        gmx_bcast(sizeof(bExist), &bExist, cr);
 -    }
 -    return bExist;
 -}
 -
 -gmx_bool gmx_eof(FILE *fp)
 -{
 -    char     data[4];
 -    gmx_bool beof;
 -
 -    if (is_pipe(fp))
 -    {
 -        return feof(fp);
 -    }
 -    else
 -    {
 -        if ((beof = fread(data, 1, 1, fp)) == 1)
 -        {
 -            gmx_fseek(fp, -1, SEEK_CUR);
 -        }
 -        return !beof;
 -    }
 -}
 -
  static char *backup_fn(const char *file, int count_max)
  {
      /* Use a reasonably low value for countmax; we might
@@@ -434,7 -495,7 +434,7 @@@ FILE *gmx_ffopen(const char *file, cons
          /* Check whether we should be using buffering (default) or not
           * (for debugging)
           */
-         if (bUnbuffered || ((bufsize = getenv("LOG_BUFS")) != NULL))
+         if (bUnbuffered || ((bufsize = getenv("GMX_LOG_BUFFER")) != NULL))
          {
              /* Check whether to use completely unbuffered */
              if (bUnbuffered)
@@@ -804,6 -865,28 +804,6 @@@ void gmx_tmpnam(char *buf
      /* name in Buf should now be OK */
  }
  
 -int gmx_truncatefile(char *path, gmx_off_t length)
 -{
 -#ifdef _MSC_VER
 -    /* Microsoft visual studio does not have "truncate" */
 -    HANDLE        fh;
 -    LARGE_INTEGER win_length;
 -
 -    win_length.QuadPart = length;
 -
 -    fh = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
 -                    OPEN_EXISTING, 0, NULL);
 -    SetFilePointerEx(fh, win_length, NULL, FILE_BEGIN);
 -    SetEndOfFile(fh);
 -    CloseHandle(fh);
 -
 -    return 0;
 -#else
 -    return truncate(path, length);
 -#endif
 -}
 -
 -
  int gmx_file_rename(const char *oldname, const char *newname)
  {
  #ifndef GMX_NATIVE_WINDOWS
index 03141a25a7cf34474f8ac566acd2a4a0e1a0cba6,0000000000000000000000000000000000000000..a8fb5a52deec970017af31f1f15437b9bc0fccb8
mode 100644,000000..100644
--- /dev/null
@@@ -1,115 -1,0 +1,115 @@@
- #define GMX_DOUBLE_EPS   1.11022302E-16
 +/*
 + * This file is part of the GROMACS molecular simulation package.
 + *
 + * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
 + * 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.
 + *
 + * 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.
 + *
 + * 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.
 + *
 + * 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.
 + *
 + * To help us fund GROMACS development, we humbly ask that you cite
 + * the research papers on the package. Check out http://www.gromacs.org.
 + */
 +/*! \file
 + * \brief
 + * Declares `real` and related constants.
 + *
 + * \inpublicapi
 + * \ingroup module_utility
 + */
 +#ifndef GMX_UTILITY_REAL_H
 +#define GMX_UTILITY_REAL_H
 +
 +/*! \brief Double precision accuracy */
- #define GMX_DOUBLE_MAX   1.79769312E+308
++#define GMX_DOUBLE_EPS   2.2204460492503131e-16
 +
 +/*! \brief Maximum double precision value - reduced 1 unit in last digit for MSVC */
- #define GMX_DOUBLE_MIN   2.22507386E-308
++#define GMX_DOUBLE_MAX   1.7976931348623157e+308
 +
 +/*! \brief Minimum double precision value */
- #define GMX_FLOAT_EPS    5.96046448E-08
++#define GMX_DOUBLE_MIN   2.2250738585072014e-308
 +
 +/*! \brief Single precision accuracy */
- #define GMX_FLOAT_MAX    3.40282346E+38
++#define GMX_FLOAT_EPS    1.19209290e-07F
 +
 +/*! \brief Maximum single precision value - reduced 1 unit in last digit for MSVC */
- #define GMX_FLOAT_MIN    1.17549435E-38
++#define GMX_FLOAT_MAX    3.40282346E+38F
 +
 +/*! \brief Minimum single precision value */
++#define GMX_FLOAT_MIN    1.175494351E-38F
 +
 +
 +/*! \typedef real
 + * \brief Precision-dependent \Gromacs floating-point type.
 + */
 +/*! \def HAVE_REAL
 + * \brief Used to check whether `real` is already defined.
 + */
 +/*! \def GMX_MPI_REAL
 + * \brief MPI data type for `real`.
 + */
 +/*! \def GMX_REAL_EPS
 + * \brief Accuracy for `real`.
 + */
 +/*! \def GMX_REAL_MIN
 + * \brief Smallest non-zero value for `real`.
 + */
 +/*! \def GMX_REAL_MAX
 + * \brief Largest finite value for `real`.
 + */
 +/*! \def gmx_real_fullprecision_pfmt
 + * \brief Format string for full `real` precision.
 + */
 +#ifdef GMX_DOUBLE
 +
 +#ifndef HAVE_REAL
 +typedef double      real;
 +#define HAVE_REAL
 +#endif
 +
 +#define GMX_MPI_REAL    MPI_DOUBLE
 +#define GMX_REAL_EPS    GMX_DOUBLE_EPS
 +#define GMX_REAL_MIN    GMX_DOUBLE_MIN
 +#define GMX_REAL_MAX    GMX_DOUBLE_MAX
 +#define gmx_real_fullprecision_pfmt "%21.14e"
 +
 +#else /* GMX_DOUBLE */
 +
 +#ifndef HAVE_REAL
 +typedef float           real;
 +#define HAVE_REAL
 +#endif
 +
 +#define GMX_MPI_REAL    MPI_FLOAT
 +#define GMX_REAL_EPS    GMX_FLOAT_EPS
 +#define GMX_REAL_MIN    GMX_FLOAT_MIN
 +#define GMX_REAL_MAX    GMX_FLOAT_MAX
 +#define gmx_real_fullprecision_pfmt "%14.7e"
 +
 +#endif /* GMX_DOUBLE */
 +
 +#endif
index 88c78dc9be381fbf3cde0db6ae2127b585800d4f,b7dab3cf200677fa778e29ec6b4e3906ce302b8e..c8b4db19d5d8f3208ff92c3acd520d3f11e4effb
  #include <config.h>
  #endif
  
 +#include <stdlib.h>
 +
  #include "typedefs.h"
 -#include "gromacs/utility/smalloc.h"
 -#include "sysstuff.h"
 -#include "vec.h"
 +#include "gromacs/math/vec.h"
  #include "vcm.h"
  #include "mdebin.h"
  #include "nrnb.h"
  #include "calcmu.h"
 -#include "index.h"
  #include "vsite.h"
  #include "update.h"
  #include "ns.h"
@@@ -53,6 -54,8 +53,6 @@@
  #include "md_support.h"
  #include "md_logging.h"
  #include "network.h"
 -#include "xvgr.h"
 -#include "physics.h"
  #include "names.h"
  #include "force.h"
  #include "disre.h"
  #include "qmmm.h"
  #include "domdec.h"
  #include "domdec_network.h"
 -#include "gromacs/gmxlib/topsort.h"
  #include "coulomb.h"
  #include "constr.h"
  #include "shellfc.h"
  #include "gromacs/gmxpreprocess/compute_io.h"
  #include "checkpoint.h"
 -#include "mtop_util.h"
 +#include "gromacs/topology/mtop_util.h"
  #include "sighandler.h"
  #include "txtdump.h"
  #include "gromacs/utility/cstringutil.h"
  #include "types/iteratedconstraints.h"
  #include "nbnxn_cuda_data_mgmt.h"
  
 -#include "gromacs/utility/gmxmpi.h"
  #include "gromacs/fileio/confio.h"
 +#include "gromacs/fileio/mdoutf.h"
  #include "gromacs/fileio/trajectory_writing.h"
  #include "gromacs/fileio/trnio.h"
  #include "gromacs/fileio/trxio.h"
  #include "gromacs/fileio/xtcio.h"
 -#include "gromacs/timing/wallcycle.h"
 -#include "gromacs/timing/walltime_accounting.h"
 +#include "gromacs/imd/imd.h"
 +#include "gromacs/pbcutil/mshift.h"
 +#include "gromacs/pbcutil/pbc.h"
  #include "gromacs/pulling/pull.h"
  #include "gromacs/swap/swapcoords.h"
 -#include "gromacs/imd/imd.h"
 +#include "gromacs/timing/wallcycle.h"
 +#include "gromacs/timing/walltime_accounting.h"
 +#include "gromacs/utility/gmxmpi.h"
 +#include "gromacs/utility/smalloc.h"
  
  #ifdef GMX_FAHCORE
  #include "corewrap.h"
@@@ -170,7 -170,7 +170,7 @@@ double do_md(FILE *fplog, t_commrec *cr
      rvec              mu_tot;
      t_vcm            *vcm;
      t_state          *bufstate = NULL;
 -    matrix           *scale_tot, pcoupl_mu, M, ebox;
 +    matrix            pcoupl_mu, M;
      gmx_nlheur_t      nlh;
      t_trxframe        rerun_fr;
      gmx_repl_ex_t     repl_ex = NULL;
      gmx_ekindata_t   *ekind, *ekind_save;
      gmx_shellfc_t     shellfc;
      int               count, nconverged = 0;
 -    real              timestep   = 0;
 -    double            tcount     = 0;
 -    gmx_bool          bConverged = TRUE, bOK, bSumEkinhOld, bDoReplEx, bExchanged, bNeedRepartition;
 -    gmx_bool          bAppend;
 +    double            tcount                 = 0;
-     gmx_bool          bConverged             = TRUE, bOK, bSumEkinhOld, bExchanged, bNeedRepartition;
++    gmx_bool          bConverged             = TRUE, bOK, bSumEkinhOld, bDoReplEx, bExchanged, bNeedRepartition;
      gmx_bool          bResetCountersHalfMaxH = FALSE;
      gmx_bool          bVV, bIterativeCase, bFirstIterate, bTemp, bPres, bTrotter;
      gmx_bool          bUpdateDoLR;
      double            cycles;
      real              saved_conserved_quantity = 0;
      real              last_ekin                = 0;
 -    int               iter_i;
      t_extmass         MassQ;
      int             **trotter_seq;
      char              sbuf[STEPSTRSIZE], sbuf2[STEPSTRSIZE];
  
      /* Check for special mdrun options */
      bRerunMD = (Flags & MD_RERUN);
 -    bAppend  = (Flags & MD_APPENDFILES);
      if (Flags & MD_RESETCOUNTERSHALFWAY)
      {
          if (ir->nsteps > 0)
          set_constraints(constr, top, ir, mdatoms, cr);
      }
  
-     if (repl_ex_nst > 0)
-     {
-         /* We need to be sure replica exchange can only occur
-          * when the energies are current */
-         check_nst_param(fplog, cr, "nstcalcenergy", ir->nstcalcenergy,
-                         "repl_ex_nst", &repl_ex_nst);
-         /* This check needs to happen before inter-simulation
-          * signals are initialized, too */
-     }
      if (repl_ex_nst > 0 && MASTER(cr))
      {
          repl_ex = init_replica_exchange(fplog, cr->ms, state_global, ir,
      bStateFromTPX    = !bStateFromCP;
      bInitStep        = bFirstStep && (bStateFromTPX || bVV);
      bStartingFromCpt = (Flags & MD_STARTFROMCPT) && bInitStep;
 -    bLastStep        = FALSE;
      bSumEkinhOld     = FALSE;
 -    bDoReplEx        = FALSE;
      bExchanged       = FALSE;
      bNeedRepartition = FALSE;
  
      step     = ir->init_step;
      step_rel = 0;
  
 -    if (ir->nstlist == -1)
 -    {
 -        init_nlistheuristics(&nlh, bGStatEveryStep, step);
 -    }
 +    init_nlistheuristics(&nlh, bGStatEveryStep, step);
  
      if (MULTISIM(cr) && (repl_ex_nst <= 0 ))
      {
                              && (ir->bExpanded) && (step > 0) && (!bStartingFromCpt));
          }
  
+         bDoReplEx = ((repl_ex_nst > 0) && (step > 0) && !bLastStep &&
+                      do_per_step(step, repl_ex_nst));
          if (bSimAnn)
          {
              update_annealing_target_temp(&(ir->opts), t);
  
          do_ene = (do_per_step(step, ir->nstenergy) || bLastStep);
  
-         if (do_ene || do_log)
+         if (do_ene || do_log || bDoReplEx)
          {
              bCalcVir  = TRUE;
              bCalcEner = TRUE;
  
          /* Replica exchange */
          bExchanged = FALSE;
-         if ((repl_ex_nst > 0) && (step > 0) && !bLastStep &&
-             do_per_step(step, repl_ex_nst))
+         if (bDoReplEx)
          {
              bExchanged = replica_exchange(fplog, cr, repl_ex,
                                            state_global, enerd,
index 480820b9814ed8882ca656761d8e04031615f87e,8c56da42d3d41549f78500923a89983cc6886ef1..b3238d39c8f9db46b571f6aca34c90a992092352
  #include <config.h>
  #endif
  
 -#include "sysstuff.h"
 +#include <stdlib.h>
 +
  #include "macros.h"
  #include "xutil.h"
  #include "Xstuff.h"
 -#include "gromacs/utility/smalloc.h"
  #include "copyrite.h"
  #include "logo.h"
  
 +#include "gromacs/utility/real.h"
 +#include "gromacs/utility/smalloc.h"
 +
  typedef struct {
      int            x, y, rad;
      unsigned long *col;
@@@ -114,6 -111,7 +114,6 @@@ static bool LogoCallBack(t_x11 *x11, XE
      };
  #define NMESS asize(Mess)
      int             i;
 -    real            wfac, hfac;
      t_logo         *logo;
      t_windata      *wd;
  
      wd   = &(logo->wd);
      if (bFirst)
      {
 -        wfac = wd->width/110.0;
 -        hfac = wd->height/110.0;
 +        const real wfac = wd->width/110.0;
 +        const real hfac = wd->height/110.0;
          for (i = 0; (i < asize(c)); i++)
          {
              c[i].x *= wfac;
@@@ -201,7 -199,7 +201,7 @@@ t_logo *init_logo(t_x11 *x11, Window pa
      logo->bQuitOnClick = bQuitOnClick;
      InitWin(&logo->wd, 0, 0, 360, 270, 1, "GROMACS");
      bg = LIGHTGREY;
-     if ((newcol = getenv("LOGO")) != NULL)
+     if ((newcol = getenv("GMX_LOGO_COLOR")) != NULL)
      {
          GetNamedColor(x11, newcol, &bg);
      }
index eb2608b85d7e2886791f275e979d2740a0505115,14ac665f03b647edb23585bbf05c0a6a8625d16d..1ebe3ce51e865dfc5ce888f27bae5e07162989ae
  #include <config.h>
  #endif
  
 +#include <stdlib.h>
  #include <string.h>
 +
  #include "typedefs.h"
 -#include "sysstuff.h"
  #include "gromacs/utility/smalloc.h"
  #include "Xstuff.h"
  #include "x11.h"
@@@ -323,7 -322,7 +323,7 @@@ t_x11 *GetX11(int *argc, char *argv[]
      title = strdup(argv[0]);
  
      /* First check environment */
-     fontname = getenv("GMXFONT");
+     fontname = getenv("GMX_FONT");
      display  = getenv("DISPLAY");
  
      snew(ARGV, *argc);