NAMD
Typedefs | Enumerations | Functions
msm.h File Reference

Go to the source code of this file.

Typedefs

typedef struct NL_Msm_t NL_Msm
 

Enumerations

enum  {
  NL_MSM_PERIODIC_NONE = 0x000, NL_MSM_PERIODIC_VEC1 = 0x001, NL_MSM_PERIODIC_VEC2 = 0x002, NL_MSM_PERIODIC_VEC3 = 0x004,
  NL_MSM_PERIODIC_ALL = 0x007, NL_MSM_COMPUTE_SHORT_RANGE = 0x008, NL_MSM_COMPUTE_LONG_RANGE = 0x010, NL_MSM_COMPUTE_ALL = 0x018,
  NL_MSM_COMPUTE_SPREC = 0x020, NL_MSM_COMPUTE_1AWAY = 0x040, NL_MSM_COMPUTE_NONFACTORED = 0x080, NL_MSM_REPORT_TIMINGS = 0x100,
  NL_MSM_COMPUTE_CUDA_FALL_BACK = 0x200, NL_MSM_COMPUTE_CUDA_GRID_CUTOFF = 0x400, NL_MSM_COMPUTE_CUDA_SHORT_RANGE = 0x800, NL_MSM_COMPUTE_CUDA = 0xE00,
  NL_MSM_ALL_FLAGS = 0xFFF
}
 
enum  {
  NL_MSM_SUCCESS = 0, NL_MSM_ERROR_MALLOC, NL_MSM_ERROR_PARAM, NL_MSM_ERROR_RANGE,
  NL_MSM_ERROR_SUPPORT, NL_MSM_ERROR_CUDA, NL_MSM_ERROR_END
}
 
enum  {
  NL_MSM_APPROX_CUBIC = 0, NL_MSM_APPROX_QUINTIC, NL_MSM_APPROX_QUINTIC2, NL_MSM_APPROX_SEPTIC,
  NL_MSM_APPROX_SEPTIC3, NL_MSM_APPROX_NONIC, NL_MSM_APPROX_NONIC4, NL_MSM_APPROX_BSPLINE,
  NL_MSM_APPROX_END
}
 
enum  {
  NL_MSM_SPLIT_TAYLOR2 = 0, NL_MSM_SPLIT_TAYLOR3, NL_MSM_SPLIT_TAYLOR4, NL_MSM_SPLIT_TAYLOR5,
  NL_MSM_SPLIT_TAYLOR6, NL_MSM_SPLIT_TAYLOR7, NL_MSM_SPLIT_TAYLOR8, NL_MSM_SPLIT_TAYLOR1,
  NL_MSM_SPLIT_SIGMA2_3, NL_MSM_SPLIT_SIGMA3_5, NL_MSM_SPLIT_SIGMA4_6, NL_MSM_SPLIT_SIGMA4_7,
  NL_MSM_SPLIT_SIGMA5_8, NL_MSM_SPLIT_SIGMA5_9, NL_MSM_SPLIT_SIGMA6_9, NL_MSM_SPLIT_SIGMA6_10,
  NL_MSM_SPLIT_SIGMA6_11, NL_MSM_SPLIT_SIGMA7_11, NL_MSM_SPLIT_SIGMA7_12, NL_MSM_SPLIT_SIGMA7_13,
  NL_MSM_SPLIT_SIGMA8_12, NL_MSM_SPLIT_SIGMA8_13, NL_MSM_SPLIT_SIGMA8_14, NL_MSM_SPLIT_SIGMA8_15,
  NL_MSM_SPLIT_SIGMA2_6, NL_MSM_SPLIT_SWITCH1_2, NL_MSM_SPLIT_SWITCH3_4, NL_MSM_SPLIT_SWITCH7_8,
  NL_MSM_SPLIT_END
}
 

Functions

NL_MsmNL_msm_create (void)
 
void NL_msm_destroy (NL_Msm *)
 
int NL_msm_setup (NL_Msm *msm, double cutoff, double cellvec1[3], double cellvec2[3], double cellvec3[3], double cellcenter[3], int msmflags)
 
int NL_msm_configure (NL_Msm *msm, double gridspacing, int approx, int split, int nlevels)
 
int NL_msm_compute_force (NL_Msm *msm, double *felec, double *uelec, const double *atom, int natoms)
 
