Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / gmxlib / network.c
index 5cdd13419865cfdce40eeded7840db896c4357fc..94905661e1c4b89bc11b4cc88c76f18b043f9d62 100644 (file)
-/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
- * 
- *                This source code is part of
- * 
- *                 G   R   O   M   A   C   S
- * 
- *          GROningen MAchine for Chemical Simulations
- * 
- *                        VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+/*
+ * 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,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
- * 
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
- * 
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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 papers on the package - you can find them in the top README file.
- * 
- * For more info, check our website at http://www.gromacs.org
- * 
- * And Hey:
- * GROningen Mixture of Alchemy and Childrens' Stories
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
-#include <string.h>
-#include "gmx_fatal.h"
-#include "main.h"
-#include "smalloc.h"
-#include "network.h"
-#include "copyrite.h"
-#include "statutil.h"
-#include <ctype.h>
-#include "macros.h"
+#include "gromacs/legacyheaders/network.h"
 
-#ifdef GMX_LIB_MPI
-#include <mpi.h>
-#endif
-
-#ifdef GMX_THREAD_MPI
-#include "tmpi.h"
-#endif
+#include "config.h"
 
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
 
-/* The source code in this file should be thread-safe. 
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/types/commrec.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)
+void gmx_fill_commrec_from_mpi(t_commrec gmx_unused *cr)
 {
-  int n;
 #ifndef GMX_MPI
-  return 0;
+    gmx_call("gmx_fill_commrec_from_mpi");
 #else
-  MPI_Initialized(&n);
-  
-  return n;
+    if (!gmx_mpi_initialized())
+    {
+        gmx_comm("MPI has not been initialized properly");
+    }
+
+    cr->nnodes           = gmx_node_num();
+    cr->nodeid           = gmx_node_rank();
+    cr->sim_nodeid       = cr->nodeid;
+    cr->mpi_comm_mysim   = MPI_COMM_WORLD;
+    cr->mpi_comm_mygroup = MPI_COMM_WORLD;
+
 #endif
 }
 
-int gmx_setup(int *argc,char **argv,int *nnodes)
+t_commrec *init_commrec()
 {
-#ifndef GMX_MPI
-  gmx_call("gmx_setup");
-  return 0;
-#else
-  char   buf[256];
-  int    resultlen;               /* actual length of node name      */
-  int    i,flag;
-  int  mpi_num_nodes;
-  int  mpi_my_rank;
-  char mpi_hostname[MPI_MAX_PROCESSOR_NAME];
-
-  /* Call the MPI routines */
+    t_commrec    *cr;
+
+    snew(cr, 1);
+
 #ifdef GMX_LIB_MPI
-#ifdef GMX_FAHCORE
-  (void) fah_MPI_Init(argc,&argv);
+    gmx_fill_commrec_from_mpi(cr);
 #else
-  (void) MPI_Init(argc,&argv);
-#endif
-#endif
-  (void) MPI_Comm_size( MPI_COMM_WORLD, &mpi_num_nodes );
-  (void) MPI_Comm_rank( MPI_COMM_WORLD, &mpi_my_rank );
-  (void) MPI_Get_processor_name( mpi_hostname, &resultlen );
-#ifdef GMX_LIB_MPI 
-  fprintf(stderr,"NNODES=%d, MYRANK=%d, HOSTNAME=%s\n",
-         mpi_num_nodes,mpi_my_rank,mpi_hostname);
-#endif
-  
-  *nnodes=mpi_num_nodes;
-  
-  return mpi_my_rank;
-#endif
+    cr->mpi_comm_mysim   = NULL;
+    cr->mpi_comm_mygroup = NULL;
+    cr->nnodes           = 1;
+    cr->sim_nodeid       = 0;
+    cr->nodeid           = cr->sim_nodeid;
+#endif
+
+    // TODO cr->duty should not be initialized here
+    cr->duty = (DUTY_PP | DUTY_PME);
+
+#if defined GMX_MPI && !defined MPI_IN_PLACE_EXISTS
+    /* initialize the MPI_IN_PLACE replacement buffers */
+    snew(cr->mpb, 1);
+    cr->mpb->ibuf        = NULL;
+    cr->mpb->libuf       = NULL;
+    cr->mpb->fbuf        = NULL;
+    cr->mpb->dbuf        = NULL;
+    cr->mpb->ibuf_alloc  = 0;
+    cr->mpb->libuf_alloc = 0;
+    cr->mpb->fbuf_alloc  = 0;
+    cr->mpb->dbuf_alloc  = 0;
+#endif
+
+    return cr;
 }
 
-int  gmx_node_num(void)
+t_commrec *reinitialize_commrec_for_this_thread(const t_commrec gmx_unused *cro)
 {
-#ifndef GMX_MPI
-  return 1;
-#else
-  int i;
-  (void) MPI_Comm_size(MPI_COMM_WORLD, &i);
-  return i;
-#endif
-}
+#ifdef GMX_THREAD_MPI
+    t_commrec *cr;
 
