2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
7 * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
52 static const t_nrnb_data nbdata[eNRNB] = {
53 /* These are re-used for different NB kernels, since there are so many.
54 * The actual number of flops is set dynamically.
56 { "NB VdW [V&F]", 1 },
58 { "NB Elec. [V&F]", 1 },
59 { "NB Elec. [F]", 1 },
60 { "NB Elec. [W3,V&F]", 1 },
61 { "NB Elec. [W3,F]", 1 },
62 { "NB Elec. [W3-W3,V&F]", 1 },
63 { "NB Elec. [W3-W3,F]", 1 },
64 { "NB Elec. [W4,V&F]", 1 },
65 { "NB Elec. [W4,F]", 1 },
66 { "NB Elec. [W4-W4,V&F]", 1 },
67 { "NB Elec. [W4-W4,F]", 1 },
68 { "NB VdW & Elec. [V&F]", 1 },
69 { "NB VdW & Elec. [F]", 1 },
70 { "NB VdW & Elec. [W3,V&F]", 1 },
71 { "NB VdW & Elec. [W3,F]", 1 },
72 { "NB VdW & Elec. [W3-W3,V&F]", 1 },
73 { "NB VdW & Elec. [W3-W3,F]", 1 },
74 { "NB VdW & Elec. [W4,V&F]", 1 },
75 { "NB VdW & Elec. [W4,F]", 1 },
76 { "NB VdW & Elec. [W4-W4,V&F]", 1 },
77 { "NB VdW & Elec. [W4-W4,F]", 1 },
79 { "NB Generic kernel", 1 },
80 { "NB Generic charge grp kernel", 1 },
81 { "NB Free energy kernel", 1 },
83 { "Pair Search distance check", 9 }, /* nbnxn pair dist. check */
84 /* nbnxn kernel flops are based on inner-loops without exclusion checks.
85 * Plain Coulomb runs through the RF kernels, except with GPUs.
86 * invsqrt is counted as 6 flops: 1 for _mm_rsqt_ps + 5 for iteration.
87 * The flops are equal for plain-C, x86 SIMD and GPUs, except for:
88 * - plain-C kernel uses one flop more for Coulomb-only (F) than listed
89 * - x86 SIMD LJ geom-comb.rule kernels (fastest) use 2 more flops
90 * - x86 SIMD LJ LB-comb.rule kernels (fast) use 3 (8 for F+E) more flops
91 * - GPU always does exclusions, which requires 2-4 flops, but as invsqrt
92 * is always counted as 6 flops, this roughly compensates.
94 { "NxN RF Elec. + LJ [F]", 38 }, /* nbnxn kernel LJ+RF, no ener */
95 { "NxN RF Elec. + LJ [V&F]", 54 },
96 { "NxN QSTab Elec. + LJ [F]", 41 }, /* nbnxn kernel LJ+tab, no en */
97 { "NxN QSTab Elec. + LJ [V&F]", 59 },
98 { "NxN Ewald Elec. + LJ [F]", 66 }, /* nbnxn kernel LJ+Ewald, no en */
99 { "NxN Ewald Elec. + LJ [V&F]", 107 },
100 { "NxN LJ [F]", 33 }, /* nbnxn kernel LJ, no ener */
101 { "NxN LJ [V&F]", 43 },
102 { "NxN RF Electrostatics [F]", 31 }, /* nbnxn kernel RF, no ener */
103 { "NxN RF Electrostatics [V&F]", 36 },
104 { "NxN QSTab Elec. [F]", 34 }, /* nbnxn kernel tab, no ener */
105 { "NxN QSTab Elec. [V&F]", 41 },
106 { "NxN Ewald Elec. [F]", 61 }, /* nbnxn kernel Ewald, no ener */
107 { "NxN Ewald Elec. [V&F]", 84 },
108 /* The switch function flops should be added to the LJ kernels above */
109 { "NxN LJ add F-switch [F]", 12 }, /* extra cost for LJ F-switch */
110 { "NxN LJ add F-switch [V&F]", 22 },
111 { "NxN LJ add P-switch [F]", 27 }, /* extra cost for LJ P-switch */
112 { "NxN LJ add P-switch [V&F]", 20 },
113 { "NxN LJ add LJ Ewald [F]", 36 }, /* extra cost for LJ Ewald */
114 { "NxN LJ add LJ Ewald [V&F]", 33 },
115 { "1,4 nonbonded interactions", 90 },
116 { "Calc Weights", 36 },
118 { "Spread Q Bspline", 2 },
120 { "Gather F Bspline", 6 },
122 { "Convolution", 4 },
125 { "Reset In Box", 3 },
131 { "FENE Bonds", 58 },
132 { "Tab. Bonds", 62 },
133 { "Restraint Potential", 86 },
134 { "Linear Angles", 57 },
136 { "G96Angles", 150 },
137 { "Quartic Angles", 160 },
138 { "Tab. Angles", 169 },
140 { "Impropers", 208 },
141 { "RB-Dihedrals", 247 },
142 { "Four. Dihedrals", 247 },
143 { "Tab. Dihedrals", 227 },
144 { "Dist. Restr.", 200 },
145 { "Orient. Restr.", 200 },
146 { "Dihedral Restr.", 200 },
147 { "Pos. Restr.", 50 },
148 { "Flat-bottom posres", 50 },
149 { "Angle Restr.", 191 },
150 { "Angle Restr. Z", 164 },
151 { "Morse Potent.", 83 },
152 { "Cubic Bonds", 54 },
154 { "Polarization", 59 },
155 { "Anharmonic Polarization", 72 },
156 { "Water Pol.", 62 },
157 { "Thole Pol.", 296 },
160 { "Ext.ens. Update", 54 },
167 { "Constraint-V", 9 },
168 { "Shake-Init", 10 },
169 { "Constraint-Vir", 24 },
171 { "Virtual Site 1", 1 },
172 { "Virtual Site 2", 23 },
173 { "Virtual Site 2fd", 63 },
174 { "Virtual Site 3", 37 },
175 { "Virtual Site 3fd", 95 },
176 { "Virtual Site 3fad", 176 },
177 { "Virtual Site 3out", 87 },
178 { "Virtual Site 4fd", 110 },
179 { "Virtual Site 4fdn", 254 },
180 { "Virtual Site N", 15 },
181 { "CMAP", 1700 }, // Estimate!
182 { "Urey-Bradley", 183 },
183 { "Cross-Bond-Bond", 163 },
184 { "Cross-Bond-Angle", 163 }
187 static void pr_two(FILE* out, int c, int i)
191 fprintf(out, "%c0%1d", c, i);
195 fprintf(out, "%c%2d", c, i);
199 static void pr_difftime(FILE* out, double dt)
201 int ndays, nhours, nmins, nsecs;
202 bool bPrint, bPrinted;
204 ndays = static_cast<int>(dt / (24 * 3600));
205 dt = dt - 24 * 3600 * ndays;
206 nhours = static_cast<int>(dt / 3600);
207 dt = dt - 3600 * nhours;
208 nmins = static_cast<int>(dt / 60);
209 dt = dt - nmins * 60;
210 nsecs = static_cast<int>(dt);
211 bPrint = (ndays > 0);
215 fprintf(out, "%d", ndays);
217 bPrint = bPrint || (nhours > 0);
222 pr_two(out, 'd', nhours);
226 fprintf(out, "%d", nhours);
229 bPrinted = bPrinted || bPrint;
230 bPrint = bPrint || (nmins > 0);
235 pr_two(out, 'h', nmins);
239 fprintf(out, "%d", nmins);
242 bPrinted = bPrinted || bPrint;
245 pr_two(out, ':', nsecs);
249 fprintf(out, "%ds", nsecs);
254 void clear_nrnb(t_nrnb* nrnb)
256 for (int i = 0; (i < eNRNB); i++)
262 void print_nrnb(FILE* out, t_nrnb* nrnb)
264 for (int i = 0; (i < eNRNB); i++)
268 fprintf(out, " %-26s %10.0f.\n", nbdata[i].name, nrnb->n[i]);
273 /* Returns in enr is the index of a full nbnxn VdW kernel */
274 static bool nrnb_is_nbnxn_vdw_kernel(int enr)
276 return (enr >= eNR_NBNXN_LJ_RF && enr <= eNR_NBNXN_LJ_E);
279 /* Returns in enr is the index of an nbnxn kernel addition (LJ modification) */
280 static bool nrnb_is_nbnxn_kernel_addition(int enr)
282 return (enr >= eNR_NBNXN_ADD_LJ_FSW && enr <= eNR_NBNXN_ADD_LJ_EWALD_E);
285 void atomicNrnbIncrement(t_nrnb* nrnb, int index, int increment)
288 nrnb->n[index] += increment;
291 void print_flop(FILE* out, t_nrnb* nrnb, double* nbfs, double* mflop)
293 double mni, frac, tfrac, tflop;
295 "-----------------------------------------------------------------------------";
298 for (int i = 0; (i < eNR_NBKERNEL_TOTAL_NR); i++)
300 if (std::strstr(nbdata[i].name, "W3-W3") != nullptr)
302 *nbfs += 9e-6 * nrnb->n[i];
304 else if (std::strstr(nbdata[i].name, "W3") != nullptr)
306 *nbfs += 3e-6 * nrnb->n[i];
308 else if (std::strstr(nbdata[i].name, "W4-W4") != nullptr)
310 *nbfs += 10e-6 * nrnb->n[i];
312 else if (std::strstr(nbdata[i].name, "W4") != nullptr)
314 *nbfs += 4e-6 * nrnb->n[i];
318 *nbfs += 1e-6 * nrnb->n[i];
322 for (int i = 0; (i < eNRNB); i++)
324 tflop += 1e-6 * nrnb->n[i] * nbdata[i].flop;
329 fprintf(out, "No MEGA Flopsen this time\n");
334 fprintf(out, "\n\tM E G A - F L O P S A C C O U N T I N G\n\n");
339 fprintf(out, " NB=Group-cutoff nonbonded kernels NxN=N-by-N cluster Verlet kernels\n");
340 fprintf(out, " RF=Reaction-Field VdW=Van der Waals QSTab=quadratic-spline table\n");
341 fprintf(out, " W3=SPC/TIP3p W4=TIP4p (single or pairs)\n");
342 fprintf(out, " V&F=Potential and force V=Potential only F=Force only\n\n");
344 fprintf(out, " %-32s %16s %15s %7s\n", "Computing:", "M-Number", "M-Flops", "% Flops");
345 fprintf(out, "%s\n", myline);
349 for (int i = 0; (i < eNRNB); i++)
351 mni = 1e-6 * nrnb->n[i];
352 /* Skip empty entries and nbnxn additional flops,
353 * which have been added to the kernel entry.
355 if (mni > 0 && !nrnb_is_nbnxn_kernel_addition(i))
359 flop = nbdata[i].flop;
360 if (nrnb_is_nbnxn_vdw_kernel(i))
362 /* Possibly add the cost of an LJ switch/Ewald function */
363 for (int j = eNR_NBNXN_ADD_LJ_FSW; j <= eNR_NBNXN_ADD_LJ_EWALD; j += 2)
367 /* Select the force or energy flop count */
368 e_kernel_add = j + ((i - eNR_NBNXN_LJ_RF) % 2);
370 if (nrnb->n[e_kernel_add] > 0)
372 flop += nbdata[e_kernel_add].flop;
376 *mflop += mni * flop;
377 frac = 100.0 * mni * flop / tflop;
381 fprintf(out, " %-32s %16.6f %15.3f %6.1f\n", nbdata[i].name, mni, mni * flop, frac);
387 fprintf(out, "%s\n", myline);
388 fprintf(out, " %-32s %16s %15.3f %6.1f\n", "Total", "", *mflop, tfrac);
389 fprintf(out, "%s\n\n", myline);
391 if (nrnb->n[eNR_NBKERNEL_GENERIC] > 0)
394 "WARNING: Using the slow generic C kernel. This is fine if you are\n"
395 "comparing different implementations or MD software. Routine\n"
396 "simulations should use a different non-bonded setup for much better\n"
402 void print_perf(FILE* out,
403 double time_per_thread,
404 double time_per_node,
410 double wallclocktime;
414 if (time_per_node > 0)
416 fprintf(out, "%12s %12s %12s %10s\n", "", "Core t (s)", "Wall t (s)", "(%)");
417 fprintf(out, "%12s %12.3f %12.3f %10.1f\n", "Time:", time_per_thread, time_per_node, 100.0 * time_per_thread / time_per_node);
418 /* only print day-hour-sec format if time_per_node is more than 30 min */
419 if (time_per_node > 30 * 60)
421 fprintf(out, "%12s %12s", "", "");
422 pr_difftime(out, time_per_node);
426 mflop = mflop / time_per_node;
427 wallclocktime = nsteps * delta_t;
429 if (getenv("GMX_DETAILED_PERF_STATS") == nullptr)
431 fprintf(out, "%12s %12s %12s\n", "", "(ns/day)", "(hour/ns)");
433 "%12s %12.3f %12.3f\n",
435 wallclocktime * 24 * 3.6 / time_per_node,
436 1000 * time_per_node / (3600 * wallclocktime));
441 "%12s %12s %12s %12s %12s\n",
444 (mflop > 1000) ? "(GFlops)" : "(MFlops)",
448 "%12s %12.3f %12.3f %12.3f %12.3f\n",
450 nbfs / time_per_node,
451 (mflop > 1000) ? (mflop / 1000) : mflop,
452 wallclocktime * 24 * 3.6 / time_per_node,
453 1000 * time_per_node / (3600 * wallclocktime));
458 if (getenv("GMX_DETAILED_PERF_STATS") == nullptr)
460 fprintf(out, "%12s %14s\n", "", "(steps/hour)");
461 fprintf(out, "%12s %14.1f\n", "Performance:", nsteps * 3600.0 / time_per_node);
466 "%12s %12s %12s %14s\n",
469 (mflop > 1000) ? "(GFlops)" : "(MFlops)",
472 "%12s %12.3f %12.3f %14.1f\n",
474 nbfs / time_per_node,
475 (mflop > 1000) ? (mflop / 1000) : mflop,
476 nsteps * 3600.0 / time_per_node);
482 int cost_nrnb(int enr)
484 return nbdata[enr].flop;
487 const char* nrnb_str(int enr)
489 return nbdata[enr].name;