Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel.h
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
3  * This file is part of GROMACS.
4  * Copyright (c) 2012-
5  *
6  * Written by the Gromacs development team under coordination of
7  * David van der Spoel, Berk Hess, and Erik Lindahl.
8  *
9  * This library 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
12  * of the License, or (at your option) any later version.
13  *
14  * To help us fund GROMACS development, we humbly ask that you cite
15  * the research papers on the package. Check out http://www.gromacs.org
16  *
17  * And Hey:
18  * Gnomes, ROck Monsters And Chili Sauce
19  */
20 #ifndef _nb_kernel_h_
21 #define _nb_kernel_h_
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 #if 0
32 } /* fixes auto-indentation problems */
33 #endif
34
35
36 #include "types/simple.h"
37 #include "typedefs.h"
38
39 /* Structure to collect kernel data not available in forcerec or mdatoms structures.
40  * This is only used inside the nonbonded module.
41  */
42 typedef struct
43 {
44     int                flags;
45     t_blocka *         exclusions;
46     real *             lambda;
47     real *             dvdl;
48
49     /* pointers to tables */
50     t_forcetable *     table_elec;
51     t_forcetable *     table_vdw;
52     t_forcetable *     table_elec_vdw;
53
54     /* potentials */
55     real *             energygrp_elec;
56     real *             energygrp_vdw;
57     real *             energygrp_polarization;
58 }
59 nb_kernel_data_t;
60
61
62 typedef void
63     nb_kernel_t (t_nblist *                nlist,
64                  rvec *                    x,
65                  rvec *                    f,
66                  t_forcerec *              fr,
67                  t_mdatoms *               mdatoms,
68                  nb_kernel_data_t *        kernel_data,
69                  t_nrnb *                  nrnb);
70
71
72 /* Structure with a kernel pointer and settings. This cannot be abstract
73  * since we define the kernel list statically for each architecture in a header,
74  * and use it to set up the kernel hash functions to find kernels.
75  *
76  * The electrostatics/vdw names should be obvious and correspond to the
77  * forms of the interactions calculated in this function, and the interaction
78  * modifiers describe switch/shift and similar alterations. Geometry refers
79  * to whether this kernel calculates interactions between single particles or
80  * waters (groups of 3/4 atoms) for better performance. Finally, the VF string
81  * selects whether the kernel calculates only potential, only force, or both
82  *
83  * The allowed values for kernel interactions are described by the
84  * enumerated types gmx_nbkernel_elec and gmx_nbkernel_vdw (see types/enums.h).
85  * Note that these are deliberately NOT identical to the interactions the
86  * user can set, since some user-specified interactions will be tabulated, and
87  * Lennard-Jones and Buckingham use different kernels while their setting in
88  * the input is decided by nonbonded parameter formats rather than mdp options.
89  *
90  * The interaction modifiers are described by the eintmod enum type, while
91  * the kernel geometry is decided from the neighborlist geometry, which is
92  * described by the enum gmx_nblist_kernel_geometry (again, see types/enums.h).
93  * The
94  *
95  * Note that any particular implementation of kernels might not support all of
96  * these strings. In fact, some might not be supported by any architecture yet.
97  * The whole point of using strings and hashes is that we do not have to define a
98  * unique set of strings in a single place. Thus, as long as you implement a
99  * corresponding kernel, you could in theory provide any string you want.
100  */
101 typedef struct nb_kernel_info
102 {
103     nb_kernel_t *   kernelptr;
104     const char *    kernelname;
105     const char *    architecture;     /* e.g. "C", "SSE", "BlueGene", etc. */
106
107     const char *    electrostatics;
108     const char *    electrostatics_modifier;
109     const char *    vdw;
110     const char *    vdw_modifier;
111     const char *    geometry;
112     const char *    other;  /* Any extra info you want/need to select a kernel */
113     const char *    vf;     /* "PotentialAndForce", "Potential", or "Force" */
114 }
115 nb_kernel_info_t;
116
117
118 void
119 nb_kernel_list_add_kernels(nb_kernel_info_t *   new_kernelinfo,
120                            int                  new_size);
121
122 int
123 nb_kernel_list_hash_init(void);
124
125 /* Return a function pointer to the nonbonded kernel pointer with
126  * settings according to the text strings provided. GROMACS does not guarantee
127  * the existence of accelerated kernels for any combination, so the return value
128  * can be NULL.
129  * In that case, you can try a different/lower-level acceleration, and
130  * eventually you need to prepare to fall back to generic kernels or change
131  * your settings and try again.
132  *
133  * The names of the text strings are obviously meant to reflect settings in
134  * GROMACS, but inside this routine they are merely used as a set of text
135  * strings not defined here. The routine will simply compare the arguments with
136  * the contents of the corresponding strings in the nb_kernel_list_t structure.
137  *
138  * This function does not check whether the kernel in question can run on the
139  * present architecture since that would require a slow cpuid call for every
140  * single invocation.
141  */
142 nb_kernel_t *
143 nb_kernel_list_findkernel(FILE *              log,
144                           const char *        architecture,
145                           const char *        electrostatics,
146                           const char *        electrostatics_modifier,
147                           const char *        vdw,
148                           const char *        vdw_modifier,
149                           const char *        geometry,
150                           const char *        other,
151                           const char *        vf);
152
153
154
155 #ifdef __cplusplus
156 }
157 #endif
158
159 #endif /* _nb_kernel_h_ */