-int gmx_node_rank(void)
-{
-#ifndef GMX_MPI
-  return 0;
-#else
-  int i;
-  (void) MPI_Comm_rank(MPI_COMM_WORLD, &i);
-  return i;
-#endif
-}
+    /* make a thread-specific commrec */
+    snew(cr, 1);
+    /* now copy the whole thing, so settings like the number of PME nodes
+       get propagated. */
+    *cr = *cro;
 
+    /* and we start setting our own thread-specific values for things */
+    gmx_fill_commrec_from_mpi(cr);
 
-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;
+    // TODO cr->duty should not be initialized here
+    cr->duty             = (DUTY_PP | DUTY_PME);
+
+    return cr;
 #else
-  int  resultlen,hostnum,i,j;
-  char mpi_hostname[MPI_MAX_PROCESSOR_NAME],hostnum_str[MPI_MAX_PROCESSOR_NAME];
-
-  MPI_Get_processor_name(mpi_hostname,&resultlen);
-  /* 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 (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 = strtol(hostnum_str + max(0,j-9), NULL, 10);
-  }
-
-  if (debug) {
-    fprintf(debug,"In gmx_setup_nodecomm: hostname '%s', hostnum %d\n",
-        mpi_hostname,hostnum);
-  }
-  return hostnum;
-#endif
+    return NULL;
 #endif
 }
 
-void gmx_setup_nodecomm(FILE *fplog,t_commrec *cr)
+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)
@@ -195,37 +156,37 @@ void gmx_setup_nodecomm(FILE *fplog,t_commrec *cr)
     nc->bUse = FALSE;
 #ifndef GMX_THREAD_MPI
 #ifdef GMX_MPI
-    MPI_Comm_size(cr->mpi_comm_mygroup,&n);
-    MPI_Comm_rank(cr->mpi_comm_mygroup,&rank);
+    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)
     {
-        fprintf(debug,"In gmx_setup_nodecomm: splitting communicator of size %d\n",n);
+        fprintf(debug, "In gmx_setup_nodecomm: splitting communicator of size %d\n", n);
     }
 
 
     /* The intra-node communicator, split on node number */
-    MPI_Comm_split(cr->mpi_comm_mygroup,hostnum,rank,&nc->comm_intra);
-    MPI_Comm_rank(nc->comm_intra,&nc->rank_intra);
+    MPI_Comm_split(cr->mpi_comm_mygroup, nodehash, rank, &nc->comm_intra);
+    MPI_Comm_rank(nc->comm_intra, &nc->rank_intra);
     if (debug)
     {
-        fprintf(debug,"In gmx_setup_nodecomm: node rank %d rank_intra %d\n",
-                rank,nc->rank_intra);
+        fprintf(debug, "In gmx_setup_nodecomm: node ID %d rank within node %d\n",
+                rank, nc->rank_intra);
     }
     /* The inter-node communicator, split on rank_intra.
      * We actually only need the one for rank=0,
      * but it is easier to create them all.
      */
-    MPI_Comm_split(cr->mpi_comm_mygroup,nc->rank_intra,rank,&nc->comm_inter);
+    MPI_Comm_split(cr->mpi_comm_mygroup, nc->rank_intra, rank, &nc->comm_inter);
     /* Check if this really created two step communication */
-    MPI_Comm_size(nc->comm_inter,&ng);
-    MPI_Comm_size(nc->comm_intra,&ni);
+    MPI_Comm_size(nc->comm_inter, &ng);
+    MPI_Comm_size(nc->comm_intra, &ni);
     if (debug)
     {
-        fprintf(debug,"In gmx_setup_nodecomm: groups %d, my group size %d\n",
-                ng,ni);
+        fprintf(debug, "In gmx_setup_nodecomm: groups %d, my group size %d\n",
+                ng, ni);
     }
 
     if (getenv("GMX_NO_NODECOMM") == NULL &&
@@ -234,8 +195,8 @@ void gmx_setup_nodecomm(FILE *fplog,t_commrec *cr)
         nc->bUse = TRUE;
         if (fplog)
         {
-            fprintf(fplog,"Using two step summing over %d groups of on average %.1f processes\n\n",
-                    ng,(real)n/(real)ng);
+            fprintf(fplog, "Using two step summing over %d groups of on average %.1f ranks\n\n",
+                    ng, (real)n/(real)ng);
         }
         if (nc->rank_intra > 0)
         {
@@ -249,7 +210,7 @@ void gmx_setup_nodecomm(FILE *fplog,t_commrec *cr)
         MPI_Comm_free(&nc->comm_intra);
         if (debug)
         {
-            fprintf(debug,"In gmx_setup_nodecomm: not unsing separate inter- and intra-node communicators.\n");
+            fprintf(debug, "In gmx_setup_nodecomm: not unsing separate inter- and intra-node communicators.\n");
         }
     }
 #endif
@@ -259,72 +220,67 @@ void gmx_setup_nodecomm(FILE *fplog,t_commrec *cr)
 #endif
 }
 
