improved load balancing with Verlet cut-off scheme
authorBerk Hess <hess@kth.se>
Fri, 12 Apr 2013 12:47:34 +0000 (14:47 +0200)
committerBerk Hess <hess@kth.se>
Fri, 12 Apr 2013 12:50:43 +0000 (14:50 +0200)
With the Verlet scheme the force calculation order is now like group:
non-bonded, bonded, PME
The non-bonded were done after PME, which prevented load balancing,
unless separate PME nodes were used.

Change-Id: I81588ac810ce7c022bd6809f29a19c41ba13449f

src/mdlib/sim_util.c

index 4156a0b1b1c897042a56c4fb011d0ed76c4968f7..72251d78bbe2b7a4ac85f39245c8bb637c3bd3ee 100644 (file)
@@ -1162,42 +1162,18 @@ void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
 
         GMX_BARRIER(cr->mpi_comm_mygroup);
     }
+
     if (inputrec->ePull == epullCONSTRAINT)
     {
         clear_pull_forces(inputrec->pull);
     }
 
-    /* update QMMMrec, if necessary */
-    if (fr->bQMMM)
-    {
-        update_QMMMrec(cr, fr, x, mdatoms, box, top);
-    }
-
-    if ((flags & GMX_FORCE_BONDED) && top->idef.il[F_POSRES].nr > 0)
-    {
-        posres_wrapper(fplog, flags, bSepDVDL, inputrec, nrnb, top, box, x,
-                       f, enerd, lambda, fr);
-    }
-
-    /* Compute the bonded and non-bonded energies and optionally forces */
-    do_force_lowlevel(fplog, step, fr, inputrec, &(top->idef),
-                      cr, nrnb, wcycle, mdatoms, &(inputrec->opts),
-                      x, hist, f, bSepLRF ? fr->f_twin : f, enerd, fcd, mtop, top, fr->born,
-                      &(top->atomtypes), bBornRadii, box,
-                      inputrec->fepvals, lambda, graph, &(top->excls), fr->mu_tot,
-                      flags, &cycles_pme);
-
-    if (bSepLRF)
-    {
-        if (do_per_step(step, inputrec->nstcalclr))
-        {
-            /* Add the long range forces to the short range forces */
-            for (i = 0; i < fr->natoms_force_constr; i++)
-            {
-                rvec_add(fr->f_twin[i], f[i], f[i]);
-            }
-        }
-    }
+    /* We calculate the non-bonded forces, when done on the CPU, here.
+     * We do this before calling do_force_lowlevel, as in there bondeds
+     * forces are calculated before PME, which does communication.
+     * With this order, non-bonded and bonded force calculation imbalance
+     * can be balanced out by the domain decomposition load balancing.
+     */
 
     if (!bUseOrEmulGPU)
     {
@@ -1206,7 +1182,6 @@ void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
                      nrnb, wcycle);
     }
 
-
     if (!bUseOrEmulGPU || bDiffKernels)
     {
         int aloc;
@@ -1248,6 +1223,38 @@ void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         }
     }
 
+    /* update QMMMrec, if necessary */
+    if (fr->bQMMM)
+    {
+        update_QMMMrec(cr, fr, x, mdatoms, box, top);
+    }
+
+    if ((flags & GMX_FORCE_BONDED) && top->idef.il[F_POSRES].nr > 0)
+    {
+        posres_wrapper(fplog, flags, bSepDVDL, inputrec, nrnb, top, box, x,
+                       f, enerd, lambda, fr);
+    }
+
+    /* Compute the bonded and non-bonded energies and optionally forces */
+    do_force_lowlevel(fplog, step, fr, inputrec, &(top->idef),
+                      cr, nrnb, wcycle, mdatoms, &(inputrec->opts),
+                      x, hist, f, bSepLRF ? fr->f_twin : f, enerd, fcd, mtop, top, fr->born,
+                      &(top->atomtypes), bBornRadii, box,
+                      inputrec->fepvals, lambda, graph, &(top->excls), fr->mu_tot,
+                      flags, &cycles_pme);
+
+    if (bSepLRF)
+    {
+        if (do_per_step(step, inputrec->nstcalclr))
+        {
+            /* Add the long range forces to the short range forces */
+            for (i = 0; i < fr->natoms_force_constr; i++)
+            {
+                rvec_add(fr->f_twin[i], f[i], f[i]);
+            }
+        }
+    }
+
     cycles_force += wallcycle_stop(wcycle, ewcFORCE);
     GMX_BARRIER(cr->mpi_comm_mygroup);