Merge branch release-5-1
[alexxy/gromacs.git] / src / gromacs / ewald / pme.cpp
index 353cfa02218b52a82e2a17cd83c27e68deb8a431..81db679a23b7a1b0906da625a0e98270348d7400 100644 (file)
@@ -927,6 +927,7 @@ int gmx_pme_do(struct gmx_pme_t *pme,
     int                  fep_state;
     int                  fep_states_lj           = pme->bFEP_lj ? 2 : 1;
     const gmx_bool       bCalcEnerVir            = flags & GMX_PME_CALC_ENER_VIR;
+    const gmx_bool       bBackFFT                = flags & (GMX_PME_CALC_F | GMX_PME_CALC_POT);
     const gmx_bool       bCalcF                  = flags & GMX_PME_CALC_F;
 
     assert(pme->nnodes > 0);
@@ -1140,7 +1141,7 @@ int gmx_pme_do(struct gmx_pme_t *pme,
                     }
                 }
 
-                if (bCalcF)
+                if (bBackFFT)
                 {
                     /* do 3d-invfft */
                     if (thread == 0)
@@ -1177,7 +1178,7 @@ int gmx_pme_do(struct gmx_pme_t *pme,
          * With MPI we have to synchronize here before gmx_sum_qgrid_dd.
          */
 
-        if (bCalcF)
+        if (bBackFFT)
         {
             /* distribute local grid to all nodes */
 #if GMX_MPI
@@ -1189,7 +1190,10 @@ int gmx_pme_do(struct gmx_pme_t *pme,
             where();
 
             unwrap_periodic_pmegrid(pme, grid);
+        }
 
+        if (bCalcF)
+        {
             /* interpolate forces for our local atoms */
 
             where();
@@ -1417,7 +1421,7 @@ int gmx_pme_do(struct gmx_pme_t *pme,
                 get_pme_ener_vir_lj(pme->solve_work, pme->nthread, &energy_AB[2+fep_state], vir_AB[2+fep_state]);
             }
 
-            if (bCalcF)
+            if (bBackFFT)
             {
                 bFirst = !(flags & GMX_PME_DO_COULOMB);
                 calc_initial_lb_coeffs(pme, local_c6, local_sigma);
@@ -1475,26 +1479,31 @@ int gmx_pme_do(struct gmx_pme_t *pme,
 
                     unwrap_periodic_pmegrid(pme, grid);
 
-                    /* interpolate forces for our local atoms */
-                    where();
-                    bClearF = (bFirst && PAR(cr));
-                    scale   = pme->bFEP ? (fep_state < 1 ? 1.0-lambda_lj : lambda_lj) : 1.0;
-                    scale  *= lb_scale_factor[grid_index-2];
-#pragma omp parallel for num_threads(pme->nthread) schedule(static)
-                    for (thread = 0; thread < pme->nthread; thread++)
+                    if (bCalcF)
                     {
-                        try
+                        /* interpolate forces for our local atoms */
+                        where();
+                        bClearF = (bFirst && PAR(cr));
+                        scale   = pme->bFEP ? (fep_state < 1 ? 1.0-lambda_lj : lambda_lj) : 1.0;
+                        scale  *= lb_scale_factor[grid_index-2];
+
+#pragma omp parallel for num_threads(pme->nthread) schedule(static)
+                        for (thread = 0; thread < pme->nthread; thread++)
                         {
-                            gather_f_bsplines(pme, grid, bClearF, &pme->atc[0],
-                                              &pme->atc[0].spline[thread],
-                                              scale);
+                            try
+                            {
+                                gather_f_bsplines(pme, grid, bClearF, &pme->atc[0],
+                                                  &pme->atc[0].spline[thread],
+                                                  scale);
+                            }
+                            GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
                         }
-                        GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
-                    }
-                    where();
 
-                    inc_nrnb(nrnb, eNR_GATHERFBSP,
-                             pme->pme_order*pme->pme_order*pme->pme_order*pme->atc[0].n);
+                        where();
+
+                        inc_nrnb(nrnb, eNR_GATHERFBSP,
+                                 pme->pme_order*pme->pme_order*pme->pme_order*pme->atc[0].n);
+                    }
                     wallcycle_stop(wcycle, ewcPME_SPREADGATHER);
 
                     bFirst = FALSE;