int NL_msm_compute_force_sprec (NL_Msm *msm, float *felec, float *uelec, const float *atom, int natoms)
 
int NL_msm_approx (const char *name)
 
int NL_msm_split (const char *name)
 
const char * NL_msm_approx_name (int approx)
 
const char * NL_msm_split_name (int split)
 

Typedef Documentation

typedef struct NL_Msm_t NL_Msm

Definition at line 13 of file msm.h.

Enumeration Type Documentation

anonymous enum

Use in setup for msmflags, bitwise OR the options.

Enumerator
NL_MSM_PERIODIC_NONE 

aperiodic cell

NL_MSM_PERIODIC_VEC1 

periodic along basis vector 1

NL_MSM_PERIODIC_VEC2 

periodic along basis vector 2

NL_MSM_PERIODIC_VEC3 

periodic along basis vector 3

NL_MSM_PERIODIC_ALL 

periodic along all basis vectors

NL_MSM_COMPUTE_SHORT_RANGE 

compute the short-range part

NL_MSM_COMPUTE_LONG_RANGE 

compute the long-range part

NL_MSM_COMPUTE_ALL 

compute both parts

NL_MSM_COMPUTE_SPREC 

use single precision (faster)

NL_MSM_COMPUTE_1AWAY 

1-away neighborhood (slower)

NL_MSM_COMPUTE_NONFACTORED 

use non-factored restriction and prolongation procedures (slower)

NL_MSM_REPORT_TIMINGS 

report timings

NL_MSM_COMPUTE_CUDA_FALL_BACK 

fall back on CPU if configuration unsupported by CUDA

NL_MSM_COMPUTE_CUDA_GRID_CUTOFF 

use CUDA for grid cutoff

NL_MSM_COMPUTE_CUDA_SHORT_RANGE 

use CUDA for short range

NL_MSM_COMPUTE_CUDA 

all CUDA flags set on

NL_MSM_ALL_FLAGS 

all flags set on

Definition at line 43 of file msm.h.

anonymous enum

Return codes.

Enumerator
NL_MSM_SUCCESS 

success

NL_MSM_ERROR_MALLOC 

can't allocate memory

NL_MSM_ERROR_PARAM 

incorrect parameters

NL_MSM_ERROR_RANGE 

atom is outside of cell

NL_MSM_ERROR_SUPPORT 

unsupported feature

NL_MSM_ERROR_CUDA 

CUDA failure

NL_MSM_ERROR_END 

(for internal use)

Definition at line 77 of file msm.h.

anonymous enum

MSM approximation/interpolation methods. (Default is CUBIC.)

Enumerator
NL_MSM_APPROX_CUBIC 

C1 degree 3 poly (numerical Hermite)

NL_MSM_APPROX_QUINTIC 

C1 degree 5 poly (linear blend of degree 4)

NL_MSM_APPROX_QUINTIC2 

C2 degree 5 poly

NL_MSM_APPROX_SEPTIC 

C1 degree 7 poly (linear blend of degree 6)

NL_MSM_APPROX_SEPTIC3 

C3 degree 7 poly

NL_MSM_APPROX_NONIC 

C1 degree 9 poly (linear blend of degree 8)

NL_MSM_APPROX_NONIC4 

C4 degree 9 poly

NL_MSM_APPROX_BSPLINE 

C2 degree 3 B-spline

NL_MSM_APPROX_END 

(for internal use)

Definition at line 153 of file msm.h.

anonymous enum

MSM splitting functions to smooth the 1/r potential. (Default is TAYLOR2.)

The Taylor splittings are the family of C^k Taylor polynomials of s^(-1/2) about s=1. Discussed in section 5.1 of the thesis. TAYLOR1 is listed last so that reasonable default parameters (CUBIC approximation with TAYLOR2 splitting) are automatically selected from zeroing the values.

The sigma(k,d) splittings generalize the Taylor splittings above for C^k continuity at r=1 and degree d polynomial in r. (The Taylor splittings are sigma(d/2,d).) The ones here are uniquely determined. Discussed in section 5.2 of the thesis.

The special sigma(2,6) splitting is from section 5.3 of the thesis. This is a proof-of-concept where the polynomial in even powers of r has an extra degree of freedom chosen to minimize the error bound.

