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-2008, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2018,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.
40 #include "wallcycle.h"
49 #include "gromacs/math/functions.h"
50 #include "gromacs/mdtypes/commrec.h"
51 #include "gromacs/timing/cyclecounter.h"
52 #include "gromacs/timing/gpu_timing.h"
53 #include "gromacs/timing/wallcyclereporting.h"
54 #include "gromacs/utility/cstringutil.h"
55 #include "gromacs/utility/gmxassert.h"
56 #include "gromacs/utility/gmxmpi.h"
57 #include "gromacs/utility/logger.h"
58 #include "gromacs/utility/smalloc.h"
59 #include "gromacs/utility/snprintf.h"
61 //! Whether wallcycle debugging is enabled
62 constexpr bool gmx_unused enableWallcycleDebug = (DEBUG_WCYCLE != 0);
63 //! True if only the master rank should print debugging output
64 constexpr bool gmx_unused onlyMasterDebugPrints = true;
65 //! True if cycle counter nesting depth debuggin prints are enabled
66 constexpr bool gmx_unused debugPrintDepth = false /* enableWallcycleDebug */;
69 # include "gromacs/utility/fatalerror.h"
72 /* Each name should not exceed 19 printing characters
73 (ie. terminating null can be twentieth) */
74 static const char* wcn[ewcNR] = { "Run",
97 "Wait PME GPU spread",
99 "PME solve", /* the strings for FFT/solve are repeated here for mixed mode counters */
100 "Wait PME GPU gather",
103 "Wait GPU NB nonloc.",
105 "Wait GPU state copy",
106 "NB X/F buffer ops.",
120 static const char* wcsn[ewcsNR] = {
131 "NS search non-loc.",
135 "Listed buffer ops.",
137 "Nonbonded F kernel",
140 "Launch NB GPU tasks",
141 "Launch Bonded GPU tasks",
142 "Launch PME GPU tasks",
144 "Ewald F correction",
147 "Clear force buffer",
148 "Launch GPU NB X buffer ops.",
149 "Launch GPU NB F buffer ops.",
150 "Launch GPU Comm. coord.",
151 "Launch GPU Comm. force.",
156 /* PME GPU timing events' names - correspond to the enum in the gpu_timing.h */
157 static const char* enumValuetoString(PmeStage enumValue)
159 constexpr gmx::EnumerationArray<PmeStage, const char*> pmeStageNames = {
160 "PME spline", "PME spread", "PME spline + spread", "PME 3D-FFT r2c",
161 "PME solve", "PME 3D-FFT c2r", "PME gather"
163 return pmeStageNames[enumValue];
166 bool wallcycle_have_counter()
168 return gmx_cycles_have_counter();
171 gmx_wallcycle_t wallcycle_init(FILE* fplog, int resetstep, const t_commrec* cr)
176 if (!wallcycle_have_counter())
183 wc->haveInvalidCount = FALSE;
184 wc->wc_barrier = FALSE;
185 wc->wcc_all = nullptr;
188 wc->reset_counters = resetstep;
193 if (cr != nullptr && PAR(cr) && getenv("GMX_CYCLE_BARRIER") != nullptr)
197 fprintf(fplog, "\nWill call MPI_Barrier before each cycle start/stop call\n\n");
199 wc->wc_barrier = TRUE;
203 snew(wc->wcc, ewcNR);
204 if (getenv("GMX_CYCLE_ALL") != nullptr)
208 fprintf(fplog, "\nWill time all the code during the run\n\n");
210 snew(wc->wcc_all, ewcNR * ewcNR);
213 if (sc_useCycleSubcounters)
215 snew(wc->wcsc, ewcsNR);
220 wc->isMasterRank = MASTER(cr);
226 void wallcycle_destroy(gmx_wallcycle_t wc)
233 if (wc->wcc != nullptr)
237 if (wc->wcc_all != nullptr)
241 if (wc->wcsc != nullptr)
249 static void debug_start_check(gmx_wallcycle_t wc, int ewc)
251 if (wc->count_depth < 0 || wc->count_depth >= DEPTH_MAX)
253 gmx_fatal(FARGS, "wallcycle counter depth out of range: %d", wc->count_depth + 1);
255 wc->counterlist[wc->count_depth] = ewc;
258 if (debugPrintDepth && (!onlyMasterDebugPrints || wc->isMasterRank))
260 std::string indentStr(4 * wc->count_depth, ' ');
261 fprintf(stderr, "%swcycle_start depth %d, %s\n", indentStr.c_str(), wc->count_depth, wcn[ewc]);
265 static void debug_stop_check(gmx_wallcycle_t wc, int ewc)
267 if (debugPrintDepth && (!onlyMasterDebugPrints || wc->isMasterRank))
269 std::string indentStr(4 * wc->count_depth, ' ');
270 fprintf(stderr, "%swcycle_stop depth %d, %s\n", indentStr.c_str(), wc->count_depth, wcn[ewc]);
275 if (wc->count_depth < 0)
277 gmx_fatal(FARGS, "wallcycle counter depth out of range when stopping %s: %d", wcn[ewc], wc->count_depth);
279 if (wc->counterlist[wc->count_depth] != ewc)
282 "wallcycle mismatch at stop, start %s, stop %s",
283 wcn[wc->counterlist[wc->count_depth]],
289 void wallcycle_get(gmx_wallcycle_t wc, int ewc, int* n, double* c)
292 *c = static_cast<double>(wc->wcc[ewc].c);
295 void wallcycle_sub_get(gmx_wallcycle_t wc, int ewcs, int* n, double* c)
297 if (sc_useCycleSubcounters && wc != nullptr)
299 *n = wc->wcsc[ewcs].n;
300 *c = static_cast<double>(wc->wcsc[ewcs].c);
304 void wallcycle_reset_all(gmx_wallcycle_t wc)
313 for (i = 0; i < ewcNR; i++)
318 wc->haveInvalidCount = FALSE;
322 for (i = 0; i < ewcNR * ewcNR; i++)
324 wc->wcc_all[i].n = 0;
325 wc->wcc_all[i].c = 0;
330 for (i = 0; i < ewcsNR; i++)
338 static gmx_bool is_pme_counter(int ewc)
340 return (ewc >= ewcPMEMESH && ewc <= ewcPMEWAITCOMM);
343 static gmx_bool is_pme_subcounter(int ewc)
345 return (ewc >= ewcPME_REDISTXF && ewc < ewcPMEWAITCOMM);
348 void wallcycleBarrier(gmx_wallcycle* wc)
353 MPI_Barrier(wc->cr->mpi_comm_mygroup);
358 /* Subtract counter ewc_sub timed inside a timing block for ewc_main */
359 static void subtract_cycles(wallcc_t* wcc, int ewc_main, int ewc_sub)
361 if (wcc[ewc_sub].n > 0)
363 if (wcc[ewc_main].c >= wcc[ewc_sub].c)
365 wcc[ewc_main].c -= wcc[ewc_sub].c;
369 /* Something is wrong with the cycle counting */
375 void wallcycle_scale_by_num_threads(gmx_wallcycle_t wc, bool isPmeRank, int nthreads_pp, int nthreads_pme)
382 for (int i = 0; i < ewcNR; i++)
384 if (is_pme_counter(i) || (i == ewcRUN && isPmeRank))
386 wc->wcc[i].c *= nthreads_pme;
390 for (int j = 0; j < ewcNR; j++)
392 wc->wcc_all[i * ewcNR + j].c *= nthreads_pme;
398 wc->wcc[i].c *= nthreads_pp;
402 for (int j = 0; j < ewcNR; j++)
404 wc->wcc_all[i * ewcNR + j].c *= nthreads_pp;
409 if (sc_useCycleSubcounters && wc->wcsc && !isPmeRank)
411 for (int i = 0; i < ewcsNR; i++)
413 wc->wcsc[i].c *= nthreads_pp;
418 /* TODO Make an object for this function to return, containing some
419 * vectors of something like wallcc_t for the summed wcc, wcc_all and
420 * wcsc, AND the original wcc for rank 0.
422 * The GPU timing is reported only for rank 0, so we want to preserve
423 * the original wcycle on that rank. Rank 0 also reports the global
424 * counts before that, so needs something to contain the global data
425 * without over-writing the rank-0 data. The current implementation
426 * uses cycles_sum to manage this, which works OK now because wcsc and
427 * wcc_all are unused by the GPU reporting, but it is not satisfactory
428 * for the future. Also, there's no need for MPI_Allreduce, since
429 * only MASTERRANK uses any of the results. */
430 WallcycleCounts wallcycle_sum(const t_commrec* cr, gmx_wallcycle_t wc)
432 WallcycleCounts cycles_sum;
434 double cycles[int(ewcNR) + int(ewcsNR)];
436 double cycles_n[int(ewcNR) + int(ewcsNR) + 1];
443 /* Default construction of std::array of non-class T can leave
444 the values indeterminate, just like a C array */
451 subtract_cycles(wcc, ewcDOMDEC, ewcDDCOMMLOAD);
452 subtract_cycles(wcc, ewcDOMDEC, ewcDDCOMMBOUND);
454 subtract_cycles(wcc, ewcPME_FFT, ewcPME_FFTCOMM);
456 if (cr->npmenodes == 0)
458 /* All nodes do PME (or no PME at all) */
459 subtract_cycles(wcc, ewcFORCE, ewcPMEMESH);
463 /* The are PME-only nodes */
464 if (wcc[ewcPMEMESH].n > 0)
466 /* This must be a PME only node, calculate the Wait + Comm. time */
467 GMX_ASSERT(wcc[ewcRUN].c >= wcc[ewcPMEMESH].c,
468 "Total run ticks must be greater than PME-only ticks");
469 wcc[ewcPMEWAITCOMM].c = wcc[ewcRUN].c - wcc[ewcPMEMESH].c;
473 /* Store the cycles in a double buffer for summing */
474 for (i = 0; i < ewcNR; i++)
477 cycles_n[i] = static_cast<double>(wcc[i].n);
479 cycles[i] = static_cast<double>(wcc[i].c);
484 for (i = 0; i < ewcsNR; i++)
487 cycles_n[ewcNR + i] = static_cast<double>(wc->wcsc[i].n);
489 cycles[ewcNR + i] = static_cast<double>(wc->wcsc[i].c);
497 double buf[int(ewcNR) + int(ewcsNR) + 1];
499 // TODO this code is used only at the end of the run, so we
500 // can just do a simple reduce of haveInvalidCount in
501 // wallcycle_print, and avoid bugs
502 cycles_n[nsum] = (wc->haveInvalidCount ? 1 : 0);
503 // TODO Use MPI_Reduce
504 MPI_Allreduce(cycles_n, buf, nsum + 1, MPI_DOUBLE, MPI_MAX, cr->mpi_comm_mysim);
505 for (i = 0; i < ewcNR; i++)
507 wcc[i].n = gmx::roundToInt(buf[i]);
509 wc->haveInvalidCount = (buf[nsum] > 0);
512 for (i = 0; i < ewcsNR; i++)
514 wc->wcsc[i].n = gmx::roundToInt(buf[ewcNR + i]);
518 // TODO Use MPI_Reduce
519 MPI_Allreduce(cycles, cycles_sum.data(), nsum, MPI_DOUBLE, MPI_SUM, cr->mpi_comm_mysim);
521 if (wc->wcc_all != nullptr)
523 double *buf_all, *cyc_all;
525 snew(cyc_all, ewcNR * ewcNR);
526 snew(buf_all, ewcNR * ewcNR);
527 for (i = 0; i < ewcNR * ewcNR; i++)
529 cyc_all[i] = wc->wcc_all[i].c;
531 // TODO Use MPI_Reduce
532 MPI_Allreduce(cyc_all, buf_all, ewcNR * ewcNR, MPI_DOUBLE, MPI_SUM, cr->mpi_comm_mysim);
533 for (i = 0; i < ewcNR * ewcNR; i++)
535 wc->wcc_all[i].c = static_cast<gmx_cycles_t>(buf_all[i]);
544 for (i = 0; i < nsum; i++)
546 cycles_sum[i] = cycles[i];
554 print_cycles(FILE* fplog, double c2t, const char* name, int nnodes, int nthreads, int ncalls, double c_sum, double tot)
556 char nnodes_str[STRLEN];
557 char nthreads_str[STRLEN];
558 char ncalls_str[STRLEN];
560 double percentage = (tot > 0.) ? (100. * c_sum / tot) : 0.;
566 snprintf(ncalls_str, sizeof(ncalls_str), "%10d", ncalls);
569 snprintf(nnodes_str, sizeof(nnodes_str), "N/A");
573 snprintf(nnodes_str, sizeof(nnodes_str), "%4d", nnodes);
577 snprintf(nthreads_str, sizeof(nthreads_str), "N/A");
581 snprintf(nthreads_str, sizeof(nthreads_str), "%4d", nthreads);
590 /* Convert the cycle count to wallclock time for this task */
594 " %-19.19s %4s %4s %10s %10.3f %14.3f %5.1f\n",
605 static void print_gputimes(FILE* fplog, const char* name, int n, double t, double tot_t)
612 snprintf(num, sizeof(num), "%10d", n);
613 snprintf(avg_perf, sizeof(avg_perf), "%10.3f", t / n);
618 sprintf(avg_perf, " ");
620 if (t != tot_t && tot_t > 0)
622 fprintf(fplog, " %-29s %10s%12.3f %s %5.1f\n", name, num, t / 1000, avg_perf, 100 * t / tot_t);
626 fprintf(fplog, " %-29s %10s%12.3f %s %5.1f\n", name, "", t / 1000, avg_perf, 100.0);
630 static void print_header(FILE* fplog, int nrank_pp, int nth_pp, int nrank_pme, int nth_pme)
632 int nrank_tot = nrank_pp + nrank_pme;
635 fprintf(fplog, "On %d MPI rank%s", nrank_tot, nrank_tot == 1 ? "" : "s");
638 fprintf(fplog, ", each using %d OpenMP threads", nth_pp);
640 /* Don't report doing PP+PME, because we can't tell here if
641 * this is RF, etc. */
645 fprintf(fplog, "On %d MPI rank%s doing PP", nrank_pp, nrank_pp == 1 ? "" : "s");
648 fprintf(fplog, ",%s using %d OpenMP threads", nrank_pp > 1 ? " each" : "", nth_pp);
650 fprintf(fplog, ", and\non %d MPI rank%s doing PME", nrank_pme, nrank_pme == 1 ? "" : "s");
653 fprintf(fplog, ",%s using %d OpenMP threads", nrank_pme > 1 ? " each" : "", nth_pme);
657 fprintf(fplog, "\n\n");
658 fprintf(fplog, " Computing: Num Num Call Wall time Giga-Cycles\n");
659 fprintf(fplog, " Ranks Threads Count (s) total sum %%\n");
663 void wallcycle_print(FILE* fplog,
664 const gmx::MDLogger& mdlog,
671 const WallcycleCounts& cyc_sum,
672 const gmx_wallclock_gpu_nbnxn_t* gpu_nbnxn_t,
673 const gmx_wallclock_gpu_pme_t* gpu_pme_t)
675 double tot, tot_for_pp, tot_for_rest, tot_cpu_overlap, gpu_cpu_ratio;
676 double c2t, c2t_pp, c2t_pme = 0;
677 int i, j, npp, nth_tot;
680 "-----------------------------------------------------------------------------";
687 GMX_ASSERT(nth_pp > 0, "Number of particle-particle threads must be >0");
688 GMX_ASSERT(nth_pme > 0, "Number of PME threads must be >0");
689 GMX_ASSERT(nnodes > 0, "Number of nodes must be >0");
690 GMX_ASSERT(npme >= 0, "Number of PME nodes cannot be negative");
692 /* npme is the number of PME-only ranks used, and we always do PP work */
693 GMX_ASSERT(npp > 0, "Number of particle-particle nodes must be >0");
695 nth_tot = npp * nth_pp + npme * nth_pme;
697 /* When using PME-only nodes, the next line is valid for both
698 PP-only and PME-only nodes because they started ewcRUN at the
700 tot = cyc_sum[ewcRUN];
705 /* TODO This is heavy handed, but until someone reworks the
706 code so that it is provably robust with respect to
707 non-positive values for all possible timer and cycle
708 counters, there is less value gained from printing whatever
709 timing data might still be sensible for some non-Jenkins
710 run, than is lost from diagnosing Jenkins FP exceptions on
711 runs about whose execution time we don't care. */
712 GMX_LOG(mdlog.warning)
714 .appendTextFormatted(
715 "WARNING: A total of %f CPU cycles was recorded, so mdrun cannot print a "
721 if (wc->haveInvalidCount)
723 GMX_LOG(mdlog.warning)
726 "NOTE: Detected invalid cycle counts, probably because threads moved "
727 "between CPU cores that do not have synchronized cycle counters. Will not "
728 "print the cycle accounting.");
733 /* Conversion factor from cycles to seconds */
734 c2t = realtime / tot;
735 c2t_pp = c2t * nth_tot / static_cast<double>(npp * nth_pp);
738 c2t_pme = c2t * nth_tot / static_cast<double>(npme * nth_pme);
745 fprintf(fplog, "\n R E A L C Y C L E A N D T I M E A C C O U N T I N G\n\n");
747 print_header(fplog, npp, nth_pp, npme, nth_pme);
749 fprintf(fplog, "%s\n", hline);
750 for (i = ewcPPDURINGPME + 1; i < ewcNR; i++)
752 if (is_pme_subcounter(i))
754 /* Do not count these at all */
756 else if (npme > 0 && is_pme_counter(i))
758 /* Print timing information for PME-only nodes, but add an
759 * asterisk so the reader of the table can know that the
760 * walltimes are not meant to add up. The asterisk still
761 * fits in the required maximum of 19 characters. */
763 snprintf(buffer, STRLEN, "%s *", wcn[i]);
764 print_cycles(fplog, c2t_pme, buffer, npme, nth_pme, wc->wcc[i].n, cyc_sum[i], tot);
768 /* Print timing information when it is for a PP or PP+PME
770 print_cycles(fplog, c2t_pp, wcn[i], npp, nth_pp, wc->wcc[i].n, cyc_sum[i], tot);
771 tot_for_pp += cyc_sum[i];
774 if (wc->wcc_all != nullptr)
776 for (i = 0; i < ewcNR; i++)
778 for (j = 0; j < ewcNR; j++)
780 snprintf(buf, 20, "%-9.9s %-9.9s", wcn[i], wcn[j]);
786 wc->wcc_all[i * ewcNR + j].n,
787 wc->wcc_all[i * ewcNR + j].c,
792 tot_for_rest = tot * npp * nth_pp / static_cast<double>(nth_tot);
793 print_cycles(fplog, c2t_pp, "Rest", npp, nth_pp, -1, tot_for_rest - tot_for_pp, tot);
794 fprintf(fplog, "%s\n", hline);
795 print_cycles(fplog, c2t, "Total", npp, nth_pp, -1, tot, tot);
796 fprintf(fplog, "%s\n", hline);
801 "(*) Note that with separate PME ranks, the walltime column actually sums to\n"
802 " twice the total reported, but the cycle count total and %% are correct.\n"
807 if (wc->wcc[ewcPMEMESH].n > 0)
809 // A workaround to not print breakdown when no subcounters were recorded.
810 // TODO: figure out and record PME GPU counters (what to do with the waiting ones?)
811 std::vector<int> validPmeSubcounterIndices;
812 for (i = ewcPPDURINGPME + 1; i < ewcNR; i++)
814 if (is_pme_subcounter(i) && wc->wcc[i].n > 0)
816 validPmeSubcounterIndices.push_back(i);
820 if (!validPmeSubcounterIndices.empty())
822 fprintf(fplog, " Breakdown of PME mesh computation\n");
823 fprintf(fplog, "%s\n", hline);
824 for (auto i : validPmeSubcounterIndices)
827 npme > 0 ? c2t_pme : c2t_pp,
829 npme > 0 ? npme : npp,
835 fprintf(fplog, "%s\n", hline);
839 if (sc_useCycleSubcounters && wc->wcsc)
841 fprintf(fplog, " Breakdown of PP computation\n");
842 fprintf(fplog, "%s\n", hline);
843 for (i = 0; i < ewcsNR; i++)
845 print_cycles(fplog, c2t_pp, wcsn[i], npp, nth_pp, wc->wcsc[i].n, cyc_sum[ewcNR + i], tot);
847 fprintf(fplog, "%s\n", hline);
850 /* print GPU timing summary */
851 double tot_gpu = 0.0;
854 for (auto key : keysOf(gpu_pme_t->timing))
856 tot_gpu += gpu_pme_t->timing[key].t;
861 const char* k_log_str[2][2] = { { "Nonbonded F kernel", "Nonbonded F+ene k." },
862 { "Nonbonded F+prune k.", "Nonbonded F+ene+prune k." } };
863 tot_gpu += gpu_nbnxn_t->pl_h2d_t + gpu_nbnxn_t->nb_h2d_t + gpu_nbnxn_t->nb_d2h_t;
865 /* add up the kernel timings */
866 for (i = 0; i < 2; i++)
868 for (j = 0; j < 2; j++)
870 tot_gpu += gpu_nbnxn_t->ktime[i][j].t;
873 tot_gpu += gpu_nbnxn_t->pruneTime.t;
875 tot_cpu_overlap = wc->wcc[ewcFORCE].c;
876 if (wc->wcc[ewcPMEMESH].n > 0)
878 tot_cpu_overlap += wc->wcc[ewcPMEMESH].c;
880 tot_cpu_overlap *= realtime * 1000 / tot; /* convert s to ms */
882 fprintf(fplog, "\n GPU timings\n%s\n", hline);
884 " Computing: Count Wall t (s) ms/step %c\n",
886 fprintf(fplog, "%s\n", hline);
887 print_gputimes(fplog, "Pair list H2D", gpu_nbnxn_t->pl_h2d_c, gpu_nbnxn_t->pl_h2d_t, tot_gpu);
888 print_gputimes(fplog, "X / q H2D", gpu_nbnxn_t->nb_c, gpu_nbnxn_t->nb_h2d_t, tot_gpu);
890 for (i = 0; i < 2; i++)
892 for (j = 0; j < 2; j++)
894 if (gpu_nbnxn_t->ktime[i][j].c)
896 print_gputimes(fplog,
898 gpu_nbnxn_t->ktime[i][j].c,
899 gpu_nbnxn_t->ktime[i][j].t,
906 for (auto key : keysOf(gpu_pme_t->timing))
908 if (gpu_pme_t->timing[key].c)
910 print_gputimes(fplog,
911 enumValuetoString(key),
912 gpu_pme_t->timing[key].c,
913 gpu_pme_t->timing[key].t,
918 if (gpu_nbnxn_t->pruneTime.c)
920 print_gputimes(fplog, "Pruning kernel", gpu_nbnxn_t->pruneTime.c, gpu_nbnxn_t->pruneTime.t, tot_gpu);
922 print_gputimes(fplog, "F D2H", gpu_nbnxn_t->nb_c, gpu_nbnxn_t->nb_d2h_t, tot_gpu);
923 fprintf(fplog, "%s\n", hline);
924 print_gputimes(fplog, "Total ", gpu_nbnxn_t->nb_c, tot_gpu, tot_gpu);
925 fprintf(fplog, "%s\n", hline);
926 if (gpu_nbnxn_t->dynamicPruneTime.c)
928 /* We print the dynamic pruning kernel timings after a separator
929 * and avoid adding it to tot_gpu as this is not in the force
930 * overlap. We print the fraction as relative to the rest.
932 print_gputimes(fplog,
934 gpu_nbnxn_t->dynamicPruneTime.c,
935 gpu_nbnxn_t->dynamicPruneTime.t,
937 fprintf(fplog, "%s\n", hline);
939 gpu_cpu_ratio = tot_gpu / tot_cpu_overlap;
940 if (gpu_nbnxn_t->nb_c > 0 && wc->wcc[ewcFORCE].n > 0)
943 "\nAverage per-step force GPU/CPU evaluation time ratio: %.3f ms/%.3f ms = "
945 tot_gpu / gpu_nbnxn_t->nb_c,
946 tot_cpu_overlap / wc->wcc[ewcFORCE].n,
950 /* only print notes related to CPU-GPU load balance with PME */
951 if (wc->wcc[ewcPMEMESH].n > 0)
953 fprintf(fplog, "For optimal resource utilization this ratio should be close to 1\n");
955 /* print note if the imbalance is high with PME case in which
956 * CPU-GPU load balancing is possible */
957 if (gpu_cpu_ratio < 0.8 || gpu_cpu_ratio > 1.25)
959 /* Only the sim master calls this function, so always print to stderr */
960 if (gpu_cpu_ratio < 0.8)
964 /* The user could have used -notunepme,
965 * but we currently can't check that here.
967 GMX_LOG(mdlog.warning)
970 "NOTE: The CPU has >25% more load than the GPU. This "
972 " GPU resources. Maybe the domain decomposition "
973 "limits the PME tuning.\n"
974 " In that case, try setting the DD grid manually "
975 "(-dd) or lowering -dds.");
979 /* We should not end up here, unless the box is
980 * too small for increasing the cut-off for PME tuning.
982 GMX_LOG(mdlog.warning)
985 "NOTE: The CPU has >25% more load than the GPU. This "
990 if (gpu_cpu_ratio > 1.25)
992 GMX_LOG(mdlog.warning)
995 "NOTE: The GPU has >25% more load than the CPU. This imbalance "
1005 GMX_LOG(mdlog.warning)
1008 "MPI_Barrier was called before each cycle start/stop\n"
1009 "call, so timings are not those of real runs.");
1012 if (wc->wcc[ewcNB_XF_BUF_OPS].n > 0 && (cyc_sum[ewcDOMDEC] > tot * 0.1 || cyc_sum[ewcNS] > tot * 0.1))
1014 /* Only the sim master calls this function, so always print to stderr */
1015 if (wc->wcc[ewcDOMDEC].n == 0)
1017 GMX_LOG(mdlog.warning)
1019 .appendTextFormatted(
1020 "NOTE: %d %% of the run time was spent in pair search,\n"
1021 " you might want to increase nstlist (this has no effect on "
1023 gmx::roundToInt(100 * cyc_sum[ewcNS] / tot));
1027 GMX_LOG(mdlog.warning)
1029 .appendTextFormatted(
1030 "NOTE: %d %% of the run time was spent in domain decomposition,\n"
1031 " %d %% of the run time was spent in pair search,\n"
1032 " you might want to increase nstlist (this has no effect on "
1034 gmx::roundToInt(100 * cyc_sum[ewcDOMDEC] / tot),
1035 gmx::roundToInt(100 * cyc_sum[ewcNS] / tot));
1039 if (cyc_sum[ewcMoveE] > tot * 0.05)
1041 GMX_LOG(mdlog.warning)
1043 .appendTextFormatted(
1044 "NOTE: %d %% of the run time was spent communicating energies,\n"
1045 " you might want to increase some nst* mdp options\n",
1046 gmx::roundToInt(100 * cyc_sum[ewcMoveE] / tot));
1050 extern int64_t wcycle_get_reset_counters(gmx_wallcycle_t wc)
1057 return wc->reset_counters;
1060 extern void wcycle_set_reset_counters(gmx_wallcycle_t wc, int64_t reset_counters)
1067 wc->reset_counters = reset_counters;