-void gmx_init_intra_counters(t_commrec *cr)
+void gmx_init_intranode_counters(t_commrec *cr)
 {
-    /* counters for PP+PME and PP-only processes on my node */
-    int nnodes, nnodes_pp, id_mynode=-1, id_mynode_group=-1, nproc_mynode, nproc_mynode_pp;
+    /* counters for PP+PME and PP-only processes on my physical node */
+    int nrank_intranode, rank_intranode;
+    int nrank_pp_intranode, rank_pp_intranode;
+    /* thread-MPI is not initialized when not running in parallel */
 #if defined GMX_MPI && !defined GMX_THREAD_MPI
-    int i, mynum, *num, *num_s, *num_pp, *num_pp_s;
-#endif
+    int nrank_world, rank_world;
+    int i, myhash, *hash, *hash_s, *hash_pp, *hash_pp_s;
 
-    nnodes    = cr->nnodes;
-    nnodes_pp = nnodes - cr->npmenodes;
+    MPI_Comm_size(MPI_COMM_WORLD, &nrank_world);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank_world);
 
-#if defined GMX_MPI && !defined GMX_THREAD_MPI
-    /* We have MPI and can expect to have different compute 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,   nnodes);
-    snew(num_s, nnodes);
-    snew(num_pp,   nnodes_pp);
-    snew(num_pp_s, nnodes_pp);
-
-    num_s[cr->sim_nodeid] = mynum;
-    if (cr->duty & DUTY_PP)
-    {
-        num_pp_s[cr->nodeid] = mynum;
-    }
-
-    MPI_Allreduce(num_s, num, nnodes, MPI_INT, MPI_SUM, cr->mpi_comm_mysim);
-    MPI_Allreduce(num_pp_s, num_pp, nnodes_pp, MPI_INT, MPI_SUM, cr->mpi_comm_mygroup);
-
-    id_mynode       = 0;
-    id_mynode_group = 0;
-    nproc_mynode    = 0;
-    nproc_mynode_pp = 0;
-    for(i=0; i<nnodes; i++)
+    snew(hash,   nrank_world);
+    snew(hash_s, nrank_world);
+    snew(hash_pp,   nrank_world);
+    snew(hash_pp_s, nrank_world);
+
+    hash_s[rank_world]    = myhash;
+    hash_pp_s[rank_world] = (cr->duty & DUTY_PP) ? myhash : -1;
+
+    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;
+    nrank_pp_intranode = 0;
+    rank_pp_intranode  = 0;
+    for (i = 0; i < nrank_world; i++)
     {
-        if (num[i] == mynum)
+        if (hash[i] == myhash)
         {
-            nproc_mynode++;
-            if (i < cr->sim_nodeid)
+            nrank_intranode++;
+            if (i < rank_world)
             {
-                id_mynode++;
-            }
-            if (i < cr->nodeid)
-            {
-                id_mynode_group++;
+                rank_intranode++;
             }
         }
-    }
-    for(i=0; i<nnodes_pp; i++)
-    {
-        if (num_pp[i] == mynum)
+        if (hash_pp[i] == myhash)
         {
-            nproc_mynode_pp++;
+            nrank_pp_intranode++;
+            if ((cr->duty & DUTY_PP) && i < rank_world)
+            {
+                rank_pp_intranode++;
+            }
         }
     }
-    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 are running within a node */
-    id_mynode       = cr->sim_nodeid;
-    id_mynode_group = cr->nodeid;
-    nproc_mynode    = cr->nnodes;
-    nproc_mynode_pp = cr->nnodes - cr->npmenodes;
+    /* Serial or thread-MPI code: we run within a single physical node */
+    nrank_intranode    = cr->nnodes;
+    rank_intranode     = cr->sim_nodeid;
+    nrank_pp_intranode = cr->nnodes - cr->npmenodes;
+    rank_pp_intranode  = cr->nodeid;
 #endif
 
     if (debug)
@@ -338,281 +294,288 @@ void gmx_init_intra_counters(t_commrec *cr)
         {
             sprintf(sbuf, "%s", cr->duty & DUTY_PP ? "PP" : "PME");
         }
-        fprintf(debug, "On %3s node %d: nodeid_intra=%d, nodeid_group_intra=%d, "
-                "nnodes_intra=%d, nnodes_pp_intra=%d\n", sbuf, cr->sim_nodeid,
-                id_mynode, id_mynode_group, nproc_mynode, nproc_mynode_pp);
+        fprintf(debug, "On %3s rank %d: nrank_intranode=%d, rank_intranode=%d, "
+                "nrank_pp_intranode=%d, rank_pp_intranode=%d\n",
+                sbuf, cr->sim_nodeid,
+                nrank_intranode, rank_intranode,
+                nrank_pp_intranode, rank_pp_intranode);
     }
 
-    cr->nodeid_intra        = id_mynode;
-    cr->nodeid_group_intra  = id_mynode_group;
-    cr->nnodes_intra        = nproc_mynode;
-    cr->nnodes_pp_intra     = nproc_mynode_pp;
+    cr->nrank_intranode    = nrank_intranode;
+    cr->rank_intranode     = rank_intranode;
+    cr->nrank_pp_intranode = nrank_pp_intranode;
+    cr->rank_pp_intranode  = rank_pp_intranode;
 }
 
 