Elimiate the self-force artifact through the use of a switching function between 1/r and a polynomial reproduced exactly by CUBIC interpolation. Discussed in section 5.4 of thesis.

Enumerator
NL_MSM_SPLIT_TAYLOR2 

C2 Taylor

NL_MSM_SPLIT_TAYLOR3 

C3 Taylor

NL_MSM_SPLIT_TAYLOR4 

C4 Taylor

NL_MSM_SPLIT_TAYLOR5 

C5 Taylor

NL_MSM_SPLIT_TAYLOR6 

C6 Taylor

NL_MSM_SPLIT_TAYLOR7 

C7 Taylor

NL_MSM_SPLIT_TAYLOR8 

C8 Taylor

NL_MSM_SPLIT_TAYLOR1 

C1 Taylor

NL_MSM_SPLIT_SIGMA2_3 

C2, degree 3 (the "perfect" smoothing)

NL_MSM_SPLIT_SIGMA3_5 

C3, degree 5

NL_MSM_SPLIT_SIGMA4_6 

C4, degree 6

NL_MSM_SPLIT_SIGMA4_7 

C4, degree 7

NL_MSM_SPLIT_SIGMA5_8 

C5, degree 8

NL_MSM_SPLIT_SIGMA5_9 

C5, degree 9

NL_MSM_SPLIT_SIGMA6_9 

C6, degree 9

NL_MSM_SPLIT_SIGMA6_10 

C6, degree 10

NL_MSM_SPLIT_SIGMA6_11 

C6, degree 11

NL_MSM_SPLIT_SIGMA7_11 

C7, degree 11

NL_MSM_SPLIT_SIGMA7_12 

C7, degree 12

NL_MSM_SPLIT_SIGMA7_13 

C7, degree 13

NL_MSM_SPLIT_SIGMA8_12 

C8, degree 12

NL_MSM_SPLIT_SIGMA8_13 

C8, degree 13

NL_MSM_SPLIT_SIGMA8_14 

C8, degree 14

NL_MSM_SPLIT_SIGMA8_15 

C8, degree 15

NL_MSM_SPLIT_SIGMA2_6 

C2, degree 6, even powers of r, chosen to minimize error bound

NL_MSM_SPLIT_SWITCH1_2 

C2, switching at r/a=1/2

NL_MSM_SPLIT_SWITCH3_4 

C2, switching at r/a=3/4

NL_MSM_SPLIT_SWITCH7_8 

C2, switching at r/a=7/8

NL_MSM_SPLIT_END 

(for internal use)

Definition at line 187 of file msm.h.

187  {
222  };

Function Documentation

int NL_msm_approx ( const char *  name)

Helper function to determine APPROX enum constant from string name.

Definition at line 160 of file msm.c.

References ApproxName, and NELEMS.

160  {
161  int i;
162  if (name) {
163  for (i = 0; i < NELEMS(ApproxName); i++) {
164  if (strcasecmp(name, ApproxName[i]) == 0) return i;
165  }
166  }
167  return -1;
168 }
#define NELEMS(arr)
Definition: msm_defn.h:39
static const char * ApproxName[]
Definition: msm.c:149
const char* NL_msm_approx_name ( int  approx)

Helper function returning string name for APPROX enum constant.

Definition at line 170 of file msm.c.

References ApproxName, and NELEMS.

Referenced by print_status().

170  {
171  if (approx >= 0 && approx < NELEMS(ApproxName)) {
172  return ApproxName[approx];
173  }
174  else return NULL;
175 }
#define NELEMS(arr)
Definition: msm_defn.h:39
static const char * ApproxName[]
Definition: msm.c:149
int NL_msm_compute_force ( NL_Msm msm,
double *  felec,
double *  uelec,
const double *  atom,
int  natoms 
)

Compute the electrostatic forces and potential energy for the array of atoms. The felec array and the location pointed to by uelec is expected to be initialized before the call. As stated, the atoms must be within the defined cell.

Parameters
msmthe MSM solver object
felecelectrostatic forces x/y/z for each atom
uelecelectrostatic potential energy
atompositions and charge x/y/z/q for each atom
natomsnumber of atoms

Definition at line 56 of file msm.c.

References NL_Msm_t::atom, NL_Msm_t::felec, NL_Msm_t::msmflags, NL_MSM_COMPUTE_LONG_RANGE, NL_msm_compute_long_range(), NL_MSM_COMPUTE_SHORT_RANGE, NL_msm_compute_short_range(), NL_MSM_COMPUTE_SPREC, NL_MSM_ERROR_PARAM, NL_Msm_t::numatoms, NL_Msm_t::report_timings, NL_Msm_t::timer, NL_Msm_t::uelec, wkf_timer_start(), wkf_timer_stop(), and wkf_timer_time().

Referenced by ComputeMsmSerialMgr::recvCoord().

62  {
63  int rc;
64  double time_delta;
65 
66  if (pm->msmflags & NL_MSM_COMPUTE_SPREC) {
67  return NL_MSM_ERROR_PARAM;
68  }
69 
70  /* store buffer pointers from caller */
71  pm->felec = felec;
72  pm->atom = atom;
73  pm->numatoms = natoms;
74  pm->uelec = 0;
75 
76  if (pm->msmflags & NL_MSM_COMPUTE_SHORT_RANGE) {
77  wkf_timer_start(pm->timer);
79  if (rc) return rc;
80  wkf_timer_stop(pm->timer);
81  time_delta = wkf_timer_time(pm->timer);
82  if (pm->report_timings) {
83  printf("MSM short-range part: %6.3f sec\n", time_delta);
84  }
85  }
86  if (pm->msmflags & NL_MSM_COMPUTE_LONG_RANGE) {
87  wkf_timer_start(pm->timer);
89  if (rc) return rc;
90  wkf_timer_stop(pm->timer);
91  time_delta = wkf_timer_time(pm->timer);
92  if (pm->report_timings) {
93  printf("MSM long-range part: %6.3f sec\n", time_delta);
94  }
95  }
96  *uelec += pm->uelec; /* add to caller's potential */
97 
98  return 0;
99 }
double wkf_timer_time(wkf_timerhandle v)
Definition: wkfutils.c:134
void wkf_timer_stop(wkf_timerhandle v)
Definition: wkfutils.c:129
int NL_msm_compute_short_range(NL_Msm *pm)
Definition: msm_shortrng.c:37
int NL_msm_compute_long_range(NL_Msm *pm)
Definition: msm_longrng.c:52
void wkf_timer_start(wkf_timerhandle v)
Definition: wkfutils.c:124
int NL_msm_compute_force_sprec ( NL_Msm msm,
float *  felec,
float *  uelec,
const float *  atom,
int  natoms 
)

Same as NL_msm_compute_force() except for single precision calculation. Call this only if NL_MSM_COMPUTE_SPREC flag was selected.

Parameters
msmthe MSM solver object
felecelectrostatic forces x/y/z for each atom
uelecelectrostatic potential energy
atompositions and charge x/y/z/q for each atom
natomsnumber of atoms

Definition at line 102 of file msm.c.

References NL_Msm_t::atom_f, NL_Msm_t::felec_f, NL_Msm_t::msmflags, NL_MSM_COMPUTE_LONG_RANGE, NL_msm_compute_long_range_sprec(), NL_MSM_COMPUTE_SHORT_RANGE, NL_msm_compute_short_range_sprec(), NL_MSM_COMPUTE_SPREC, NL_MSM_ERROR_PARAM, NL_Msm_t::numatoms, NL_Msm_t::report_timings, NL_Msm_t::timer, NL_Msm_t::uelec, wkf_timer_start(), wkf_timer_stop(), and wkf_timer_time().

