Commit 65e33d97 authored by Mark Abraham's avatar Mark Abraham Committed by Gerrit Code Review
Browse files

Separate table construction

Construction of tables for the group scheme, pair interactions and
dispersion correction are now separated. The resulting tables are
never re-used for something else. This uses slightly more memory, but
makes the logic rather more simple. Some of the tables are now held by
reference by their owners, rather than by value, which might improve
cache locality a little.

With this change, we can implement the table support for the Verlet
scheme without getting involved with the group-scheme code, and will
have an easier time removing the group scheme.

Refs #1666, #1852

Change-Id: I8ca608f0e41b02723e6080b80b04d9e7ff048900
parent 3a97f29a
......@@ -53,6 +53,7 @@
#include <algorithm>
#include "gromacs/listed-forces/pairs.h"
#include "gromacs/math/functions.h"
#include "gromacs/math/units.h"
#include "gromacs/math/utilities.h"
......@@ -70,7 +71,6 @@
#include "gromacs/utility/smalloc.h"
#include "listed-internal.h"
#include "pairs.h"
#include "restcbt.h"
using namespace gmx; // TODO: Remove when this file is moved into gmx namespace
......
......@@ -56,6 +56,7 @@
#include "gromacs/listed-forces/bonded.h"
#include "gromacs/listed-forces/disre.h"
#include "gromacs/listed-forces/orires.h"
#include "gromacs/listed-forces/pairs.h"
#include "gromacs/listed-forces/position-restraints.h"
#include "gromacs/math/vec.h"
#include "gromacs/mdlib/force.h"
......@@ -74,7 +75,6 @@
#include "gromacs/utility/smalloc.h"
#include "listed-internal.h"
#include "pairs.h"
namespace
{
......
/*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2014,2015, by the GROMACS development team, led by
* Copyright (c) 2014,2015,2016, 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.
......@@ -411,7 +411,7 @@ do_pairs(int ftype, int nbonds,
the table layout, which should be made explicit in future
cleanup. */
GMX_ASSERT(etiNR == 3, "Pair-interaction code that uses GROMACS interaction tables supports exactly 3 tables");
GMX_ASSERT(fr->tab14->interaction == GMX_TABLE_INTERACTION_ELEC_VDWREP_VDWDISP,
GMX_ASSERT(fr->pairsTable->interaction == GMX_TABLE_INTERACTION_ELEC_VDWREP_VDWDISP,
"Pair interaction kernels need a table with Coulomb, repulsion and dispersion entries");
bFreeEnergy = FALSE;
......@@ -471,13 +471,13 @@ do_pairs(int ftype, int nbonds,
}
r2 = norm2(dx);
if (r2 >= fr->tab14->r*fr->tab14->r)
if (r2 >= fr->pairsTable->r*fr->pairsTable->r)
{
/* This check isn't race free. But it doesn't matter because if a race occurs the only
* disadvantage is that the warning is printed twice */
if (warned_rlimit == FALSE)
{
warning_rlimit(x, ai, aj, global_atom_index, sqrt(r2), fr->tab14->r);
warning_rlimit(x, ai, aj, global_atom_index, sqrt(r2), fr->pairsTable->r);
warned_rlimit = TRUE;
}
continue;
......@@ -491,7 +491,7 @@ do_pairs(int ftype, int nbonds,
c12B = iparams[itype].lj14.c12B*12.0;
fscal = free_energy_evaluate_single(r2, fr->sc_r_power, fr->sc_alphacoul, fr->sc_alphavdw,
fr->tab14->scale, fr->tab14->data, fr->tab14->stride,
fr->pairsTable->scale, fr->pairsTable->data, fr->pairsTable->stride,
qq, c6, c12, qqB, c6B, c12B,
LFC, LFV, DLF, lfac_coul, lfac_vdw, dlfac_coul, dlfac_vdw,
fr->sc_sigma6_def, fr->sc_sigma6_min, sigma2_def, sigma2_min, &velec, &vvdw, dvdl);
......@@ -499,7 +499,8 @@ do_pairs(int ftype, int nbonds,
else
{
/* Evaluate tabulated interaction without free energy */
fscal = evaluate_single(r2, fr->tab14->scale, fr->tab14->data, fr->tab14->stride, qq, c6, c12, &velec, &vvdw);
fscal = evaluate_single(r2, fr->pairsTable->scale, fr->pairsTable->data, fr->pairsTable->stride,
qq, c6, c12, &velec, &vvdw);
}
energygrp_elec[gid] += velec;
......
/*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2014,2015, by the GROMACS development team, led by
* Copyright (c) 2014,2015,2016, 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.
......@@ -32,13 +32,13 @@
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \internal \file
/*! \libinternal \file
*
* \brief This file declares functions for "pair" interactions
* (i.e. listed non-bonded interactions, e.g. 1-4 interactions)
*
* \author Mark Abraham <mark.j.abraham@gmail.com>
*
* \inlibraryapi
* \ingroup module_listed-forces
*/
#ifndef GMX_LISTED_FORCES_PAIRS_H
......
......@@ -58,6 +58,7 @@
#include "gromacs/gpu_utils/gpu_utils.h"
#include "gromacs/hardware/detecthardware.h"
#include "gromacs/listed-forces/manage-threading.h"
#include "gromacs/listed-forces/pairs.h"
#include "gromacs/math/calculate-ewald-splitting-coefficient.h"
#include "gromacs/math/functions.h"
#include "gromacs/math/units.h"
......@@ -2272,7 +2273,7 @@ void init_forcerec(FILE *fp,
double dbl;
const t_block *cgs;
gmx_bool bGenericKernelOnly;
gmx_bool bMakeTables, bMakeSeparate14Table, bSomeNormalNbListsAreInUse;
gmx_bool needGroupSchemeTables, bSomeNormalNbListsAreInUse;
gmx_bool bFEP_NonBonded;
int *nm_ind, egp_flags;
......@@ -2921,37 +2922,23 @@ void init_forcerec(FILE *fp,
/*This now calculates sum for q and c6*/
set_chargesum(fp, fr, mtop);
/* if we are using LR electrostatics, and they are tabulated,
* the tables will contain modified coulomb interactions.
* Since we want to use the non-shifted ones for 1-4
* coulombic interactions, we must have an extra set of tables.
*/
/* Construct tables.
* A little unnecessary to make both vdw and coul tables sometimes,
* but what the heck... */
bMakeTables = fr->bcoultab || fr->bvdwtab || fr->bEwald ||
(ir->eDispCorr != edispcNO && ir_vdw_switched(ir));
bMakeSeparate14Table = ((!bMakeTables || fr->eeltype != eelCUT || fr->vdwtype != evdwCUT ||
fr->coulomb_modifier != eintmodNONE ||
fr->vdw_modifier != eintmodNONE ||
fr->bBHAM || fr->bEwald) &&
(gmx_mtop_ftype_count(mtop, F_LJ14) > 0 ||
gmx_mtop_ftype_count(mtop, F_LJC14_Q) > 0 ||
gmx_mtop_ftype_count(mtop, F_LJC_PAIRS_NB) > 0));
/* Construct tables for the group scheme. A little unnecessary to
* make both vdw and coul tables sometimes, but what the
* heck. Note that both cutoff schemes construct Ewald tables in
* init_interaction_const_tables. */
needGroupSchemeTables = (ir->cutoff_scheme == ecutsGROUP &&
(fr->bcoultab || fr->bvdwtab));
negp_pp = ir->opts.ngener - ir->nwall;
negptable = 0;
if (!bMakeTables)
if (!needGroupSchemeTables)
{
bSomeNormalNbListsAreInUse = TRUE;
fr->nnblists = 1;
}
else
{
bSomeNormalNbListsAreInUse = (ir->eDispCorr != edispcNO);
bSomeNormalNbListsAreInUse = FALSE;
for (egi = 0; egi < negp_pp; egi++)
{
for (egj = egi; egj < negp_pp; egj++)
......@@ -2992,16 +2979,12 @@ void init_forcerec(FILE *fp,
*/
rtab = ir->rlist + ir->tabext;
if (bMakeTables)
if (needGroupSchemeTables)
{
/* make tables for ordinary interactions */
if (bSomeNormalNbListsAreInUse)
{
make_nbf_tables(fp, fr, rtab, tabfn, NULL, NULL, &fr->nblists[0]);
if (!bMakeSeparate14Table)
{
fr->tab14 = fr->nblists[0].table_elec_vdw;
}
m = 1;
}
else
......@@ -3038,22 +3021,24 @@ void init_forcerec(FILE *fp,
}
}
}
else if ((fr->eDispCorr != edispcNO) &&
((fr->vdw_modifier == eintmodPOTSWITCH) ||
(fr->vdw_modifier == eintmodFORCESWITCH) ||
(fr->vdw_modifier == eintmodPOTSHIFT)))
/* Tables might not be used for the potential modifier
* interactions per se, but we still need them to evaluate
* switch/shift dispersion corrections in this case. */
if (fr->eDispCorr != edispcNO)
{
/* Tables might not be used for the potential modifier interactions per se, but
* we still need them to evaluate switch/shift dispersion corrections in this case.
*/
make_nbf_tables(fp, fr, rtab, tabfn, NULL, NULL, &fr->nblists[0]);
fr->dispersionCorrectionTable = makeDispersionCorrectionTable(fp, fr, rtab, tabfn);
}
if (bMakeSeparate14Table)
/* We want to use unmodified tables for 1-4 coulombic
* interactions, so we must in general have an extra set of
* tables. */
if (gmx_mtop_ftype_count(mtop, F_LJ14) > 0 ||
gmx_mtop_ftype_count(mtop, F_LJC14_Q) > 0 ||
gmx_mtop_ftype_count(mtop, F_LJC_PAIRS_NB) > 0)
{
/* generate extra tables with plain Coulomb for 1-4 interactions only */
fr->tab14 = make_tables(fp, fr, tabpfn, rtab,
GMX_MAKETABLES_14ONLY);
fr->pairsTable = make_tables(fp, fr, tabpfn, rtab,
GMX_MAKETABLES_14ONLY);
}
/* Wall stuff */
......
......@@ -2139,10 +2139,10 @@ void calc_enervirdiff(FILE *fplog, int eDispCorr, t_forcerec *fr)
/* TODO This code depends on the logic in tables.c that
constructs the table layout, which should be made
explicit in future cleanup. */
GMX_ASSERT(fr->nblists[0].table_vdw->interaction == GMX_TABLE_INTERACTION_VDWREP_VDWDISP,
GMX_ASSERT(fr->dispersionCorrectionTable->interaction == GMX_TABLE_INTERACTION_VDWREP_VDWDISP,
"Dispersion-correction code needs a table with both repulsion and dispersion terms");
scale = fr->nblists[0].table_vdw->scale;
vdwtab = fr->nblists[0].table_vdw->data;
scale = fr->dispersionCorrectionTable->scale;
vdwtab = fr->dispersionCorrectionTable->data;
/* Round the cut-offs to exact table values for precision */
ri0 = static_cast<int>(floor(fr->rvdw_switch*scale));
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
* Copyright (c) 2013,2014,2015,2016, 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.
......@@ -212,8 +212,10 @@ typedef struct t_forcerec {
rvec mu_tot[2];
/* Dispersion correction stuff */
int eDispCorr;
int numAtomsForDispersionCorrection;
int eDispCorr;
int numAtomsForDispersionCorrection;
struct t_forcetable *dispersionCorrectionTable;
/* The shift of the shift or user potentials */
real enershiftsix;
real enershifttwelve;
......@@ -237,7 +239,8 @@ typedef struct t_forcerec {
gmx_bool bcoultab;
gmx_bool bvdwtab;
/* The normal tables are in the nblists struct(s) below */
struct t_forcetable *tab14; /* for 1-4 interactions only */
struct t_forcetable *pairsTable; /* for 1-4 interactions, [pairs] and [pairs_nb] */
/* PPPM & Shifting stuff */
int coulomb_modifier;
......@@ -277,15 +280,15 @@ typedef struct t_forcerec {
rvec *shift_vec;
/* The neighborlists including tables */
int nnblists;
int *gid2nblists;
struct t_nblists *nblists;
int nnblists;
int *gid2nblists;
struct t_nblists *nblists;
int cutoff_scheme; /* group- or Verlet-style cutoff */
gmx_bool bNonbonded; /* true if nonbonded calculations are *not* turned off */
struct nonbonded_verlet_t *nbv;
int cutoff_scheme; /* group- or Verlet-style cutoff */
gmx_bool bNonbonded; /* true if nonbonded calculations are *not* turned off */
struct nonbonded_verlet_t *nbv;
/* The wall tables (if used). A 2D array of pointers to tables. */
/* The wall tables (if used) */
int nwall;
struct t_forcetable ***wall_tab;
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
* Copyright (c) 2013,2014,2015,2016, 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.
......@@ -1388,7 +1388,7 @@ t_forcetable *make_tables(FILE *out,
read_tables(out, fn, etiNR, 0, td);
if (rtab == 0 || (flags & GMX_MAKETABLES_14ONLY))
{
table->n = td[0].nx;
table->n = td[0].nx;
}
else
{
......@@ -1565,3 +1565,47 @@ bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle)
return tab;
}
t_forcetable *makeDispersionCorrectionTable(FILE *fp,
t_forcerec *fr, real rtab,
const char *tabfn)
{
t_forcetable *dispersionCorrectionTable = NULL;
if (tabfn == NULL)
{
if (debug)
{
fprintf(debug, "No table file name passed, can not read table, can not do non-bonded interactions\n");
}
return dispersionCorrectionTable;
}
t_forcetable *fullTable = make_tables(fp, fr, tabfn, rtab, 0);
/* Copy the contents of the table to one that has just dispersion
* and repulsion, to improve cache performance. We want the table
* data to be aligned to 32-byte boundaries. The pointers could be
* freed but currently aren't. */
snew(dispersionCorrectionTable, 1);
dispersionCorrectionTable->interaction = GMX_TABLE_INTERACTION_VDWREP_VDWDISP;
dispersionCorrectionTable->format = fullTable->format;
dispersionCorrectionTable->r = fullTable->r;
dispersionCorrectionTable->n = fullTable->n;
dispersionCorrectionTable->scale = fullTable->scale;
dispersionCorrectionTable->formatsize = fullTable->formatsize;
dispersionCorrectionTable->ninteractions = 2;
dispersionCorrectionTable->stride = dispersionCorrectionTable->formatsize * dispersionCorrectionTable->ninteractions;
snew_aligned(dispersionCorrectionTable->data, dispersionCorrectionTable->stride*(dispersionCorrectionTable->n+1), 32);
for (int i = 0; i <= fullTable->n; i++)
{
for (int j = 0; j < 8; j++)
{
dispersionCorrectionTable->data[8*i+j] = fullTable->data[12*i+4+j];
}
}
sfree_aligned(fullTable->data);
sfree(fullTable);
return dispersionCorrectionTable;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
* Copyright (c) 2012,2014,2015,2016, 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.
......@@ -92,4 +92,10 @@ bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle);
/* Return a table for GB calculations */
t_forcetable *make_gb_table(const t_forcerec *fr);
/*! \brief Construct and return tabulated dispersion and repulsion interactions
*
* This table can be used to compute long-range dispersion corrections */
t_forcetable *makeDispersionCorrectionTable(FILE *fp, t_forcerec *fr,
real rtab, const char *tabfn);
#endif /* GMX_TABLES_FORCETABLE_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment