Merge branch release-2016
authorBerk Hess <hess@kth.se>
Fri, 16 Sep 2016 11:40:25 +0000 (13:40 +0200)
committerBerk Hess <hess@kth.se>
Fri, 16 Sep 2016 11:41:08 +0000 (13:41 +0200)
Change-Id: I0c8c02d4fbd56042ad77e7b646323b2570d06c7c

1  2 
docs/dev-manual/build-system.rst
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/mdlib/force.cpp
src/gromacs/mdlib/minimize.cpp

index a6762a5d8315a1d86e6a606688da8c57eb6ac9f3,a86c6cebd6306492d2fe00548329d4767d4c0c9c..ae313c1bfbf1d1340de416bd147c46d3a12cceb2
@@@ -4,7 -4,7 +4,7 @@@ Build system overvie
  =====================
  
  The |Gromacs| build system uses CMake (version
 -|GMX_CMAKE_MINIMUM_REQUIRED_VERSION| or newer is required) to generate the
 +|CMAKE_MINIMUM_REQUIRED_VERSION| or newer is required) to generate the
  actual build system for the build tool choosen by the user.  See CMake
  documentation for general introduction to CMake and how to use it.  This
  documentation focuses on how the |Gromacs| build system is organized and
@@@ -202,6 -202,12 +202,12 @@@ Variables affecting compilation/linkin
  
  .. cmake:: GMX_CYCLE_SUBCOUNTERS
  
+    If set to ``ON``, enables performance subcounters that offer more
+    fine-grained mdrun performance measurement and evaluation than the default
+    counters. See :doc:`/user-guide/mdrun-performance` for the description of
+    subcounters which are available.
+    Defaults to ``OFF``.
  .. cmake:: GMX_DATA_INSTALL_DIR
  
     Sets the directory under :file:`share/` where data files are installed.