-void gmx_barrier(const t_commrec *cr)
+void gmx_barrier(const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
-  gmx_call("gmx_barrier");
+    gmx_call("gmx_barrier");
 #else
-  MPI_Barrier(cr->mpi_comm_mygroup);
+    MPI_Barrier(cr->mpi_comm_mygroup);
 #endif
 }
 
-void gmx_abort(int noderank,int nnodes,int errorno)
+void gmx_bcast(int gmx_unused nbytes, void gmx_unused *b, const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
-  gmx_call("gmx_abort");
+    gmx_call("gmx_bast");
 #else
-#ifdef GMX_THREAD_MPI
-  fprintf(stderr,"Halting program %s\n",ShortProgram());
-  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());
-  }
-
-  thanx(stderr);
-  MPI_Abort(MPI_COMM_WORLD,errorno);
-  exit(1);
-#endif
+    MPI_Bcast(b, nbytes, MPI_BYTE, MASTERRANK(cr), cr->mpi_comm_mygroup);
 #endif
 }
 
-void gmx_bcast(int nbytes,void *b,const t_commrec *cr)
+void gmx_bcast_sim(int gmx_unused nbytes, void gmx_unused *b, const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
-  gmx_call("gmx_bast");
+    gmx_call("gmx_bast");
 #else
-  MPI_Bcast(b,nbytes,MPI_BYTE,MASTERRANK(cr),cr->mpi_comm_mygroup);
+    MPI_Bcast(b, nbytes, MPI_BYTE, MASTERRANK(cr), cr->mpi_comm_mysim);
 #endif
 }
 
-void gmx_bcast_sim(int nbytes,void *b,const t_commrec *cr)
-{
-#ifndef GMX_MPI
-  gmx_call("gmx_bast");
-#else
-  MPI_Bcast(b,nbytes,MPI_BYTE,MASTERRANK(cr),cr->mpi_comm_mysim);
-#endif
-}
-
-void gmx_sumd(int nr,double r[],const t_commrec *cr)
+void gmx_sumd(int gmx_unused nr, double gmx_unused r[], const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
     gmx_call("gmx_sumd");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    if (cr->nc.bUse) {
+#if defined(MPI_IN_PLACE_EXISTS)
+    if (cr->nc.bUse)
+    {
         if (cr->nc.rank_intra == 0)
         {
             /* Use two step summing. */
-            MPI_Reduce(MPI_IN_PLACE,r,nr,MPI_DOUBLE,MPI_SUM,0,
+            MPI_Reduce(MPI_IN_PLACE, r, nr, MPI_DOUBLE, MPI_SUM, 0,
                        cr->nc.comm_intra);
             /* Sum the roots of the internal (intra) buffers. */
-            MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_DOUBLE,MPI_SUM,
+            MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_DOUBLE, MPI_SUM,
                           cr->nc.comm_inter);
         }
         else
         {
             /* This is here because of the silly MPI specification
                 that MPI_IN_PLACE should be put in sendbuf instead of recvbuf */
-            MPI_Reduce(r,NULL,nr,MPI_DOUBLE,MPI_SUM,0,cr->nc.comm_intra);
+            MPI_Reduce(r, NULL, nr, MPI_DOUBLE, MPI_SUM, 0, cr->nc.comm_intra);
         }
-        MPI_Bcast(r,nr,MPI_DOUBLE,0,cr->nc.comm_intra);
-    } 
-    else 
+        MPI_Bcast(r, nr, MPI_DOUBLE, 0, cr->nc.comm_intra);
+    }
+    else
     {
-        MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_DOUBLE,MPI_SUM, 
+        MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_DOUBLE, MPI_SUM,
                       cr->mpi_comm_mygroup);
     }
 #else
     int i;
 
