+ pme_lb->bBalance = dd_dlb_is_on(cr->dd);
+ }
+ else
+ {
+ if (DDMASTER(cr->dd))
+ {
+ /* PME node load is too high, start tuning */
+ pme_lb->bBalance =
+ (dd_pme_f_ratio(cr->dd) >= loadBalanceTriggerFactor);
+ }
+ dd_bcast(cr->dd, sizeof(gmx_bool), &pme_lb->bBalance);
+ }
+
+ pme_lb->bActive = (pme_lb->bBalance ||
+ step_rel <= pme_lb->step_rel_stop);
+ }
+
+ /* The location in the code of this balancing termination is strange.
+ * You would expect to have it after the call to pme_load_balance()
+ * below, since there pme_lb->stage is updated.
+ * But when terminating directly after deciding on and selecting the
+ * optimal setup, DLB will turn on right away if it was locked before.
+ * This might be due to PME reinitialization. So we check stage here
+ * to allow for another nstlist steps with DLB locked to stabilize
+ * the performance.
+ */
+ if (pme_lb->bBalance && pme_lb->stage == pme_lb->nstage)
+ {
+ pme_lb->bBalance = FALSE;
+
+ if (DOMAINDECOMP(cr) && dd_dlb_is_locked(cr->dd))
+ {
+ /* Unlock the DLB=auto, DLB is allowed to activate */
+ dd_dlb_unlock(cr->dd);
+ md_print_warn(cr, fp_log, "NOTE: DLB can now turn on, when beneficial\n");
+
+ /* We don't deactivate the tuning yet, since we will balance again
+ * after DLB gets turned on, if it does within PMETune_period.
+ */
+ continue_pme_loadbal(pme_lb, TRUE);
+ pme_lb->bTriggerOnDLB = TRUE;
+ pme_lb->step_rel_stop = step_rel + PMETunePeriod*ir->nstlist;
+ }
+ else
+ {
+ /* We're completely done with PME tuning */
+ pme_lb->bActive = FALSE;