Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / mdlib / domdec_setup.c
index 10b45e5a81004710136925de3767132da4ece6f6..5caa68a9b58508750b040a2e4140d07cb00c1d48 100644 (file)
@@ -1,35 +1,50 @@
-/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+/*
+ * This file is part of the GROMACS molecular simulation package.
  *
+ * Copyright (c) 2008,2009,2010,2011,2012,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.
  *
- * This file is part of Gromacs        Copyright (c) 1991-2008
- * David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen.
- *
- * 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
+ * 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.
  *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://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.
  *
- * And Hey:
- * Gnomes, ROck Monsters And Chili Sauce
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
 #include <stdio.h>
 #include <assert.h>
-#include "domdec.h"
-#include "network.h"
-#include "perf_est.h"
-#include "physics.h"
-#include "smalloc.h"
-#include "typedefs.h"
-#include "vec.h"
-#include "names.h"
+#include "gromacs/legacyheaders/domdec.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/legacyheaders/perf_est.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/legacyheaders/names.h"
 
 /* Margin for setting up the DD grid */
 #define DD_GRID_MARGIN_PRES_SCALE 1.05
@@ -200,8 +215,8 @@ static int guess_npme(FILE *fplog, gmx_mtop_t *mtop, t_inputrec *ir, matrix box,
     }
     if (npme > nnodes/2)
     {
-        gmx_fatal(FARGS, "Could not find an appropriate number of separate PME nodes. i.e. >= %5f*#nodes (%d) and <= #nodes/2 (%d) and reasonable performance wise (grid_x=%d, grid_y=%d).\n"
-                  "Use the -npme option of mdrun or change the number of processors or the PME grid dimensions, see the manual for details.",
+        gmx_fatal(FARGS, "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks (%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, grid_y=%d).\n"
+                  "Use the -npme option of mdrun or change the number of ranks or the PME grid dimensions, see the manual for details.",
                   ratio, (int)(0.95*ratio*nnodes+0.5), nnodes/2, ir->nkx, ir->nky);
         /* Keep the compiler happy */
         npme = 0;
@@ -211,12 +226,12 @@ static int guess_npme(FILE *fplog, gmx_mtop_t *mtop, t_inputrec *ir, matrix box,
         if (fplog)
         {
             fprintf(fplog,
-                    "Will use %d particle-particle and %d PME only nodes\n"
+                    "Will use %d particle-particle and %d PME only ranks\n"
                     "This is a guess, check the performance at the end of the log file\n",
                     nnodes-npme, npme);
         }
         fprintf(stderr, "\n"
-                "Will use %d particle-particle and %d PME only nodes\n"
+                "Will use %d particle-particle and %d PME only ranks\n"
                 "This is a guess, check the performance at the end of the log file\n",
                 nnodes-npme, npme);
     }
@@ -341,11 +356,16 @@ static float comm_cost_est(real limit, real cutoff,
     {
         bt[i] = ddbox->box_size[i]*ddbox->skew_fac[i];
 
-        /* Without PBC there are no cell size limits with 2 cells */
+        /* Without PBC and with 2 cells, there are no lower limits on the cell size */
         if (!(i >= ddbox->npbcdim && nc[i] <= 2) && bt[i] < nc[i]*limit)
         {
             return -1;
         }
+        /* With PBC, check if the cut-off fits in nc[i]-1 cells */
+        if (i < ddbox->npbcdim && nc[i] > 1 && (nc[i] - 1)*bt[i] < nc[i]*cutoff)
+        {
+            return -1;
+        }
     }
 
     if (npme_tot > 1)
@@ -663,7 +683,7 @@ real dd_choose_grid(FILE *fplog,
                     real cellsize_limit, real cutoff_dd,
                     gmx_bool bInterCGBondeds)
 {
-    gmx_large_int_t nnodes_div, ldiv;
+    gmx_int64_t     nnodes_div, ldiv;
     real            limit;
 
     if (MASTER(cr))
@@ -676,12 +696,12 @@ real dd_choose_grid(FILE *fplog,
                 if (cr->nnodes <= 2)
                 {
                     gmx_fatal(FARGS,
-                              "Can not have separate PME nodes with 2 or less nodes");
+                              "Cannot have separate PME ranks with 2 or fewer ranks");
                 }
                 if (cr->npmenodes >= cr->nnodes)
                 {
                     gmx_fatal(FARGS,
-                              "Can not have %d separate PME nodes with just %d total nodes",
+                              "Cannot have %d separate PME ranks with just %d total ranks",
                               cr->npmenodes, cr->nnodes);
                 }
 
@@ -696,13 +716,13 @@ real dd_choose_grid(FILE *fplog,
             cr->npmenodes = 0;
         }
 
-        if (cr->nnodes > 12)
+        if (nnodes_div > 12)
         {
             ldiv = largest_divisor(nnodes_div);
             /* Check if the largest divisor is more than nnodes^2/3 */
             if (ldiv*ldiv*ldiv > nnodes_div*nnodes_div)
             {
-                gmx_fatal(FARGS, "The number of nodes you selected (%d) contains a large prime factor %d. In most cases this will lead to bad performance. Choose a number with smaller prime factors or set the decomposition (option -dd) manually.",
+                gmx_fatal(FARGS, "The number of ranks you selected (%d) contains a large prime factor %d. In most cases this will lead to bad performance. Choose a number with smaller prime factors or set the decomposition (option -dd) manually.",
                           nnodes_div, ldiv);
             }
         }
@@ -717,7 +737,7 @@ real dd_choose_grid(FILE *fplog,
                     cr->npmenodes = 0;
                     if (fplog)
                     {
-                        fprintf(fplog, "Using %d separate PME nodes, as there are too few total\n nodes for efficient splitting\n", cr->npmenodes);
+                        fprintf(fplog, "Using %d separate PME ranks, as there are too few total\n ranks for efficient splitting\n", cr->npmenodes);
                     }
                 }
                 else
@@ -725,7 +745,7 @@ real dd_choose_grid(FILE *fplog,
                     cr->npmenodes = guess_npme(fplog, mtop, ir, box, cr->nnodes);
                     if (fplog)
                     {
-                        fprintf(fplog, "Using %d separate PME nodes, as guessed by mdrun\n", cr->npmenodes);
+                        fprintf(fplog, "Using %d separate PME ranks, as guessed by mdrun\n", cr->npmenodes);
                     }
                 }
             }
@@ -733,7 +753,7 @@ real dd_choose_grid(FILE *fplog,
             {
                 if (fplog)
                 {
-                    fprintf(fplog, "Using %d separate PME nodes, per user request\n", cr->npmenodes);
+                    fprintf(fplog, "Using %d separate PME ranks, per user request\n", cr->npmenodes);
                 }
             }
         }