108  {
109  int rc;
110  double time_delta;
111 
112  if ((pm->msmflags & NL_MSM_COMPUTE_SPREC) == 0) {
113  return NL_MSM_ERROR_PARAM;
114  }
115 
116  /* store buffer pointers from caller */
117  pm->felec_f = felec_f;
118  pm->atom_f = atom_f;
119  pm->numatoms = natoms;
120  pm->uelec = 0;
121 
122  if (pm->msmflags & NL_MSM_COMPUTE_SHORT_RANGE) {
123  wkf_timer_start(pm->timer);
125  if (rc) return rc;
126  wkf_timer_stop(pm->timer);
127  time_delta = wkf_timer_time(pm->timer);
128  if (pm->report_timings) {
129  printf("MSM short-range part: %6.3f sec\n", time_delta);
130  }
131  }
132  if (pm->msmflags & NL_MSM_COMPUTE_LONG_RANGE) {
133  wkf_timer_start(pm->timer);
135  if (rc) return rc;
136  wkf_timer_stop(pm->timer);
137  time_delta = wkf_timer_time(pm->timer);
138  if (pm->report_timings) {
139  printf("MSM long-range part: %6.3f sec\n", time_delta);
140  }
141  }
142  *uelec_f += (float) pm->uelec; /* add to caller's potential */
143 
144  return 0;
145 }
double wkf_timer_time(wkf_timerhandle v)
Definition: wkfutils.c:134
void wkf_timer_stop(wkf_timerhandle v)
Definition: wkfutils.c:129
int NL_msm_compute_short_range_sprec(NL_Msm *pm)
int NL_msm_compute_long_range_sprec(NL_Msm *pm)
void wkf_timer_start(wkf_timerhandle v)
Definition: wkfutils.c:124
int NL_msm_configure ( NL_Msm msm,
double  gridspacing,
int  approx,
int  split,
int  nlevels 
)

Advanced configuration of MSM. The ratio of cutoff / gridspacing is generally kept between about 2.5 and 6. For atomic lengths in Angstroms, good results are demonstrated for a cutoff distance between 8 and 12 A and the default grid spacing of 2.5 A.

The optimal pairings of approx and split have been demonstrated to be:

  • CUBIC with TAYLOR2 (the default),
  • QUINTIC with TAYLOR3,
  • SEPTIC with TAYLOR4,
  • NONIC with TAYLOR5.

Use QUINTIC2, SEPTIC3, NONIC4 paired with the same splitting functions above if greater continuity is desired.

Set "nlevels" to 0 (the default) to fully adapt the number of grid levels to the system cell size.

Parameters
msmthe MSM solver object
gridspacinggrid spacing for first grid level
approxwhich approximation method
splitwhich splitting
nlevelsnumber of grid levels to use

Definition at line 36 of file msm.c.

References NL_Msm_t::approx, NL_Msm_t::gridspacing, NL_MSM_APPROX_END, NL_MSM_ERROR_PARAM, NL_MSM_SPLIT_END, NL_MSM_SUCCESS, NL_Msm_t::nlevels, split(), and NL_Msm_t::split.

Referenced by ComputeMsmSerialMgr::recvCoord().

42  {
43  if (gridspacing > 0) pm->gridspacing = gridspacing;
44  else if (gridspacing < 0) return NL_MSM_ERROR_PARAM;
45  if (approx >= 0 && approx < NL_MSM_APPROX_END) pm->approx = approx;
46  else return NL_MSM_ERROR_PARAM;
47  if (split >= 0 && split < NL_MSM_SPLIT_END) pm->split = split;
48  else return NL_MSM_ERROR_PARAM;
49  if (nlevels >= 0) pm->nlevels = nlevels;
50  else return NL_MSM_ERROR_PARAM;
51 
52  return NL_MSM_SUCCESS;
53 }
std::vector< std::string > split(const std::string &text, std::string delimiter)
Definition: MoleculeQM.C:73
NL_Msm* NL_msm_create ( void  )

Allocate MSM solver.

Definition at line 6 of file msm.c.

References NL_Msm_t::approx, NL_Msm_t::binfill, DEFAULT_APPROX, DEFAULT_BINFILL, DEFAULT_DENSITY, DEFAULT_GRIDSPACING, DEFAULT_NBINSLOTS, DEFAULT_NLEVELS, DEFAULT_SPLIT, NL_Msm_t::density, NL_Msm_t::gridspacing, NL_Msm_t::nbinslots, NL_Msm_t::nlevels, NL_Msm_t::split, NL_Msm_t::timer, NL_Msm_t::timer_longrng, and wkf_timer_create().

Referenced by ComputeMsmSerialMgr::recvCoord().