index 9b8dd632e273d90e2eddea4e901950da34f015e5,94dc678cda99126a2d2c54e5054c361899d2be17..58413e45eaf951785c97162559a9eb03c351ca92
@@@ -204,7 -204,7 +204,7 @@@ static void check_viol(FILE *log
          while (((i+n) < disres->nr) &&
                 (forceparams[forceatoms[i+n]].disres.label == label));
  
-         calc_disres_R_6(n, &forceatoms[i], forceparams,
+         calc_disres_R_6(NULL, n, &forceatoms[i],
                          (const rvec*)x, pbc, fcd, NULL);
  
          if (fcd->disres.Rt_6[0] <= 0)
@@@ -839,7 -839,7 +839,7 @@@ int gmx_disre(int argc, char *argv[]
      }
  
      mdatoms = init_mdatoms(fplog, &mtop, ir.efep != efepNO);
 -    atoms2md(&mtop, &ir, 0, NULL, mtop.natoms, mdatoms);
 +    atoms2md(&mtop, &ir, -1, NULL, mtop.natoms, mdatoms);
      update_mdatoms(mdatoms, ir.fepvals->init_lambda);
      init_nrnb(&nrnb);
      if (ir.ePBC != epbcNONE)
index cf842a9a0c1c99e3f7990ea27a1abd549d9cfd69,fa592e1993b0a7736fe2c524975858c6f2c0bf29..30c0ed7ecf18cb2e41d7034573105ebf8781802c
@@@ -359,7 -359,7 +359,7 @@@ void do_force_lowlevel(t_forcerec *fr
                     TRUE, box);
      }
  
-     do_force_listed(wcycle, box, ir->fepvals, cr->ms,
+     do_force_listed(wcycle, box, ir->fepvals, cr,
                      idef, (const rvec *) x, hist, f, fr,
                      &pbc, graph, enerd, nrnb, lambda, md, fcd,
                      DOMAINDECOMP(cr) ? cr->dd->gatindex : NULL,
                  if (fr->n_tpi == 0 || (flags & GMX_FORCE_STATECHANGED))
                  {
                      pme_flags = GMX_PME_SPREAD | GMX_PME_SOLVE;
 -                    if (EEL_PME(fr->eeltype))
 -                    {
 -                        pme_flags     |= GMX_PME_DO_COULOMB;
 -                    }
 -                    if (EVDW_PME(fr->vdwtype))
 -                    {
 -                        pme_flags |= GMX_PME_DO_LJ;
 -                    }
 +
                      if (flags & GMX_FORCE_FORCES)
                      {
                          pme_flags |= GMX_PME_CALC_F;
                                          DOMAINDECOMP(cr) ? dd_pme_maxshift_x(cr->dd) : 0,
                                          DOMAINDECOMP(cr) ? dd_pme_maxshift_y(cr->dd) : 0,
                                          nrnb, wcycle,
 -                                        fr->vir_el_recip, fr->ewaldcoeff_q,
 -                                        fr->vir_lj_recip, fr->ewaldcoeff_lj,
 +                                        fr->vir_el_recip, fr->vir_lj_recip,
                                          &Vlr_q, &Vlr_lj,
                                          lambda[efptCOUL], lambda[efptVDW],
                                          &dvdl_long_range_q, &dvdl_long_range_lj, pme_flags);
index 8f8e76ddf5e7d48b1c11259fced42d45c32c0edb,2d5290d4b9502a9d1f900089717a5b1578c490ed..0246bfba100ca6fe6aaf7d2f274234bbd336b6b4
@@@ -61,6 -61,7 +61,6 @@@
  #include "gromacs/ewald/pme.h"
  #include "gromacs/fileio/confio.h"
  #include "gromacs/fileio/mtxio.h"
 -#include "gromacs/gmxlib/md_logging.h"
  #include "gromacs/gmxlib/network.h"
  #include "gromacs/gmxlib/nrnb.h"
  #include "gromacs/imd/imd.h"
@@@ -76,7 -77,6 +76,7 @@@
  #include "gromacs/mdlib/mdatoms.h"
  #include "gromacs/mdlib/mdebin.h"
  #include "gromacs/mdlib/mdrun.h"
 +#include "gromacs/mdlib/mdsetup.h"
  #include "gromacs/mdlib/ns.h"
  #include "gromacs/mdlib/shellfc.h"
  #include "gromacs/mdlib/sim_util.h"
  #include "gromacs/timing/wallcycle.h"
  #include "gromacs/timing/walltime_accounting.h"
  #include "gromacs/topology/mtop_util.h"
 +#include "gromacs/topology/topology.h"
  #include "gromacs/utility/cstringutil.h"
  #include "gromacs/utility/exceptions.h"
  #include "gromacs/utility/fatalerror.h"
 +#include "gromacs/utility/logger.h"
  #include "gromacs/utility/smalloc.h"
  
  //! Utility structure for manipulating states during EM
@@@ -340,7 -338,7 +340,7 @@@ void init_em(FILE *fplog, const char *t
               t_nrnb *nrnb, rvec mu_tot,
               t_forcerec *fr, gmx_enerdata_t **enerd,
               t_graph **graph, t_mdatoms *mdatoms, gmx_global_stat_t *gstat,
 -             gmx_vsite_t *vsite, gmx_constr_t constr,
 +             gmx_vsite_t *vsite, gmx_constr_t constr, gmx_shellfc_t **shellfc,
               int nfile, const t_filenm fnm[],
               gmx_mdoutf_t *outf, t_mdebin **mdebin,
               int imdport, unsigned long gmx_unused Flags,
      init_IMD(ir, cr, top_global, fplog, 1, state_global->x,
               nfile, fnm, NULL, imdport, Flags);
  
 +    if (ir->eI == eiNM)
 +    {
 +        GMX_ASSERT(shellfc != NULL, "With NM we always support shells");
 +
 +        *shellfc = init_shell_flexcon(stdout,
 +                                      top_global,
 +                                      n_flexible_constraints(constr),
 +                                      ir->nstcalcenergy,
 +                                      DOMAINDECOMP(cr));
 +    }
 +    else
 +    {
 +        GMX_ASSERT(EI_ENERGY_MINIMIZATION(ir->eI), "This else currently only handles energy minimizers, consider if your algorithm needs shell/flexible-constraint support");
 +
 +        /* With energy minimization, shells and flexible constraints are
 +         * automatically minimized when treated like normal DOFS.
 +         */
 +        if (shellfc != NULL)
 +        {
 +            *shellfc = NULL;
 +        }
 +    }
 +
      if (DOMAINDECOMP(cr))
      {
          *top = dd_init_local_top(top_global);
          }
          copy_mat(state_global->box, ems->s.box);
  
 -        *top      = gmx_mtop_generate_local_top(top_global, ir->efep != efepNO);
  
 -        setup_bonded_threading(fr, &(*top)->idef);
 +        snew(*top, 1);
 +        mdAlgorithmsSetupAtomData(cr, ir, top_global, *top, fr,
 +                                  graph, mdatoms,
 +                                  vsite, shellfc ? *shellfc : NULL);
  
 -        if (ir->ePBC != epbcNONE && !fr->bMolPBC)
 -        {
 -            *graph = mk_graph(fplog, &((*top)->idef), 0, top_global->natoms, FALSE, FALSE);
 -        }
 -        else
 -        {
 -            *graph = NULL;
 -        }
 -
 -        atoms2md(top_global, ir, 0, NULL, top_global->natoms, mdatoms);
          update_mdatoms(mdatoms, state_global->lambda[efptFEP]);
  
          if (vsite)
@@@ -597,9 -580,7 +597,7 @@@ static bool do_em_step(t_commrec *cr, t
  
  {
      t_state *s1, *s2;
-     int      i;
      int      start, end;
-     rvec    *x1, *x2;
      real     dvdl_constr;
      int      nthreads gmx_unused;
  
      s2->natoms = s1->natoms;
      copy_mat(s1->box, s2->box);
      /* Copy free energy state */
-     for (i = 0; i < efptNR; i++)
+     for (int i = 0; i < efptNR; i++)
      {
          s2->lambda[i] = s1->lambda[i];
      }
      start = 0;
      end   = md->homenr;
  
-     x1 = s1->x;
-     x2 = s2->x;
      // cppcheck-suppress unreadVariable
      nthreads = gmx_omp_nthreads_get(emntUpdate);
  #pragma omp parallel num_threads(nthreads)
      {
-         int gf, i, m;
+         rvec *x1 = s1->x;
+         rvec *x2 = s2->x;
  
-         gf = 0;
+         int   gf = 0;
  #pragma omp for schedule(static) nowait
-         for (i = start; i < end; i++)
+         for (int i = start; i < end; i++)
          {
              try
              {
                  {
                      gf = md->cFREEZE[i];
                  }
-                 for (m = 0; m < DIM; m++)
+                 for (int m = 0; m < DIM; m++)
                  {
                      if (ir->opts.nFreeze[gf][m])
                      {
          if (s2->flags & (1<<estCGP))
          {
              /* Copy the CG p vector */
-             x1 = s1->cg_p;
-             x2 = s2->cg_p;
+             rvec *p1 = s1->cg_p;
+             rvec *p2 = s2->cg_p;
  #pragma omp for schedule(static) nowait
-             for (i = start; i < end; i++)
+             for (int i = start; i < end; i++)
              {
                  // Trivial OpenMP block that does not throw
-                 copy_rvec(x1[i], x2[i]);
+                 copy_rvec(p1[i], p2[i]);
              }
          }
  
              }
              s2->ncg_gl = s1->ncg_gl;
  #pragma omp for schedule(static) nowait
-             for (i = 0; i < s2->ncg_gl; i++)
+             for (int i = 0; i < s2->ncg_gl; i++)
              {
                  s2->cg_gl[i] = s1->cg_gl[i];
              }
@@@ -1016,7 -995,7 +1012,7 @@@ namespace gm
  {
  
  /*! \brief Do conjugate gradients minimization
 -    \copydoc integrator_t (FILE *fplog, t_commrec *cr,
 +    \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                             int nfile, const t_filenm fnm[],
                             const gmx_output_env_t *oenv, gmx_bool bVerbose,
                             int nstglobalcomm,
                             unsigned long Flags,
                             gmx_walltime_accounting_t walltime_accounting)
   */
 -double do_cg(FILE *fplog, t_commrec *cr,
 +double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
               int nfile, const t_filenm fnm[],
               const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
               int gmx_unused nstglobalcomm,
      /* Init em and store the local state in s_min */
      init_em(fplog, CG, cr, inputrec,
              state_global, top_global, s_min, &top, &f,
 -            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr,
 +            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
 +            vsite, constr, NULL,
              nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle);
  
      /* Print to log file */
  
  
  /*! \brief Do L-BFGS conjugate gradients minimization
 -    \copydoc integrator_t (FILE *fplog, t_commrec *cr,
 -                           int nfile, const t_filenm fnm[],
 -                           const gmx_output_env_t *oenv, gmx_bool bVerbose,
 -                           int nstglobalcomm,
 -                           gmx_vsite_t *vsite, gmx_constr_t constr,
 -                           int stepout,
 -                           t_inputrec *inputrec,
 -                           gmx_mtop_t *top_global, t_fcdata *fcd,
 -                           t_state *state_global,
 -                           t_mdatoms *mdatoms,
 -                           t_nrnb *nrnb, gmx_wallcycle_t wcycle,
 -                           gmx_edsam_t ed,
 -                           t_forcerec *fr,
 -                           int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
 -                           real cpt_period, real max_hours,
 -                           int imdport,
 -                           unsigned long Flags,
 -                           gmx_walltime_accounting_t walltime_accounting)
 +    \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 +                          int nfile, const t_filenm fnm[],
 +                          const gmx_output_env_t *oenv, gmx_bool bVerbose,
 +                          int nstglobalcomm,
 +                          gmx_vsite_t *vsite, gmx_constr_t constr,
 +                          int stepout,
 +                          t_inputrec *inputrec,
 +                          gmx_mtop_t *top_global, t_fcdata *fcd,
 +                          t_state *state_global,
 +                          t_mdatoms *mdatoms,
 +                          t_nrnb *nrnb, gmx_wallcycle_t wcycle,
 +                          gmx_edsam_t ed,
 +                          t_forcerec *fr,
 +                          int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
 +                          real cpt_period, real max_hours,
 +                          int imdport,
 +                          unsigned long Flags,
 +                          gmx_walltime_accounting_t walltime_accounting)
   */
 -double do_lbfgs(FILE *fplog, t_commrec *cr,
 +double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                  int nfile, const t_filenm fnm[],
                  const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
                  int gmx_unused nstglobalcomm,
      /* Init em */
      init_em(fplog, LBFGS, cr, inputrec,
              state_global, top_global, &ems, &top, &f,
 -            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr,
 +            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
 +            vsite, constr, NULL,
              nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle);
      /* Do_lbfgs is not completely updated like do_steep and do_cg,
       * so we free some memory again.
  }   /* That's all folks */
  
  /*! \brief Do steepest descents minimization
 -    \copydoc integrator_t (FILE *fplog, t_commrec *cr,
 -                           int nfile, const t_filenm fnm[],
 -                           const gmx_output_env_t *oenv, gmx_bool bVerbose,
 -                           int nstglobalcomm,
 -                           gmx_vsite_t *vsite, gmx_constr_t constr,
 -                           int stepout,
 -                           t_inputrec *inputrec,
 -                           gmx_mtop_t *top_global, t_fcdata *fcd,
 -                           t_state *state_global,
 -                           t_mdatoms *mdatoms,
 -                           t_nrnb *nrnb, gmx_wallcycle_t wcycle,
 -                           gmx_edsam_t ed,
 -                           t_forcerec *fr,
 -                           int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
 -                           real cpt_period, real max_hours,
 -                           int imdport,
 -                           unsigned long Flags,
 -                           gmx_walltime_accounting_t walltime_accounting)
 +    \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 +                          int nfile, const t_filenm fnm[],
 +                          const gmx_output_env_t *oenv, gmx_bool bVerbose,
 +                          int nstglobalcomm,
 +                          gmx_vsite_t *vsite, gmx_constr_t constr,
 +                          int stepout,
 +                          t_inputrec *inputrec,
 +                          gmx_mtop_t *top_global, t_fcdata *fcd,
 +                          t_state *state_global,
 +                          t_mdatoms *mdatoms,
 +                          t_nrnb *nrnb, gmx_wallcycle_t wcycle,
 +                          gmx_edsam_t ed,
 +                          t_forcerec *fr,
 +                          int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
 +                          real cpt_period, real max_hours,
 +                          int imdport,
 +                          unsigned long Flags,
 +                          gmx_walltime_accounting_t walltime_accounting)
   */
 -double do_steep(FILE *fplog, t_commrec *cr,
 +double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                  int nfile, const t_filenm fnm[],
                  const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
                  int gmx_unused nstglobalcomm,
      /* Init em and store the local state in s_try */
      init_em(fplog, SD, cr, inputrec,
              state_global, top_global, s_try, &top, &f,
 -            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr,
 +            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
 +            vsite, constr, NULL,
              nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle);
  
      /* Print to log file  */
  }   /* That's all folks */
  
  /*! \brief Do normal modes analysis
 -    \copydoc integrator_t (FILE *fplog, t_commrec *cr,
 -                           int nfile, const t_filenm fnm[],
 -                           const gmx_output_env_t *oenv, gmx_bool bVerbose,
 -                           int nstglobalcomm,
 -                           gmx_vsite_t *vsite, gmx_constr_t constr,
 -                           int stepout,
 -                           t_inputrec *inputrec,
 -                           gmx_mtop_t *top_global, t_fcdata *fcd,
 -                           t_state *state_global,
 -                           t_mdatoms *mdatoms,
 -                           t_nrnb *nrnb, gmx_wallcycle_t wcycle,
 -                           gmx_edsam_t ed,
 -                           t_forcerec *fr,
 -                           int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
 -                           real cpt_period, real max_hours,
 -                           int imdport,
 -                           unsigned long Flags,
 -                           gmx_walltime_accounting_t walltime_accounting)
 +    \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 +                          int nfile, const t_filenm fnm[],
 +                          const gmx_output_env_t *oenv, gmx_bool bVerbose,
 +                          int nstglobalcomm,
 +                          gmx_vsite_t *vsite, gmx_constr_t constr,
 +                          int stepout,
 +                          t_inputrec *inputrec,
 +                          gmx_mtop_t *top_global, t_fcdata *fcd,
 +                          t_state *state_global,
 +                          t_mdatoms *mdatoms,
 +                          t_nrnb *nrnb, gmx_wallcycle_t wcycle,
 +                          gmx_edsam_t ed,
 +                          t_forcerec *fr,
 +                          int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
 +                          real cpt_period, real max_hours,
 +                          int imdport,
 +                          unsigned long Flags,
 +                          gmx_walltime_accounting_t walltime_accounting)
   */
 -double do_nm(FILE *fplog, t_commrec *cr,
 +double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
               int nfile, const t_filenm fnm[],
               const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
               int gmx_unused nstglobalcomm,
  
      state_work = init_em_state();
  
 +    gmx_shellfc_t *shellfc;
 +
      /* Init em and store the local state in state_minimum */
      init_em(fplog, NM, cr, inputrec,
              state_global, top_global, state_work, &top,
              &f,
 -            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr,
 +            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
 +            vsite, constr, &shellfc,
              nfile, fnm, &outf, NULL, imdport, Flags, wcycle);
  
 -    gmx_shellfc_t *shellfc = init_shell_flexcon(stdout,
 -                                                top_global,
 -                                                n_flexible_constraints(constr),
 -                                                inputrec->nstcalcenergy,
 -                                                DOMAINDECOMP(cr));
 -
 -    if (shellfc)
 -    {
 -        make_local_shells(cr, mdatoms, shellfc);
 -    }
      std::vector<size_t> atom_index = get_atom_index(top_global);
      snew(fneg, atom_index.size());
      snew(dfdx, atom_index.size());
       */
      if (EEL_FULL(fr->eeltype) || fr->rlist == 0.0)
      {
 -        md_print_info(cr, fplog, "Non-cutoff electrostatics used, forcing full Hessian format.\n");
 +        GMX_LOG(mdlog.warning).appendText("Non-cutoff electrostatics used, forcing full Hessian format.");
          bSparse = FALSE;
      }
      else if (atom_index.size() < 1000)
      {
 -        md_print_info(cr, fplog, "Small system size (N=%d), using full Hessian format.\n", atom_index.size());
 +        GMX_LOG(mdlog.warning).appendTextFormatted("Small system size (N=%d), using full Hessian format.",
 +                                                   atom_index.size());
          bSparse = FALSE;
      }
      else
      {
 -        md_print_info(cr, fplog, "Using compressed symmetric sparse Hessian format.\n");
 +        GMX_LOG(mdlog.warning).appendText("Using compressed symmetric sparse Hessian format.");
          bSparse = TRUE;
      }
  
      /* if forces are not small, warn user */
      get_state_f_norm_max(cr, &(inputrec->opts), mdatoms, state_work);
  
 -    md_print_info(cr, fplog, "Maximum force:%12.5e\n", state_work->fmax);
 +    GMX_LOG(mdlog.warning).appendTextFormatted("Maximum force:%12.5e", state_work->fmax);
      if (state_work->fmax > 1.0e-3)
      {
 -        md_print_info(cr, fplog,
 -                      "The force is probably not small enough to "
 -                      "ensure that you are at a minimum.\n"
 -                      "Be aware that negative eigenvalues may occur\n"
 -                      "when the resulting matrix is diagonalized.\n\n");
 +        GMX_LOG(mdlog.warning).appendText(
 +                "The force is probably not small enough to "
 +                "ensure that you are at a minimum.\n"
 +                "Be aware that negative eigenvalues may occur\n"
 +                "when the resulting matrix is diagonalized.");
      }
  
      /***********************************************************