-    if (nr > cr->mpb->dbuf_alloc) {
+    if (nr > cr->mpb->dbuf_alloc)
+    {
         cr->mpb->dbuf_alloc = nr;
-        srenew(cr->mpb->dbuf,cr->mpb->dbuf_alloc);
+        srenew(cr->mpb->dbuf, cr->mpb->dbuf_alloc);
     }
-    if (cr->nc.bUse) {
+    if (cr->nc.bUse)
+    {
         /* Use two step summing */
-        MPI_Allreduce(r,cr->mpb->dbuf,nr,MPI_DOUBLE,MPI_SUM,cr->nc.comm_intra);
-        if (cr->nc.rank_intra == 0) {
+        MPI_Allreduce(r, cr->mpb->dbuf, nr, MPI_DOUBLE, MPI_SUM, cr->nc.comm_intra);
+        if (cr->nc.rank_intra == 0)
+        {
             /* Sum with the buffers reversed */
-            MPI_Allreduce(cr->mpb->dbuf,r,nr,MPI_DOUBLE,MPI_SUM, 
+            MPI_Allreduce(cr->mpb->dbuf, r, nr, MPI_DOUBLE, MPI_SUM,
                           cr->nc.comm_inter);
         }
-        MPI_Bcast(r,nr,MPI_DOUBLE,0,cr->nc.comm_intra);
-    } else {
-        MPI_Allreduce(r,cr->mpb->dbuf,nr,MPI_DOUBLE,MPI_SUM,
+        MPI_Bcast(r, nr, MPI_DOUBLE, 0, cr->nc.comm_intra);
+    }
+    else
+    {
+        MPI_Allreduce(r, cr->mpb->dbuf, nr, MPI_DOUBLE, MPI_SUM,
                       cr->mpi_comm_mygroup);
-        for(i=0; i<nr; i++)
+        for (i = 0; i < nr; i++)
+        {
             r[i] = cr->mpb->dbuf[i];
+        }
     }
 #endif
 #endif
 }
 
-void gmx_sumf(int nr,float r[],const t_commrec *cr)
+void gmx_sumf(int gmx_unused nr, float gmx_unused r[], const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
     gmx_call("gmx_sumf");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    if (cr->nc.bUse) {
+#if defined(MPI_IN_PLACE_EXISTS)
+    if (cr->nc.bUse)
+    {
         /* Use two step summing.  */
         if (cr->nc.rank_intra == 0)
         {
-            MPI_Reduce(MPI_IN_PLACE,r,nr,MPI_FLOAT,MPI_SUM,0,
+            MPI_Reduce(MPI_IN_PLACE, r, nr, MPI_FLOAT, MPI_SUM, 0,
                        cr->nc.comm_intra);
             /* Sum the roots of the internal (intra) buffers */
-            MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_FLOAT,MPI_SUM,
+            MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_FLOAT, MPI_SUM,
                           cr->nc.comm_inter);
         }
         else
         {
             /* This is here because of the silly MPI specification
                 that MPI_IN_PLACE should be put in sendbuf instead of recvbuf */
-            MPI_Reduce(r,NULL,nr,MPI_FLOAT,MPI_SUM,0,cr->nc.comm_intra);
+            MPI_Reduce(r, NULL, nr, MPI_FLOAT, MPI_SUM, 0, cr->nc.comm_intra);
         }
-        MPI_Bcast(r,nr,MPI_FLOAT,0,cr->nc.comm_intra);
-    } 
-    else 
+        MPI_Bcast(r, nr, MPI_FLOAT, 0, cr->nc.comm_intra);
+    }
+    else
     {
-        MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_FLOAT,MPI_SUM,cr->mpi_comm_mygroup);
+        MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_FLOAT, MPI_SUM, cr->mpi_comm_mygroup);
     }
 #else
     int i;
 
-    if (nr > cr->mpb->fbuf_alloc) {
+    if (nr > cr->mpb->fbuf_alloc)
+    {
         cr->mpb->fbuf_alloc = nr;
-        srenew(cr->mpb->fbuf,cr->mpb->fbuf_alloc);
+        srenew(cr->mpb->fbuf, cr->mpb->fbuf_alloc);
     }
-    if (cr->nc.bUse) {
+    if (cr->nc.bUse)
+    {
         /* Use two step summing */
-        MPI_Allreduce(r,cr->mpb->fbuf,nr,MPI_FLOAT,MPI_SUM,cr->nc.comm_intra);
-        if (cr->nc.rank_intra == 0) {
+        MPI_Allreduce(r, cr->mpb->fbuf, nr, MPI_FLOAT, MPI_SUM, cr->nc.comm_intra);
+        if (cr->nc.rank_intra == 0)
+        {
             /* Sum with the buffers reversed */
-            MPI_Allreduce(cr->mpb->fbuf,r,nr,MPI_FLOAT,MPI_SUM, 
+            MPI_Allreduce(cr->mpb->fbuf, r, nr, MPI_FLOAT, MPI_SUM,
                           cr->nc.comm_inter);
         }
-        MPI_Bcast(r,nr,MPI_FLOAT,0,cr->nc.comm_intra);
-    } else {
-        MPI_Allreduce(r,cr->mpb->fbuf,nr,MPI_FLOAT,MPI_SUM,
+        MPI_Bcast(r, nr, MPI_FLOAT, 0, cr->nc.comm_intra);
+    }
+    else
+    {
+        MPI_Allreduce(r, cr->mpb->fbuf, nr, MPI_FLOAT, MPI_SUM,
                       cr->mpi_comm_mygroup);
-        for(i=0; i<nr; i++)
+        for (i = 0; i < nr; i++)
+        {
             r[i] = cr->mpb->fbuf[i];
+        }
     }
 #endif
 #endif
 }
 
-void gmx_sumi(int nr,int r[],const t_commrec *cr)
+void gmx_sumi(int gmx_unused nr, int gmx_unused r[], const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
     gmx_call("gmx_sumi");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    if (cr->nc.bUse) {
+#if defined(MPI_IN_PLACE_EXISTS)
+    if (cr->nc.bUse)
+    {
         /* Use two step summing */
-        if (cr->nc.rank_intra == 0) 
+        if (cr->nc.rank_intra == 0)
         {
-            MPI_Reduce(MPI_IN_PLACE,r,nr,MPI_INT,MPI_SUM,0,cr->nc.comm_intra);
+            MPI_Reduce(MPI_IN_PLACE, r, nr, MPI_INT, MPI_SUM, 0, cr->nc.comm_intra);
             /* Sum with the buffers reversed */
-            MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_INT,MPI_SUM,cr->nc.comm_inter);
+            MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT, MPI_SUM, cr->nc.comm_inter);
         }
         else
         {
             /* This is here because of the silly MPI specification
                 that MPI_IN_PLACE should be put in sendbuf instead of recvbuf */
-            MPI_Reduce(r,NULL,nr,MPI_INT,MPI_SUM,0,cr->nc.comm_intra);
+            MPI_Reduce(r, NULL, nr, MPI_INT, MPI_SUM, 0, cr->nc.comm_intra);
         }
-        MPI_Bcast(r,nr,MPI_INT,0,cr->nc.comm_intra);
-    } 
-    else 
+        MPI_Bcast(r, nr, MPI_INT, 0, cr->nc.comm_intra);
+    }
+    else
     {
-        MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_INT,MPI_SUM,cr->mpi_comm_mygroup);
+        MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT, MPI_SUM, cr->mpi_comm_mygroup);
     }
 #else
     int i;
 
-    if (nr > cr->mpb->ibuf_alloc) {
+    if (nr > cr->mpb->ibuf_alloc)
+    {
         cr->mpb->ibuf_alloc = nr;
-        srenew(cr->mpb->ibuf,cr->mpb->ibuf_alloc);
+        srenew(cr->mpb->ibuf, cr->mpb->ibuf_alloc);
     }
-    if (cr->nc.bUse) {
+    if (cr->nc.bUse)
+    {
         /* Use two step summing */
-        MPI_Allreduce(r,cr->mpb->ibuf,nr,MPI_INT,MPI_SUM,cr->nc.comm_intra);
-        if (cr->nc.rank_intra == 0) {
+        MPI_Allreduce(r, cr->mpb->ibuf, nr, MPI_INT, MPI_SUM, cr->nc.comm_intra);
+        if (cr->nc.rank_intra == 0)
+        {
             /* Sum with the buffers reversed */
-            MPI_Allreduce(cr->mpb->ibuf,r,nr,MPI_INT,MPI_SUM,cr->nc.comm_inter);
+            MPI_Allreduce(cr->mpb->ibuf, r, nr, MPI_INT, MPI_SUM, cr->nc.comm_inter);
         }
-        MPI_Bcast(r,nr,MPI_INT,0,cr->nc.comm_intra);
-    } else {
-        MPI_Allreduce(r,cr->mpb->ibuf,nr,MPI_INT,MPI_SUM,cr->mpi_comm_mygroup);
-        for(i=0; i<nr; i++)
+        MPI_Bcast(r, nr, MPI_INT, 0, cr->nc.comm_intra);
+    }
+    else
+    {
+        MPI_Allreduce(r, cr->mpb->ibuf, nr, MPI_INT, MPI_SUM, cr->mpi_comm_mygroup);
+        for (i = 0; i < nr; i++)
+        {
             r[i] = cr->mpb->ibuf[i];
+        }
     }
 #endif
 #endif
 }
 
-void gmx_sumli(int nr,gmx_large_int_t r[],const t_commrec *cr)
+void gmx_sumli(int gmx_unused nr, gmx_int64_t gmx_unused r[], const t_commrec gmx_unused *cr)
 {
 #ifndef GMX_MPI
     gmx_call("gmx_sumli");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    if (cr->nc.bUse) {
+#if defined(MPI_IN_PLACE_EXISTS)
+    if (cr->nc.bUse)
+    {
         /* Use two step summing */
-        if (cr->nc.rank_intra == 0) 
+        if (cr->nc.rank_intra == 0)
         {
-            MPI_Reduce(MPI_IN_PLACE,r,nr,GMX_MPI_LARGE_INT,MPI_SUM,0,
+            MPI_Reduce(MPI_IN_PLACE, r, nr, MPI_INT64_T, MPI_SUM, 0,
                        cr->nc.comm_intra);
             /* Sum with the buffers reversed */
-            MPI_Allreduce(MPI_IN_PLACE,r,nr,GMX_MPI_LARGE_INT,MPI_SUM,
+            MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT64_T, MPI_SUM,
                           cr->nc.comm_inter);
         }
         else
         {
             /* This is here because of the silly MPI specification
                 that MPI_IN_PLACE should be put in sendbuf instead of recvbuf */
-            MPI_Reduce(r,NULL,nr,GMX_MPI_LARGE_INT,MPI_SUM,0,cr->nc.comm_intra);
+            MPI_Reduce(r, NULL, nr, MPI_INT64_T, MPI_SUM, 0, cr->nc.comm_intra);
         }
-        MPI_Bcast(r,nr,GMX_MPI_LARGE_INT,0,cr->nc.comm_intra);
-    } 
-    else 
+        MPI_Bcast(r, nr, MPI_INT64_T, 0, cr->nc.comm_intra);
+    }
+    else
     {
-        MPI_Allreduce(MPI_IN_PLACE,r,nr,GMX_MPI_LARGE_INT,MPI_SUM,cr->mpi_comm_mygroup);
+        MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT64_T, MPI_SUM, cr->mpi_comm_mygroup);
     }
 #else
     int i;
 
-    if (nr > cr->mpb->libuf_alloc) {
+    if (nr > cr->mpb->libuf_alloc)
+    {
         cr->mpb->libuf_alloc = nr;
-        srenew(cr->mpb->libuf,cr->mpb->libuf_alloc);
+        srenew(cr->mpb->libuf, cr->mpb->libuf_alloc);
     }
-    if (cr->nc.bUse) {
+    if (cr->nc.bUse)
+    {
         /* Use two step summing */
-        MPI_Allreduce(r,cr->mpb->libuf,nr,GMX_MPI_LARGE_INT,MPI_SUM,
+        MPI_Allreduce(r, cr->mpb->libuf, nr, MPI_INT64_T, MPI_SUM,
                       cr->nc.comm_intra);
-        if (cr->nc.rank_intra == 0) {
+        if (cr->nc.rank_intra == 0)
+        {
             /* Sum with the buffers reversed */
-            MPI_Allreduce(cr->mpb->libuf,r,nr,GMX_MPI_LARGE_INT,MPI_SUM,
+            MPI_Allreduce(cr->mpb->libuf, r, nr, MPI_INT64_T, MPI_SUM,
                           cr->nc.comm_inter);
         }
-        MPI_Bcast(r,nr,GMX_MPI_LARGE_INT,0,cr->nc.comm_intra);
-    } else {
-        MPI_Allreduce(r,cr->mpb->libuf,nr,GMX_MPI_LARGE_INT,MPI_SUM,
+        MPI_Bcast(r, nr, MPI_INT64_T, 0, cr->nc.comm_intra);
+    }
+    else
+    {
+        MPI_Allreduce(r, cr->mpb->libuf, nr, MPI_INT64_T, MPI_SUM,
                       cr->mpi_comm_mygroup);
-        for(i=0; i<nr; i++)
+        for (i = 0; i < nr; i++)
+        {
             r[i] = cr->mpb->libuf[i];
+        }
     }
 #endif
 #endif
@@ -621,157 +584,161 @@ void gmx_sumli(int nr,gmx_large_int_t r[],const t_commrec *cr)
 
 
 #ifdef GMX_MPI
-void gmx_sumd_comm(int nr,double r[],MPI_Comm mpi_comm)
+static void gmx_sumd_comm(int nr, double r[], MPI_Comm mpi_comm)
 {
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_DOUBLE,MPI_SUM,mpi_comm);
+#if defined(MPI_IN_PLACE_EXISTS)
+    MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_DOUBLE, MPI_SUM, mpi_comm);
 #else
     /* this function is only used in code that is not performance critical,
-       (during setup, when comm_rec is not the appropriate communication  
+       (during setup, when comm_rec is not the appropriate communication
        structure), so this isn't as bad as it looks. */
     double *buf;
-    int i;
+    int     i;
 
     snew(buf, nr);
-    MPI_Allreduce(r,buf,nr,MPI_DOUBLE,MPI_SUM,mpi_comm);
-    for(i=0; i<nr; i++)
+    MPI_Allreduce(r, buf, nr, MPI_DOUBLE, MPI_SUM, mpi_comm);
+    for (i = 0; i < nr; i++)
+    {
         r[i] = buf[i];
+    }
     sfree(buf);
 #endif
 }
 #endif
 
 #ifdef GMX_MPI
-void gmx_sumf_comm(int nr,float r[],MPI_Comm mpi_comm)
+static void gmx_sumf_comm(int nr, float r[], MPI_Comm mpi_comm)
 {
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_FLOAT,MPI_SUM,mpi_comm);
+#if defined(MPI_IN_PLACE_EXISTS)
+    MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_FLOAT, MPI_SUM, mpi_comm);
 #else
     /* this function is only used in code that is not performance critical,
-       (during setup, when comm_rec is not the appropriate communication  
+       (during setup, when comm_rec is not the appropriate communication
        structure), so this isn't as bad as it looks. */
     float *buf;
-    int i;
+    int    i;
 
     snew(buf, nr);
-    MPI_Allreduce(r,buf,nr,MPI_FLOAT,MPI_SUM,mpi_comm);
-    for(i=0; i<nr; i++)
+    MPI_Allreduce(r, buf, nr, MPI_FLOAT, MPI_SUM, mpi_comm);
+    for (i = 0; i < nr; i++)
+    {
         r[i] = buf[i];
+    }
     sfree(buf);
 #endif
 }
 #endif
 
-void gmx_sumd_sim(int nr,double r[],const gmx_multisim_t *ms)
+void gmx_sumd_sim(int gmx_unused nr, double gmx_unused r[], const gmx_multisim_t gmx_unused *ms)
 {
 #ifndef GMX_MPI
-  gmx_call("gmx_sumd_sim");
+    gmx_call("gmx_sumd_sim");
 #else
-  gmx_sumd_comm(nr,r,ms->mpi_comm_masters);
+    gmx_sumd_comm(nr, r, ms->mpi_comm_masters);
 #endif
 }
 
-void gmx_sumf_sim(int nr,float r[],const gmx_multisim_t *ms)
+void gmx_sumf_sim(int gmx_unused nr, float gmx_unused r[], const gmx_multisim_t gmx_unused *ms)
 {
 #ifndef GMX_MPI
-  gmx_call("gmx_sumf_sim");
+    gmx_call("gmx_sumf_sim");
 #else
-  gmx_sumf_comm(nr,r,ms->mpi_comm_masters);
+    gmx_sumf_comm(nr, r, ms->mpi_comm_masters);
 #endif
 }
 
-void gmx_sumi_sim(int nr,int r[], const gmx_multisim_t *ms)
+void gmx_sumi_sim(int gmx_unused nr, int gmx_unused r[], const gmx_multisim_t gmx_unused *ms)
 {
 #ifndef GMX_MPI
     gmx_call("gmx_sumi_sim");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    MPI_Allreduce(MPI_IN_PLACE,r,nr,MPI_INT,MPI_SUM,ms->mpi_comm_masters);
+#if defined(MPI_IN_PLACE_EXISTS)
+    MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT, MPI_SUM, ms->mpi_comm_masters);
 #else
     /* this is thread-unsafe, but it will do for now: */
     int i;
 
-    if (nr > ms->mpb->ibuf_alloc) {
+    if (nr > ms->mpb->ibuf_alloc)
+    {
         ms->mpb->ibuf_alloc = nr;
-        srenew(ms->mpb->ibuf,ms->mpb->ibuf_alloc);
+        srenew(ms->mpb->ibuf, ms->mpb->ibuf_alloc);
     }
-    MPI_Allreduce(r,ms->mpb->ibuf,nr,MPI_INT,MPI_SUM,ms->mpi_comm_masters);
-    for(i=0; i<nr; i++)
+    MPI_Allreduce(r, ms->mpb->ibuf, nr, MPI_INT, MPI_SUM, ms->mpi_comm_masters);
+    for (i = 0; i < nr; i++)
+    {
         r[i] = ms->mpb->ibuf[i];
+    }
 #endif
 #endif
 }
 
-void gmx_sumli_sim(int nr,gmx_large_int_t r[], const gmx_multisim_t *ms)
+void gmx_sumli_sim(int gmx_unused nr, gmx_int64_t gmx_unused r[], const gmx_multisim_t gmx_unused *ms)
 {
 #ifndef GMX_MPI
     gmx_call("gmx_sumli_sim");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
-    MPI_Allreduce(MPI_IN_PLACE,r,nr,GMX_MPI_LARGE_INT,MPI_SUM,
+#if defined(MPI_IN_PLACE_EXISTS)
+    MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT64_T, MPI_SUM,
                   ms->mpi_comm_masters);
 #else
     /* this is thread-unsafe, but it will do for now: */
     int i;
 
-    if (nr > ms->mpb->libuf_alloc) {
+    if (nr > ms->mpb->libuf_alloc)
+    {
         ms->mpb->libuf_alloc = nr;
-        srenew(ms->mpb->libuf,ms->mpb->libuf_alloc);
+        srenew(ms->mpb->libuf, ms->mpb->libuf_alloc);
     }
-    MPI_Allreduce(r,ms->mpb->libuf,nr,GMX_MPI_LARGE_INT,MPI_SUM,
+    MPI_Allreduce(r, ms->mpb->libuf, nr, MPI_INT64_T, MPI_SUM,
                   ms->mpi_comm_masters);
-    for(i=0; i<nr; i++)
+    for (i = 0; i < nr; i++)
+    {
         r[i] = ms->mpb->libuf[i];
+    }
 #endif
 #endif
 }
 
-
-void gmx_finalize_par(void)
+gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr)
 {
-#ifndef GMX_MPI
-    /* Compiled without MPI, no MPI finalizing needed */
-    return;
-#else
-    int initialized,finalized;
-    int ret;
+    gmx_bool bExist;
 
-    MPI_Initialized(&initialized);
-    if (!initialized)
+    if (SIMMASTER(cr))
     {
-        return;
+        bExist = gmx_fexist(fname);
     }
-    /* just as a check; we don't want to finalize twice */
-    MPI_Finalized(&finalized);
-    if (finalized)
+    if (PAR(cr))
     {
-       return;
+        gmx_bcast(sizeof(bExist), &bExist, cr);
     }
+    return bExist;
+}
 
-  /* We sync the processes here to try to avoid problems
-   * with buggy MPI implementations that could cause
-   * unfinished processes to terminate.
-   */
-  MPI_Barrier(MPI_COMM_WORLD);
-
-  /*
-  if (DOMAINDECOMP(cr)) {
-    if (cr->npmenodes > 0 || cr->dd->bCartesian) 
-      MPI_Comm_free(&cr->mpi_comm_mygroup);
-    if (cr->dd->bCartesian)
-      MPI_Comm_free(&cr->mpi_comm_mysim);
-  }
-  */
-
-  /* Apparently certain mpich implementations cause problems
-   * with MPI_Finalize. In that case comment out MPI_Finalize.
-   */
-  if (debug)
-    fprintf(debug,"Will call MPI_Finalize now\n");
-
-  ret = MPI_Finalize();
-  if (debug)
-    fprintf(debug,"Return code from MPI_Finalize = %d\n",ret);
+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);
+}