6  {
7  NL_Msm *pm = (NL_Msm *) calloc(1, sizeof(NL_Msm));
8  if (NULL == pm) return NULL;
9 
10  pm->timer = wkf_timer_create();
11  if (NULL == pm->timer) return NULL;
13  if (NULL == pm->timer) return NULL;
14 
15  /* method parameters are modified with msm_configure() */
17  pm->approx = DEFAULT_APPROX;
18  pm->split = DEFAULT_SPLIT;
20 
24  return pm;
25 }
wkf_timerhandle timer
Definition: msm_defn.h:684
int approx
Definition: msm_defn.h:642
wkf_timerhandle wkf_timer_create(void)
Definition: wkfutils.c:161
#define DEFAULT_APPROX
Definition: msm_defn.h:120
#define DEFAULT_DENSITY
Definition: msm_defn.h:124
double density
Definition: msm_defn.h:605
#define DEFAULT_SPLIT
Definition: msm_defn.h:121
int nbinslots
Definition: msm_defn.h:606
#define DEFAULT_BINFILL
Definition: msm_defn.h:125
#define DEFAULT_GRIDSPACING
Definition: msm_defn.h:119
wkf_timerhandle timer_longrng
Definition: msm_defn.h:685
double binfill
Definition: msm_defn.h:604
double gridspacing
Definition: msm_defn.h:633
int split
Definition: msm_defn.h:643
#define DEFAULT_NLEVELS
Definition: msm_defn.h:122
int nlevels
Definition: msm_defn.h:645
#define DEFAULT_NBINSLOTS
Definition: msm_defn.h:126
void NL_msm_destroy ( NL_Msm )

Free MSM solver.

Definition at line 28 of file msm.c.

References NL_msm_cleanup(), NL_Msm_t::timer, NL_Msm_t::timer_longrng, and wkf_timer_destroy().

Referenced by ComputeMsmSerialMgr::~ComputeMsmSerialMgr().

28  {
29  NL_msm_cleanup(pm);
30  wkf_timer_destroy(pm->timer);
31  wkf_timer_destroy(pm->timer_longrng);
32  free(pm);
33 }
void wkf_timer_destroy(wkf_timerhandle v)
Definition: wkfutils.c:168
void NL_msm_cleanup(NL_Msm *pm)
Definition: msm_setup.c:7
int NL_msm_setup ( NL_Msm msm,
double  cutoff,
double  cellvec1[3],
double  cellvec2[3],
double  cellvec3[3],
double  cellcenter[3],
int  msmflags 
)

Setup the MSM solver for the molecular system. These parameters come directly from the simulation. Here the cutoff provides some control over the accuracy. The region of space containing the atoms is defined as a parallelepiped, and the "isperiodic" flag determines whether or not each individual cell dimension has periodic boundary conditions. The defined cell is expected to contain the atoms regardless of the choice of boundary conditions. The cell volume must contain the cutoff-sphere.

XXX For now, the MSM solver permits only cell vectors that align with the x-, y-, and z-axis, respectively.

Parameters
msmthe MSM solver object
cutoffcutoff distance for short-range part
cellvec1cell basis vector 1
cellvec2cell basis vector 2
cellvec3cell basis vector 3
cellcentercenter of cell
msmflagsflags for periodicity and calculation

Definition at line 62 of file msm_setup.c.

References NL_Msm_t::a, NL_Msm_t::a_f, NL_Msm_t::cellcenter, NL_Msm_t::cellcenter_f, NL_Msm_t::cellvec1, NL_Msm_t::cellvec1_f, NL_Msm_t::cellvec2, NL_Msm_t::cellvec2_f, NL_Msm_t::cellvec3, NL_Msm_t::cellvec3_f, NL_Msm_t::gx, NL_Msm_t::gx_f, NL_Msm_t::gy, NL_Msm_t::gy_f, NL_Msm_t::gz, NL_Msm_t::gz_f, NL_Msm_t::hx, NL_Msm_t::hx_f, NL_Msm_t::hy, NL_Msm_t::hy_f, NL_Msm_t::hz, NL_Msm_t::hz_f, NL_Msm_t::msmflags, NL_MSM_ALL_FLAGS, NL_MSM_COMPUTE_1AWAY, NL_MSM_COMPUTE_ALL, NL_MSM_COMPUTE_CUDA_FALL_BACK, NL_MSM_COMPUTE_CUDA_GRID_CUTOFF, NL_MSM_COMPUTE_LONG_RANGE, NL_MSM_COMPUTE_SHORT_RANGE, NL_MSM_COMPUTE_SPREC, NL_MSM_ERROR_PARAM, NL_MSM_ERROR_SUPPORT, NL_MSM_PERIODIC_VEC1, NL_MSM_PERIODIC_VEC2, NL_MSM_PERIODIC_VEC3, NL_MSM_REPORT_TIMINGS, NL_MSM_SUCCESS, print_status(), NL_Msm_t::recipvec1, NL_Msm_t::recipvec1_f, NL_Msm_t::recipvec2, NL_Msm_t::recipvec2_f, NL_Msm_t::recipvec3, NL_Msm_t::recipvec3_f, NL_Msm_t::report_timings, setup_bins_1away(), setup_bins_k_away(), setup_cell_vectors(), and setup_grids().

