Merge branch release-4-6 into release-5-0
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 #ifndef _nb_kernel_h_
36 #define _nb_kernel_h_
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 #if 0
47 } /* fixes auto-indentation problems */
48 #endif
49
50
51 #include "types/simple.h"
52 #include "typedefs.h"
53
54 /* Structure to collect kernel data not available in forcerec or mdatoms structures.
55  * This is only used inside the nonbonded module.
56  */
57 typedef struct
58 {
59     int                flags;
60     t_blocka *         exclusions;
61     real *             lambda;
62     real *             dvdl;
63
64     /* pointers to tables */
65     t_forcetable *     table_elec;
66     t_forcetable *     table_vdw;
67     t_forcetable *     table_elec_vdw;
68
69     /* potentials */
70     real *             energygrp_elec;
71     real *             energygrp_vdw;
72     real *             energygrp_polarization;
73 }
74 nb_kernel_data_t;
75
76
77 typedef void
78     nb_kernel_t (t_nblist *                nlist,
79                  rvec *                    x,
80                  rvec *                    f,
81                  t_forcerec *              fr,
82                  t_mdatoms *               mdatoms,
83                  nb_kernel_data_t *        kernel_data,
84                  t_nrnb *                  nrnb);
85
86
87 /* Structure with a kernel pointer and settings. This cannot be abstract
88  * since we define the kernel list statically for each architecture in a header,
89  * and use it to set up the kernel hash functions to find kernels.
90  *
91  * The electrostatics/vdw names should be obvious and correspond to the
92  * forms of the interactions calculated in this function, and the interaction
93  * modifiers describe switch/shift and similar alterations. Geometry refers
94  * to whether this kernel calculates interactions between single particles or
95  * waters (groups of 3/4 atoms) for better performance. Finally, the VF string
96  * selects whether the kernel calculates only potential, only force, or both
97  *
98  * The allowed values for kernel interactions are described by the
99  * enumerated types gmx_nbkernel_elec and gmx_nbkernel_vdw (see types/enums.h).
100  * Note that these are deliberately NOT identical to the interactions the
101  * user can set, since some user-specified interactions will be tabulated, and
102  * Lennard-Jones and Buckingham use different kernels while their setting in
103  * the input is decided by nonbonded parameter formats rather than mdp options.
104  *
105  * The interaction modifiers are described by the eintmod enum type, while
106  * the kernel geometry is decided from the neighborlist geometry, which is
107  * described by the enum gmx_nblist_kernel_geometry (again, see types/enums.h).
108  * The
109  *
110  * Note that any particular implementation of kernels might not support all of
111  * these strings. In fact, some might not be supported by any architecture yet.
112  * The whole point of using strings and hashes is that we do not have to define a
113  * unique set of strings in a single place. Thus, as long as you implement a
114  * corresponding kernel, you could in theory provide any string you want.
115  */
116 typedef struct nb_kernel_info
117 {
118     nb_kernel_t *   kernelptr;
119     const char *    kernelname;
120     const char *    architecture;     /* e.g. "C", "SSE", "BlueGene", etc. */
121
122     const char *    electrostatics;
123     const char *    electrostatics_modifier;
124     const char *    vdw;
125     const char *    vdw_modifier;
126     const char *    geometry;
127     const char *    other;  /* Any extra info you want/need to select a kernel */
128     const char *    vf;     /* "PotentialAndForce", "Potential", or "Force" */
129 }
130 nb_kernel_info_t;
131
132
133 void
134 nb_kernel_list_add_kernels(nb_kernel_info_t *   new_kernelinfo,
135                            int                  new_size);
136
137 int
138 nb_kernel_list_hash_init(void);
139
140 /* Return a function pointer to the nonbonded kernel pointer with
141  * settings according to the text strings provided. GROMACS does not guarantee
142  * the existence of accelerated kernels for any combination, so the return value
143  * can be NULL.
144  * In that case, you can try a different/lower-level acceleration, and
145  * eventually you need to prepare to fall back to generic kernels or change
146  * your settings and try again.
147  *
148  * The names of the text strings are obviously meant to reflect settings in
149  * GROMACS, but inside this routine they are merely used as a set of text
150  * strings not defined here. The routine will simply compare the arguments with
151  * the contents of the corresponding strings in the nb_kernel_list_t structure.
152  *
153  * This function does not check whether the kernel in question can run on the
154  * present architecture since that would require a slow cpuid call for every
155  * single invocation.
156  */
157 nb_kernel_t *
158 nb_kernel_list_findkernel(FILE *              log,
159                           const char *        architecture,
160                           const char *        electrostatics,
161                           const char *        electrostatics_modifier,
162                           const char *        vdw,
163                           const char *        vdw_modifier,
164                           const char *        geometry,
165                           const char *        other,
166                           const char *        vf);
167
168
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif /* _nb_kernel_h_ */