Fixes seperate PME nodes without LJ-PME
authorBerk Hess <hess@kth.se>
Tue, 25 Feb 2014 06:29:54 +0000 (07:29 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 25 Feb 2014 18:46:16 +0000 (19:46 +0100)
The very recent LJ-PME nbnxn patch dereferenced a NULL pointer
with seperate PME nodes without LJ-PME. Also LJ parameters were
communicated when not needed.

Change-Id: I40bd0c8f96294b54599afee6021139b71cc8c860

src/gromacs/legacyheaders/pme.h
src/gromacs/mdlib/pme_pp.c

index 95597c0b199f293ff80bc0434c74c26ac6a55fe9..b30678c2faf84ed8b9273b27537877fd471ed0ac 100644 (file)
@@ -155,7 +155,8 @@ gmx_pme_pp_t gmx_pme_pp_init(t_commrec *cr);
 void gmx_pme_send_parameters(t_commrec *cr,
                              gmx_bool bFreeEnergy_q, gmx_bool bFreeEnergy_lj,
                              real *chargeA, real *chargeB,
-                             real *c6A, real *c6B, real *sigmaA, real *sigmaB,
+                             real *sqrt_c6A, real *sqrt_c6B,
+                             real *sigmaA, real *sigmaB,
                              int maxshift_x, int maxshift_y);
 /* Send the charges and maxshift to out PME-only node. */
 
@@ -193,7 +194,7 @@ enum {
 int gmx_pme_recv_params_coords(gmx_pme_pp_t pme_pp,
                                int *natoms,
                                real **chargeA, real **chargeB,
-                               real **c6A, real **c6B,
+                               real **sqrt_c6A, real **sqrt_c6B,
                                real **sigmaA, real **sigmaB,
                                matrix box, rvec **x, rvec **f,
                                int *maxshift_x, int *maxshift_y,
index c9cf63deaa23636f7ab1d3f397d4e6371eb41f75..773ad76f8ea432a1b7ac04c5d874c8df12302654 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -55,7 +55,7 @@
 #include "gromacs/utility/gmxmpi.h"
 
 enum {
-    eCommType_ChargeA, eCommType_ChargeB, eCommType_C6A, eCommType_C6B,
+    eCommType_ChargeA, eCommType_ChargeB, eCommType_SQRTC6A, eCommType_SQRTC6B,
     eCommType_SigmaA, eCommType_SigmaB, eCommType_NR, eCommType_COORD,
     eCommType_CNB
 };
@@ -69,8 +69,8 @@ enum {
 
 #define PP_PME_CHARGE         (1<<0)
 #define PP_PME_CHARGEB        (1<<1)
-#define PP_PME_C6             (1<<2)
-#define PP_PME_C6B            (1<<3)
+#define PP_PME_SQRTC6         (1<<2)
+#define PP_PME_SQRTC6B        (1<<3)
 #define PP_PME_SIGMA          (1<<4)
 #define PP_PME_SIGMAB         (1<<5)
 #define PP_PME_COORD          (1<<6)
@@ -95,8 +95,8 @@ typedef struct gmx_pme_pp {
     int          flags_charge; /* The flags sent along with the last charges */
     real        *chargeA;
     real        *chargeB;
-    real        *c6A;
-    real        *c6B;
+    real        *sqrt_c6A;
+    real        *sqrt_c6B;
     real        *sigmaA;
     real        *sigmaB;
     rvec        *x;
@@ -226,7 +226,7 @@ static void gmx_pme_send_params_coords(t_commrec *cr, int flags,
                   &dd->req_pme[dd->nreq_pme++]);
 #endif
     }
-    else if (flags & (PP_PME_CHARGE | PP_PME_C6 | PP_PME_SIGMA))
+    else if (flags & (PP_PME_CHARGE | PP_PME_SQRTC6 | PP_PME_SIGMA))
     {
 #ifdef GMX_MPI
         /* Communicate only the number of atoms */
@@ -251,16 +251,16 @@ static void gmx_pme_send_params_coords(t_commrec *cr, int flags,
                       dd->pme_nodeid, eCommType_ChargeB, cr->mpi_comm_mysim,
                       &dd->req_pme[dd->nreq_pme++]);
         }
-        if (flags & PP_PME_C6)
+        if (flags & PP_PME_SQRTC6)
         {
             MPI_Isend(c6A, n*sizeof(real), MPI_BYTE,
-                      dd->pme_nodeid, eCommType_C6A, cr->mpi_comm_mysim,
+                      dd->pme_nodeid, eCommType_SQRTC6A, cr->mpi_comm_mysim,
                       &dd->req_pme[dd->nreq_pme++]);
         }
-        if (flags & PP_PME_C6B)
+        if (flags & PP_PME_SQRTC6B)
         {
             MPI_Isend(c6B, n*sizeof(real), MPI_BYTE,
-                      dd->pme_nodeid, eCommType_C6B, cr->mpi_comm_mysim,
+                      dd->pme_nodeid, eCommType_SQRTC6B, cr->mpi_comm_mysim,
                       &dd->req_pme[dd->nreq_pme++]);
         }
         if (flags & PP_PME_SIGMA)
@@ -296,12 +296,22 @@ static void gmx_pme_send_params_coords(t_commrec *cr, int flags,
 void gmx_pme_send_parameters(t_commrec *cr,
                              gmx_bool bFreeEnergy_q, gmx_bool bFreeEnergy_lj,
                              real *chargeA, real *chargeB,
-                             real *c6A, real *c6B, real *sigmaA, real *sigmaB,
+                             real *sqrt_c6A, real *sqrt_c6B,
+                             real *sigmaA, real *sigmaB,
                              int maxshift_x, int maxshift_y)
 {
     int flags;
 
-    flags = PP_PME_CHARGE | PP_PME_C6 | PP_PME_SIGMA;
+    /* We always send the charges, even with only LJ- and no Coulomb-PME */
+    flags = PP_PME_CHARGE;
+    if (sqrt_c6A != NULL)
+    {
+        flags |= PP_PME_SQRTC6;
+    }
+    if (sigmaA != NULL)
+    {
+        flags |= PP_PME_SIGMA;
+    }
     if (bFreeEnergy_q || bFreeEnergy_lj)
     {
         /* Assumes that the B state flags are in the bits just above
@@ -309,7 +319,9 @@ void gmx_pme_send_parameters(t_commrec *cr,
         flags |= (flags << 1);
     }
 
-    gmx_pme_send_params_coords(cr, flags, chargeA, chargeB, c6A, c6B, sigmaA, sigmaB,
+    gmx_pme_send_params_coords(cr, flags,
+                               chargeA, chargeB,
+                               sqrt_c6A, sqrt_c6B, sigmaA, sigmaB,
                                NULL, NULL, 0, 0, maxshift_x, maxshift_y, -1);
 }
 
@@ -392,8 +404,8 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
                                int                        *natoms,
                                real                      **chargeA,
                                real                      **chargeB,
-                               real                      **c6A,
-                               real                      **c6B,
+                               real                      **sqrt_c6A,
+                               real                      **sqrt_c6B,
                                real                      **sigmaA,
                                real                      **sigmaB,
                                matrix gmx_unused           box,
@@ -456,7 +468,7 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
             return pmerecvqxRESETCOUNTERS;
         }
 
-        if (cnb.flags & (PP_PME_CHARGE | PP_PME_C6 | PP_PME_SIGMA))
+        if (cnb.flags & (PP_PME_CHARGE | PP_PME_SQRTC6 | PP_PME_SIGMA))
         {
             /* Receive the send counts from the other PP nodes */
             for (sender = 0; sender < pme_pp->nnode; sender++)
@@ -493,13 +505,13 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
                 {
                     srenew(pme_pp->chargeB, pme_pp->nalloc);
                 }
-                if (cnb.flags & PP_PME_C6)
+                if (cnb.flags & PP_PME_SQRTC6)
                 {
-                    srenew(pme_pp->c6A, pme_pp->nalloc);
+                    srenew(pme_pp->sqrt_c6A, pme_pp->nalloc);
                 }
-                if (cnb.flags & PP_PME_C6B)
+                if (cnb.flags & PP_PME_SQRTC6B)
                 {
-                    srenew(pme_pp->c6B, pme_pp->nalloc);
+                    srenew(pme_pp->sqrt_c6B, pme_pp->nalloc);
                 }
                 if (cnb.flags & PP_PME_SIGMA)
                 {
@@ -526,12 +538,12 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
                 }
                 switch (q)
                 {
-                    case eCommType_ChargeA: charge_pp = pme_pp->chargeA; break;
-                    case eCommType_ChargeB: charge_pp = pme_pp->chargeB; break;
-                    case eCommType_C6A:     charge_pp = pme_pp->c6A;     break;
-                    case eCommType_C6B:     charge_pp = pme_pp->c6B;     break;
-                    case eCommType_SigmaA:  charge_pp = pme_pp->sigmaA;  break;
-                    case eCommType_SigmaB:  charge_pp = pme_pp->sigmaB;  break;
+                    case eCommType_ChargeA: charge_pp = pme_pp->chargeA;  break;
+                    case eCommType_ChargeB: charge_pp = pme_pp->chargeB;  break;
+                    case eCommType_SQRTC6A: charge_pp = pme_pp->sqrt_c6A; break;
+                    case eCommType_SQRTC6B: charge_pp = pme_pp->sqrt_c6B; break;
+                    case eCommType_SigmaA:  charge_pp = pme_pp->sigmaA;   break;
+                    case eCommType_SigmaB:  charge_pp = pme_pp->sigmaB;   break;
                     default: gmx_incons("Wrong eCommType");
                 }
                 nat = 0;
@@ -561,7 +573,7 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
 
         if (cnb.flags & PP_PME_COORD)
         {
-            if (!(pme_pp->flags_charge & (PP_PME_CHARGE | PP_PME_C6)))
+            if (!(pme_pp->flags_charge & (PP_PME_CHARGE | PP_PME_SQRTC6)))
             {
                 gmx_incons("PME-only node received coordinates before charges and/or C6-values"
                            );
@@ -583,7 +595,7 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
                            "did not receive B-state charges");
             }
 
-            if (*bFreeEnergy_lj && !(pme_pp->flags_charge & PP_PME_C6B))
+            if (*bFreeEnergy_lj && !(pme_pp->flags_charge & PP_PME_SQRTC6B))
             {
                 gmx_incons("PME-only node received free energy request, but "
                            "did not receive B-state C6-values");
@@ -619,15 +631,15 @@ int gmx_pme_recv_params_coords(struct gmx_pme_pp          *pme_pp,
     *step = cnb.step;
 #endif
 
-    *natoms  = nat;
-    *chargeA = pme_pp->chargeA;
-    *chargeB = pme_pp->chargeB;
-    *c6A     = pme_pp->c6A;
-    *c6B     = pme_pp->c6B;
-    *sigmaA  = pme_pp->sigmaA;
-    *sigmaB  = pme_pp->sigmaB;
-    *x       = pme_pp->x;
-    *f       = pme_pp->f;
+    *natoms   = nat;
+    *chargeA  = pme_pp->chargeA;
+    *chargeB  = pme_pp->chargeB;
+    *sqrt_c6A = pme_pp->sqrt_c6A;
+    *sqrt_c6B = pme_pp->sqrt_c6B;
+    *sigmaA   = pme_pp->sigmaA;
+    *sigmaB   = pme_pp->sigmaB;
+    *x        = pme_pp->x;
+    *f        = pme_pp->f;
 
     return ((cnb.flags & PP_PME_FINISH) ? pmerecvqxFINISH : pmerecvqxX);
 }