Referenced by ComputeMsmSerialMgr::recvCoord().

70  {
71 
72  int rc = 0;
73 
74  /* check sanity of msmflags */
75  if ((~NL_MSM_ALL_FLAGS & msmflags) != 0 ||
76  (NL_MSM_COMPUTE_ALL & msmflags) == 0) {
77  return NL_MSM_ERROR_PARAM;
78  }
79 
80  /* report timings? */
81  pm->report_timings = ((msmflags & NL_MSM_REPORT_TIMINGS) != 0);
82 
83  /* for now, permit only orthogonal cell aligned with coordinate axes */
84  if (cellvec1[1] != 0 || cellvec1[2] != 0 ||
85  cellvec2[0] != 0 || cellvec2[2] != 0 ||
86  cellvec3[0] != 0 || cellvec3[1] != 0 ||
87  cellvec1[0] <= 0 || cellvec2[1] <= 0 || cellvec3[2] <= 0) {
88  return NL_MSM_ERROR_SUPPORT;
89  }
90 
91  /* check sanity of cutoff wrt expected cell;
92  * XXX cell widths must be at least the cutoff distance length */
93  if (cutoff <= 0 ||
94  (cutoff > cellvec1[0] && (msmflags & NL_MSM_PERIODIC_VEC1)) ||
95  (cutoff > cellvec2[1] && (msmflags & NL_MSM_PERIODIC_VEC2)) ||
96  (cutoff > cellvec3[2] && (msmflags & NL_MSM_PERIODIC_VEC3))) {
97  return NL_MSM_ERROR_PARAM;
98  }
99 
100  pm->msmflags = msmflags;
101  pm->cellvec1[0] = cellvec1[0];
102  pm->cellvec1[1] = cellvec1[1];
103  pm->cellvec1[2] = cellvec1[2];
104  pm->cellvec2[0] = cellvec2[0];
105  pm->cellvec2[1] = cellvec2[1];
106  pm->cellvec2[2] = cellvec2[2];
107  pm->cellvec3[0] = cellvec3[0];
108  pm->cellvec3[1] = cellvec3[1];
109  pm->cellvec3[2] = cellvec3[2];
110  pm->cellcenter[0] = cellcenter[0];
111  pm->cellcenter[1] = cellcenter[1];
112  pm->cellcenter[2] = cellcenter[2];
113 
114  pm->a = cutoff;
115 
116  rc = setup_cell_vectors(pm);
117  if (rc) return rc;
118 
119  if (msmflags & NL_MSM_COMPUTE_SHORT_RANGE) {
120  /* set up bins for short-range part */
121  if (msmflags & NL_MSM_COMPUTE_1AWAY) {
122  rc = setup_bins_1away(pm);
123  }
124  else {
125  rc = setup_bins_k_away(pm);
126  }
127  if (rc) return rc;
128  }
129 
130  if (msmflags & NL_MSM_COMPUTE_LONG_RANGE) {
131  /* set up grid hierarchy for long-range part */
132  rc = setup_grids(pm);
133  if (rc) return rc;
134  }
135 
136  if (msmflags & NL_MSM_COMPUTE_SPREC) {
137  /* fill out single precision data if needed */
138  pm->cellvec1_f[0] = (float) pm->cellvec1[0];
139  pm->cellvec1_f[1] = (float) pm->cellvec1[1];
140  pm->cellvec1_f[2] = (float) pm->cellvec1[2];
141  pm->cellvec2_f[0] = (float) pm->cellvec2[0];
142  pm->cellvec2_f[1] = (float) pm->cellvec2[1];
143  pm->cellvec2_f[2] = (float) pm->cellvec2[2];
144  pm->cellvec3_f[0] = (float) pm->cellvec3[0];
145  pm->cellvec3_f[1] = (float) pm->cellvec3[1];
146  pm->cellvec3_f[2] = (float) pm->cellvec3[2];
147  pm->cellcenter_f[0] = (float) pm->cellcenter[0];
148  pm->cellcenter_f[1] = (float) pm->cellcenter[1];
149  pm->cellcenter_f[2] = (float) pm->cellcenter[2];
150  pm->recipvec1_f[0] = (float) pm->recipvec1[0];
151  pm->recipvec1_f[1] = (float) pm->recipvec1[1];
152  pm->recipvec1_f[2] = (float) pm->recipvec1[2];
153  pm->recipvec2_f[0] = (float) pm->recipvec2[0];
154  pm->recipvec2_f[1] = (float) pm->recipvec2[1];
155  pm->recipvec2_f[2] = (float) pm->recipvec2[2];
156  pm->recipvec3_f[0] = (float) pm->recipvec3[0];
157  pm->recipvec3_f[1] = (float) pm->recipvec3[1];
158  pm->recipvec3_f[2] = (float) pm->recipvec3[2];
159  pm->hx_f = pm->hx;
160  pm->hy_f = pm->hy;
161  pm->hz_f = pm->hz;
162  pm->a_f = pm->a;
163  pm->gx_f = pm->gx;
164  pm->gy_f = pm->gy;
165  pm->gz_f = pm->gz;
166  }
167 
168  print_status(pm);
169 
170 #ifdef NL_USE_CUDA
171  if (msmflags & NL_MSM_COMPUTE_CUDA_GRID_CUTOFF) {
172  rc = NL_msm_cuda_setup_gridcutoff(pm);
173  if (rc == NL_MSM_SUCCESS) {
174  printf("Using CUDA for grid cutoff computation\n");
175  }
176  else {
177  printf("Unable to set up CUDA for grid cutoff computation\n");
178  if (msmflags & NL_MSM_COMPUTE_CUDA_FALL_BACK) {
179  NL_msm_cuda_cleanup_gridcutoff(pm);
180  printf("Falling back on CPU\n");
181  pm->msmflags &= ~NL_MSM_COMPUTE_CUDA_GRID_CUTOFF;
182  }
183  else return rc;
184  }
185  }
186 #else
187  if (msmflags & NL_MSM_COMPUTE_CUDA_GRID_CUTOFF) {
188  if (msmflags & NL_MSM_COMPUTE_CUDA_FALL_BACK) {
189  printf("Falling back on CPU\n");
190  pm->msmflags &= ~NL_MSM_COMPUTE_CUDA_GRID_CUTOFF;
191  }
192  else return NL_MSM_ERROR_SUPPORT;
193  }
194 #endif /* NL_USE_CUDA */
195 
196  return NL_MSM_SUCCESS;
197 }
static int setup_grids(NL_Msm *pm)
Definition: msm_setup.c:707
static int setup_bins_k_away(NL_Msm *pm)
Definition: msm_setup.c:420
static int setup_bins_1away(NL_Msm *pm)
Definition: msm_setup.c:318
static int print_status(NL_Msm *msm)
Definition: msm_setup.c:218
static int setup_cell_vectors(NL_Msm *pm)
Definition: msm_setup.c:281
int NL_msm_split ( const char *  name)

Helper function to determine SPLIT enum constant from string name.

Definition at line 210 of file msm.c.

References NELEMS, and SplitName.

210  {
211  int i;
212  if (name) {
213  for (i = 0; i < NELEMS(SplitName); i++) {
214  if (strcasecmp(name, SplitName[i]) == 0) return i;
215  }
216  }
217  return -1;
218 }
#define NELEMS(arr)
Definition: msm_defn.h:39
static const char * SplitName[]
Definition: msm.c:179
const char* NL_msm_split_name ( int  split)

Helper function returning string name for SPLIT enum constant.

Definition at line 220 of file msm.c.

References NELEMS, split(), and SplitName.

Referenced by print_status().

220  {
221  if (split >= 0 && split < NELEMS(SplitName)) {
222  return SplitName[split];
223  }
224  else return NULL;
225 }
#define NELEMS(arr)
Definition: msm_defn.h:39
std::vector< std::string > split(const std::string &text, std::string delimiter)
Definition: MoleculeQM.C:73
static const char * SplitName[]
Definition: msm.c:179