2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2008,2009,2010,2011,2012 by the GROMACS development team.
5 * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
6 * Copyright (c) 2019,2020, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
40 * \brief This file defines functions used by the domdec module
41 * in its initial setup phase.
43 * \author Berk Hess <hess@kth.se>
44 * \ingroup module_domdec
49 #include "domdec_setup.h"
56 #include "gromacs/domdec/domdec.h"
57 #include "gromacs/domdec/domdec_struct.h"
58 #include "gromacs/domdec/options.h"
59 #include "gromacs/ewald/pme.h"
60 #include "gromacs/gmxlib/network.h"
61 #include "gromacs/math/utilities.h"
62 #include "gromacs/math/vec.h"
63 #include "gromacs/mdlib/perf_est.h"
64 #include "gromacs/mdtypes/commrec.h"
65 #include "gromacs/mdtypes/inputrec.h"
66 #include "gromacs/mdtypes/md_enums.h"
67 #include "gromacs/pbcutil/pbc.h"
68 #include "gromacs/topology/topology.h"
69 #include "gromacs/utility/fatalerror.h"
70 #include "gromacs/utility/logger.h"
71 #include "gromacs/utility/stringutil.h"
74 #include "domdec_internal.h"
77 // TODO remove this when moving domdec into gmx namespace
78 using gmx::DomdecOptions;
80 /*! \brief Margin for setting up the DD grid */
81 #define DD_GRID_MARGIN_PRES_SCALE 1.05
83 /*! \brief Factorize \p n.
85 * \param[in] n Value to factorize
86 * \param[out] fac Vector of factors (to be allocated in this function)
87 * \param[out] mfac Vector with the number of times each factor repeats in the factorization (to be allocated in this function)
89 static void factorize(int n, std::vector<int>* fac, std::vector<int>* mfac)
93 gmx_fatal(FARGS, "Can only factorize positive integers.");
96 /* Decompose n in factors */
104 if (fac->empty() || fac->back() != d)
119 /*! \brief Find largest divisor of \p n smaller than \p n*/
120 static int largest_divisor(int n)
122 std::vector<int> div;
123 std::vector<int> mdiv;
124 factorize(n, &div, &mdiv);
129 /*! \brief Compute largest common divisor of \p n1 and \b n2 */
130 static int lcd(int n1, int n2)
135 for (i = 2; (i <= n1 && i <= n2); i++)
137 if (n1 % i == 0 && n2 % i == 0)
146 /*! \brief Returns TRUE when there are enough PME ranks for the ratio */
147 static gmx_bool fits_pme_ratio(int nrank_tot, int nrank_pme, float ratio)
149 return (static_cast<double>(nrank_pme) / static_cast<double>(nrank_tot) > 0.95 * ratio);
152 /*! \brief Returns TRUE when npme out of ntot ranks doing PME is expected to give reasonable performance */
153 static gmx_bool fits_pp_pme_perf(int ntot, int npme, float ratio)
155 std::vector<int> div;
156 std::vector<int> mdiv;
157 factorize(ntot - npme, &div, &mdiv);
159 int npp_root3 = gmx::roundToInt(std::cbrt(ntot - npme));
160 int npme_root2 = gmx::roundToInt(std::sqrt(static_cast<double>(npme)));
162 /* The check below gives a reasonable division:
163 * factor 5 allowed at 5 or more PP ranks,
164 * factor 7 allowed at 49 or more PP ranks.
166 if (div.back() > 3 + npp_root3)
171 /* Check if the number of PP and PME ranks have a reasonable sized
172 * denominator in common, such that we can use 2D PME decomposition
173 * when required (which requires nx_pp == nx_pme).
174 * The factor of 2 allows for a maximum ratio of 2^2=4
175 * between nx_pme and ny_pme.
177 if (lcd(ntot - npme, npme) * 2 < npme_root2)
182 /* Does this division gives a reasonable PME load? */
183 return fits_pme_ratio(ntot, npme, ratio);
186 /*! \brief Make a guess for the number of PME ranks to use. */
187 static int guess_npme(const gmx::MDLogger& mdlog,
188 const gmx_mtop_t& mtop,
189 const t_inputrec& ir,
196 ratio = pme_load_estimate(mtop, ir, box);
198 GMX_LOG(mdlog.info).appendTextFormatted("Guess for relative PME load: %.2f", ratio);
200 /* We assume the optimal rank ratio is close to the load ratio.
201 * The communication load is neglected,
202 * but (hopefully) this will balance out between PP and PME.
205 if (!fits_pme_ratio(nrank_tot, nrank_tot / 2, ratio))
207 /* We would need more than nrank_tot/2 PME only nodes,
208 * which is not possible. Since the PME load is very high,
209 * we will not loose much performance when all ranks do PME.
215 /* First try to find npme as a factor of nrank_tot up to nrank_tot/3.
216 * We start with a minimum PME node fraction of 1/16
217 * and avoid ratios which lead to large prime factors in nnodes-npme.
219 npme = (nrank_tot + 15) / 16;
220 while (npme <= nrank_tot / 3)
222 if (nrank_tot % npme == 0)
224 /* Note that fits_perf might change the PME grid,
225 * in the current implementation it does not.
227 if (fits_pp_pme_perf(nrank_tot, npme, ratio))
234 if (npme > nrank_tot / 3)
236 /* Try any possible number for npme */
238 while (npme <= nrank_tot / 2)
240 /* Note that fits_perf may change the PME grid */
241 if (fits_pp_pme_perf(nrank_tot, npme, ratio))
248 if (npme > nrank_tot / 2)
251 "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks "
252 "(%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, "
254 "Use the -npme option of mdrun or change the number of ranks or the PME grid "
255 "dimensions, see the manual for details.",
257 gmx::roundToInt(0.95 * ratio * nrank_tot),
265 .appendTextFormatted(
266 "Will use %d particle-particle and %d PME only ranks\n"
267 "This is a guess, check the performance at the end of the log file",
275 /*! \brief Return \p n divided by \p f rounded up to the next integer. */
276 static int div_up(int n, int f)
278 return (n + f - 1) / f;
281 real comm_box_frac(const gmx::IVec& dd_nc, real cutoff, const gmx_ddbox_t& ddbox)
287 for (i = 0; i < DIM; i++)
289 real bt = ddbox.box_size[i] * ddbox.skew_fac[i];
290 nw[i] = dd_nc[i] * cutoff / bt;
294 for (i = 0; i < DIM; i++)
299 for (j = i + 1; j < DIM; j++)
303 comm_vol += nw[i] * nw[j] * M_PI / 4;
304 for (k = j + 1; k < DIM; k++)
308 comm_vol += nw[i] * nw[j] * nw[k] * M_PI / 6;
319 /*! \brief Return whether the DD inhomogeneous in the z direction */
320 static gmx_bool inhomogeneous_z(const t_inputrec& ir)
322 return ((EEL_PME(ir.coulombtype) || ir.coulombtype == eelEWALD) && ir.pbcType == PbcType::Xyz
323 && ir.ewald_geometry == eewg3DC);
326 /*! \brief Estimate cost of PME FFT communication
328 * This only takes the communication into account and not imbalance
329 * in the calculation. But the imbalance in communication and calculation
330 * are similar and therefore these formulas also prefer load balance
331 * in the FFT and pme_solve calculation.
333 static float comm_pme_cost_vol(int npme, int a, int b, int c)
335 /* We use a float here, since an integer might overflow */
340 comm_vol *= div_up(a, npme);
341 comm_vol *= div_up(b, npme);
347 /*! \brief Estimate cost of communication for a possible domain decomposition. */
348 static float comm_cost_est(real limit,
351 const gmx_ddbox_t& ddbox,
353 const t_inputrec& ir,
358 gmx::IVec npme = { 1, 1, 1 };
359 int i, j, nk, overlap;
361 float comm_vol, comm_vol_xf, comm_pme, cost_pbcdx;
362 /* This is the cost of a pbc_dx call relative to the cost
363 * of communicating the coordinate and force of an atom.
364 * This will be machine dependent.
365 * These factors are for x86 with SMP or Infiniband.
367 float pbcdx_rect_fac = 0.1;
368 float pbcdx_tric_fac = 0.2;
371 /* Check the DD algorithm restrictions */
372 if ((ir.pbcType == PbcType::XY && ir.nwall < 2 && nc[ZZ] > 1)
373 || (ir.pbcType == PbcType::Screw && (nc[XX] == 1 || nc[YY] > 1 || nc[ZZ] > 1)))
378 if (inhomogeneous_z(ir) && nc[ZZ] > 1)
383 assert(ddbox.npbcdim <= DIM);
385 /* Check if the triclinic requirements are met */
386 for (i = 0; i < DIM; i++)
388 for (j = i + 1; j < ddbox.npbcdim; j++)
390 if (box[j][i] != 0 || ir.deform[j][i] != 0 || (ir.epc != epcNO && ir.compress[j][i] != 0))
392 if (nc[j] > 1 && nc[i] == 1)
400 for (i = 0; i < DIM; i++)
402 bt[i] = ddbox.box_size[i] * ddbox.skew_fac[i];
404 /* Without PBC and with 2 cells, there are no lower limits on the cell size */
405 if (!(i >= ddbox.npbcdim && nc[i] <= 2) && bt[i] < nc[i] * limit)
409 /* With PBC, check if the cut-off fits in nc[i]-1 cells */
410 if (i < ddbox.npbcdim && nc[i] > 1 && (nc[i] - 1) * bt[i] < nc[i] * cutoff)
418 /* The following choices should match those
419 * in init_domain_decomposition in domdec.c.
421 if (nc[XX] == 1 && nc[YY] > 1)
426 else if (nc[YY] == 1)
433 /* Will we use 1D or 2D PME decomposition? */
434 npme[XX] = (npme_tot % nc[XX] == 0) ? nc[XX] : npme_tot;
435 npme[YY] = npme_tot / npme[XX];
439 if (EEL_PME(ir.coulombtype) || EVDW_PME(ir.vdwtype))
441 /* Check the PME grid restrictions.
442 * Currently these can only be invalid here with too few grid lines
443 * along the x dimension per rank doing PME.
445 int npme_x = (npme_tot > 1 ? npme[XX] : nc[XX]);
447 /* Currently we don't have the OpenMP thread count available here.
448 * But with threads we have only tighter restrictions and it's
449 * probably better anyhow to avoid settings where we need to reduce
450 * grid lines over multiple ranks, as the thread check will do.
452 bool useThreads = true;
453 bool errorsAreFatal = false;
454 if (!gmx_pme_check_restrictions(
455 ir.pme_order, ir.nkx, ir.nky, ir.nkz, npme_x, useThreads, errorsAreFatal))
461 /* When two dimensions are (nearly) equal, use more cells
462 * for the smallest index, so the decomposition does not
463 * depend sensitively on the rounding of the box elements.
465 for (i = 0; i < DIM; i++)
467 for (j = i + 1; j < DIM; j++)
469 /* Check if the box size is nearly identical,
470 * in that case we prefer nx > ny and ny > nz.
472 if (std::fabs(bt[j] - bt[i]) < 0.01 * bt[i] && nc[j] > nc[i])
474 /* The XX/YY check is a bit compact. If nc[YY]==npme[YY]
475 * this means the swapped nc has nc[XX]==npme[XX],
476 * and we can also swap X and Y for PME.
478 /* Check if dimension i and j are equivalent for PME.
479 * For x/y: if nc[YY]!=npme[YY], we can not swap x/y
480 * For y/z: we can not have PME decomposition in z
483 || !((i == XX && j == YY && nc[YY] != npme[YY]) || (i == YY && j == ZZ && npme[YY] > 1)))
491 /* This function determines only half of the communication cost.
492 * All PP, PME and PP-PME communication is symmetric
493 * and the "back"-communication cost is identical to the forward cost.
496 comm_vol = comm_box_frac(nc, cutoff, ddbox);
499 for (i = 0; i < 2; i++)
501 /* Determine the largest volume for PME x/f redistribution */
502 if (nc[i] % npme[i] != 0)
506 comm_vol_xf = (npme[i] == 2 ? 1.0 / 3.0 : 0.5);
510 comm_vol_xf = 1.0 - lcd(nc[i], npme[i]) / static_cast<double>(npme[i]);
512 comm_pme += 3 * natoms * comm_vol_xf;
515 /* Grid overlap communication */
518 nk = (i == 0 ? ir.nkx : ir.nky);
519 overlap = (nk % npme[i] == 0 ? ir.pme_order - 1 : ir.pme_order);
527 /* Old line comm_pme += npme[i]*overlap*ir.nkx*ir.nky*ir.nkz/nk; */
531 comm_pme += comm_pme_cost_vol(npme[YY], ir.nky, ir.nkz, ir.nkx);
532 comm_pme += comm_pme_cost_vol(npme[XX], ir.nkx, ir.nky, ir.nkz);
534 /* Add cost of pbc_dx for bondeds */
536 if ((nc[XX] == 1 || nc[YY] == 1) || (nc[ZZ] == 1 && ir.pbcType != PbcType::XY))
538 if ((ddbox.tric_dir[XX] && nc[XX] == 1) || (ddbox.tric_dir[YY] && nc[YY] == 1))
540 cost_pbcdx = pbcdxr * pbcdx_tric_fac;
544 cost_pbcdx = pbcdxr * pbcdx_rect_fac;
551 "nc %2d %2d %2d %2d %2d vol pp %6.4f pbcdx %6.4f pme %9.3e tot %9.3e\n",
559 comm_pme / (3 * natoms),
560 comm_vol + cost_pbcdx + comm_pme / (3 * natoms));
563 return 3 * natoms * (comm_vol + cost_pbcdx) + comm_pme;
566 /*! \brief Assign penalty factors to possible domain decompositions,
567 * based on the estimated communication costs. */
568 static void assign_factors(const real limit,
571 const gmx_ddbox_t& ddbox,
573 const t_inputrec& ir,
584 gmx::IVec& ir_try = *irTryPtr;
589 ce = comm_cost_est(limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, ir_try);
592 || ce < comm_cost_est(limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, *opt)))
600 for (x = mdiv[0]; x >= 0; x--)
602 for (i = 0; i < x; i++)
604 ir_try[XX] *= div[0];
606 for (y = mdiv[0] - x; y >= 0; y--)
608 for (i = 0; i < y; i++)
610 ir_try[YY] *= div[0];
612 for (i = 0; i < mdiv[0] - x - y; i++)
614 ir_try[ZZ] *= div[0];
619 limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, ndiv - 1, div + 1, mdiv + 1, irTryPtr, opt);
621 for (i = 0; i < mdiv[0] - x - y; i++)
623 ir_try[ZZ] /= div[0];
625 for (i = 0; i < y; i++)
627 ir_try[YY] /= div[0];
630 for (i = 0; i < x; i++)
632 ir_try[XX] /= div[0];
637 /*! \brief Determine the optimal distribution of DD cells for the
638 * simulation system and number of MPI ranks
640 * \returns The optimal grid cell choice. The latter will contain all
641 * zeros if no valid cell choice exists. */
642 static gmx::IVec optimizeDDCells(const gmx::MDLogger& mdlog,
643 const int numRanksRequested,
644 const int numPmeOnlyRanks,
645 const real cellSizeLimit,
646 const gmx_mtop_t& mtop,
648 const gmx_ddbox_t& ddbox,
649 const t_inputrec& ir,
650 const DDSystemInfo& systemInfo)
654 const int numPPRanks = numRanksRequested - numPmeOnlyRanks;
657 .appendTextFormatted(
658 "Optimizing the DD grid for %d cells with a minimum initial size of %.3f nm",
661 if (inhomogeneous_z(ir))
664 .appendTextFormatted(
665 "Ewald_geometry=%s: assuming inhomogeneous particle distribution in z, "
666 "will not decompose in z.",
667 eewg_names[ir.ewald_geometry]);
671 // For cost estimates, we need the number of ranks doing PME work,
672 // which is the number of PP ranks when not using separate
674 const int numRanksDoingPmeWork =
675 (EEL_PME(ir.coulombtype) ? ((numPmeOnlyRanks > 0) ? numPmeOnlyRanks : numPPRanks) : 0);
677 if (systemInfo.haveInterDomainBondeds)
679 /* If we can skip PBC for distance calculations in plain-C bondeds,
680 * we can save some time (e.g. 3D DD with pbc=xyz).
681 * Here we ignore SIMD bondeds as they always do (fast) PBC.
683 count_bonded_distances(mtop, ir, &pbcdxr, nullptr);
684 pbcdxr /= static_cast<double>(mtop.natoms);
688 /* Every molecule is a single charge group: no pbc required */
692 if (cellSizeLimit > 0)
694 std::string maximumCells = "The maximum allowed number of cells is:";
695 for (int d = 0; d < DIM; d++)
697 int nmax = static_cast<int>(ddbox.box_size[d] * ddbox.skew_fac[d] / cellSizeLimit);
698 if (d >= ddbox.npbcdim && nmax < 2)
702 if (d == ZZ && inhomogeneous_z(ir))
706 maximumCells += gmx::formatString(" %c %d", 'X' + d, nmax);
708 GMX_LOG(mdlog.info).appendText(maximumCells);
713 fprintf(debug, "Average nr of pbc_dx calls per atom %.2f\n", pbcdxr);
716 /* Decompose numPPRanks in factors */
717 std::vector<int> div;
718 std::vector<int> mdiv;
719 factorize(numPPRanks, &div, &mdiv);
721 gmx::IVec itry = { 1, 1, 1 };
722 gmx::IVec numDomains = { 0, 0, 0 };
723 assign_factors(cellSizeLimit,
730 numRanksDoingPmeWork,
740 real getDDGridSetupCellSizeLimit(const gmx::MDLogger& mdlog,
741 const bool bDynLoadBal,
742 const real dlb_scale,
743 const t_inputrec& ir,
744 real systemInfoCellSizeLimit)
746 real cellSizeLimit = systemInfoCellSizeLimit;
748 /* Add a margin for DLB and/or pressure scaling */
751 if (dlb_scale >= 1.0)
753 gmx_fatal(FARGS, "The value for option -dds should be smaller than 1");
756 .appendTextFormatted(
757 "Scaling the initial minimum size with 1/%g (option -dds) = %g", dlb_scale, 1 / dlb_scale);
758 cellSizeLimit /= dlb_scale;
760 else if (ir.epc != epcNO)
763 .appendTextFormatted(
764 "To account for pressure scaling, scaling the initial minimum size with %g",
765 DD_GRID_MARGIN_PRES_SCALE);
766 cellSizeLimit *= DD_GRID_MARGIN_PRES_SCALE;
769 return cellSizeLimit;
771 void checkForValidRankCountRequests(const int numRanksRequested,
773 const int numPmeRanksRequested,
774 const bool checkForLargePrimeFactors)
776 int numPPRanksRequested = numRanksRequested;
777 if (usingPme && numPmeRanksRequested > 0)
779 numPPRanksRequested -= numPmeRanksRequested;
780 if (numPmeRanksRequested > numPPRanksRequested)
783 "Cannot have %d separate PME ranks with only %d PP ranks, choose fewer or no "
784 "separate PME ranks",
785 numPmeRanksRequested,
786 numPPRanksRequested);
790 // Once the rank count is large enough, it becomes worth
791 // suggesting improvements to the user.
792 const int minPPRankCountToCheckForLargePrimeFactors = 13;
793 if (checkForLargePrimeFactors && numPPRanksRequested >= minPPRankCountToCheckForLargePrimeFactors)
795 const int largestDivisor = largest_divisor(numPPRanksRequested);
796 /* Check if the largest divisor is more than numPPRanks ^ (2/3) */
797 if (largestDivisor * largestDivisor * largestDivisor > numPPRanksRequested * numPPRanksRequested)
800 "The number of ranks selected for particle-particle work (%d) "
801 "contains a large prime factor %d. In most cases this will lead to "
802 "bad performance. Choose a number with smaller prime factors or "
803 "set the decomposition (option -dd) manually.",
810 /*! \brief Return the number of PME-only ranks used by the simulation
812 * If the user did not choose a number, then decide for them. */
813 static int getNumPmeOnlyRanksToUse(const gmx::MDLogger& mdlog,
814 const DomdecOptions& options,
815 const gmx_mtop_t& mtop,
816 const t_inputrec& ir,
818 const int numRanksRequested)
821 const char* extraMessage = "";
823 if (options.numCells[XX] > 0)
825 if (options.numPmeRanks >= 0)
827 // TODO mdrun should give a fatal error with a non-PME input file and -npme > 0
828 numPmeOnlyRanks = options.numPmeRanks;
832 // When the DD grid is set explicitly and -npme is set to auto,
833 // don't use PME ranks. We check later if the DD grid is
834 // compatible with the total number of ranks.
840 if (!EEL_PME(ir.coulombtype))
842 // TODO mdrun should give a fatal error with a non-PME input file and -npme > 0
847 if (options.numPmeRanks >= 0)
849 numPmeOnlyRanks = options.numPmeRanks;
853 // Controls the automated choice of when to use separate PME-only ranks.
854 const int minRankCountToDefaultToSeparatePmeRanks = 19;
856 if (numRanksRequested < minRankCountToDefaultToSeparatePmeRanks)
860 ", as there are too few total\n"
861 " ranks for efficient splitting";
865 numPmeOnlyRanks = guess_npme(mdlog, mtop, ir, box, numRanksRequested);
866 extraMessage = ", as guessed by mdrun";
871 GMX_RELEASE_ASSERT(numPmeOnlyRanks <= numRanksRequested,
872 "Cannot have more PME ranks than total ranks");
873 if (EEL_PME(ir.coulombtype))
875 GMX_LOG(mdlog.info).appendTextFormatted("Using %d separate PME ranks%s", numPmeOnlyRanks, extraMessage);
878 return numPmeOnlyRanks;
881 /*! \brief Sets the order of the DD dimensions, returns the number of DD dimensions */
882 static int set_dd_dim(const gmx::IVec& numDDCells, const DDSettings& ddSettings, ivec* dims)
885 if (ddSettings.useDDOrderZYX)
887 /* Decomposition order z,y,x */
888 for (int dim = DIM - 1; dim >= 0; dim--)
890 if (numDDCells[dim] > 1)
892 (*dims)[ndim++] = dim;
898 /* Decomposition order x,y,z */
899 for (int dim = 0; dim < DIM; dim++)
901 if (numDDCells[dim] > 1)
903 (*dims)[ndim++] = dim;
910 /* Set dim[0] to avoid extra checks on ndim in several places */
917 DDGridSetup getDDGridSetup(const gmx::MDLogger& mdlog,
919 MPI_Comm communicator,
920 const int numRanksRequested,
921 const DomdecOptions& options,
922 const DDSettings& ddSettings,
923 const DDSystemInfo& systemInfo,
924 const real cellSizeLimit,
925 const gmx_mtop_t& mtop,
926 const t_inputrec& ir,
928 gmx::ArrayRef<const gmx::RVec> xGlobal,
931 int numPmeOnlyRanks = getNumPmeOnlyRanksToUse(mdlog, options, mtop, ir, box, numRanksRequested);
933 gmx::IVec numDomains;
934 if (options.numCells[XX] > 0)
936 numDomains = gmx::IVec(options.numCells);
937 const ivec numDomainsLegacyIvec = { numDomains[XX], numDomains[YY], numDomains[ZZ] };
938 set_ddbox_cr(ddRole, communicator, &numDomainsLegacyIvec, ir, box, xGlobal, ddbox);
942 set_ddbox_cr(ddRole, communicator, nullptr, ir, box, xGlobal, ddbox);
944 if (ddRole == DDRole::Master)
946 numDomains = optimizeDDCells(
947 mdlog, numRanksRequested, numPmeOnlyRanks, cellSizeLimit, mtop, box, *ddbox, ir, systemInfo);
951 /* Communicate the information set by the master to all ranks */
952 gmx_bcast(sizeof(numDomains), numDomains, communicator);
953 if (EEL_PME(ir.coulombtype))
955 gmx_bcast(sizeof(numPmeOnlyRanks), &numPmeOnlyRanks, communicator);
958 DDGridSetup ddGridSetup;
959 ddGridSetup.numPmeOnlyRanks = numPmeOnlyRanks;
960 ddGridSetup.numDomains[XX] = numDomains[XX];
961 ddGridSetup.numDomains[YY] = numDomains[YY];
962 ddGridSetup.numDomains[ZZ] = numDomains[ZZ];
963 ddGridSetup.numDDDimensions = set_dd_dim(numDomains, ddSettings, &ddGridSetup.ddDimensions);