msm_defn.h File Reference

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <strings.h>
#include "msm.h"
#include "wkfutils.h"

Go to the source code of this file.

Classes

struct  NL_Msm_t

Defines

#define X   0
#define Y   1
#define Z   2
#define Q   3
#define NELEMS(arr)   (sizeof(arr)/sizeof(arr[0]))
#define GRID_TEMPLATE(TYPE)
#define GRID_INIT(_p)
#define GRID_DONE(_p)   free((_p)->buffer)
#define GRID_INDEX(_p, _i, _j, _k)   (((_k)*((_p)->nj) + (_j))*((_p)->ni) + (_i))
#define GRID_POINTER(_p, _i, _j, _k)   ((_p)->data + GRID_INDEX(_p, _i, _j, _k))
#define GRID_RESIZE(_p, TYPE, __i0, __ni, __j0, __nj, __k0, __nk)
#define GRID_ZERO(_p)   memset((_p)->buffer, 0, (_p)->numbytes)
#define ASSERT(expr)
#define GRID_INDEX_CHECK(a, _i, _j, _k)
#define DEFAULT_GRIDSPACING   2.5
#define DEFAULT_APPROX   NL_MSM_APPROX_CUBIC
#define DEFAULT_SPLIT   NL_MSM_SPLIT_TAYLOR2
#define DEFAULT_NLEVELS   0
#define DEFAULT_DENSITY   0.1
#define DEFAULT_BINFILL   0.8
#define DEFAULT_NBINSLOTS   8
#define SPOLY(pg, pdg, ra, split)
#define SPOLY_SPREC(pg, pdg, ra, split)

Functions

 GRID_TEMPLATE (double)
 GRID_TEMPLATE (float)
void NL_msm_cleanup (NL_Msm *pm)
int NL_msm_compute_short_range (NL_Msm *pm)
int NL_msm_compute_long_range (NL_Msm *pm)
int NL_msm_compute_short_range_sprec (NL_Msm *pm)
int NL_msm_compute_long_range_sprec (NL_Msm *pm)


Define Documentation

#define ASSERT ( expr   ) 

Definition at line 113 of file msm_defn.h.

#define DEFAULT_APPROX   NL_MSM_APPROX_CUBIC

Definition at line 120 of file msm_defn.h.

Referenced by NL_msm_create().

#define DEFAULT_BINFILL   0.8

Definition at line 125 of file msm_defn.h.

Referenced by NL_msm_create().

#define DEFAULT_DENSITY   0.1

Definition at line 124 of file msm_defn.h.

Referenced by NL_msm_create().

#define DEFAULT_GRIDSPACING   2.5

Default MSM parameters

Definition at line 119 of file msm_defn.h.

Referenced by NL_msm_create().

#define DEFAULT_NBINSLOTS   8

Definition at line 126 of file msm_defn.h.

Referenced by NL_msm_create().

#define DEFAULT_NLEVELS   0

Definition at line 122 of file msm_defn.h.

Referenced by NL_msm_create().

#define DEFAULT_SPLIT   NL_MSM_SPLIT_TAYLOR2

Definition at line 121 of file msm_defn.h.

Referenced by NL_msm_create().

#define GRID_DONE ( _p   )     free((_p)->buffer)

Finished with grid, free its memory

Definition at line 61 of file msm_defn.h.

Referenced by NL_msm_cleanup().

#define GRID_INDEX ( _p,
_i,
_j,
_k   )     (((_k)*((_p)->nj) + (_j))*((_p)->ni) + (_i))

Determine the signed flattened index for 3D grid datum

Definition at line 66 of file msm_defn.h.

Referenced by anterpolation(), gridcutoff(), and interpolation().

#define GRID_INDEX_CHECK ( a,
_i,
_j,
_k   ) 

Definition at line 114 of file msm_defn.h.

Referenced by anterpolation(), gridcutoff(), and interpolation().

#define GRID_INIT ( _p   ) 

Value:

((_p)->buffer=NULL, (_p)->data=NULL, (_p)->numbytes=0, (_p)->maxbytes=0, \
   (_p)->i0=0, (_p)->j0=0, (_p)->k0=0, (_p)->ni=0, (_p)->nj=0, (_p)->nk=0)
Initialize grid to empty

Definition at line 55 of file msm_defn.h.

Referenced by setup_grids().

#define GRID_POINTER ( _p,
_i,
_j,
_k   )     ((_p)->data + GRID_INDEX(_p, _i, _j, _k))

Obtain pointer to 3D grid datum

Definition at line 71 of file msm_defn.h.

#define GRID_RESIZE ( _p,
TYPE,
__i0,
__ni,
__j0,
__nj,
__k0,
__nk   ) 

Value:

do { \
    int _i0=(__i0), _ni=(__ni); \
    int _j0=(__j0), _nj=(__nj); \
    int _k0=(__k0), _nk=(__nk); \
    size_t _numbytes = (_nk * _nj) * (size_t) _ni * sizeof((_p)->buffer[0]); \
    if ((_p)->maxbytes < _numbytes) { \
      void *_t = realloc((_p)->buffer, _numbytes); \
      if (NULL == _t) return NL_MSM_ERROR_MALLOC; \
      (_p)->buffer = (TYPE *) _t; \
      (_p)->maxbytes = _numbytes; \
    } \
    (_p)->numbytes = _numbytes; \
    (_p)->i0 = _i0, (_p)->ni = _ni; \
    (_p)->j0 = _j0, (_p)->nj = _nj; \
    (_p)->k0 = _k0, (_p)->nk = _nk; \
    (_p)->data = (_p)->buffer + GRID_INDEX((_p), -_i0, -_j0, -_k0); \
  } while (0)
Resize 3D grid buffer, setup its indexing. Grab more memory when needed (must be used within function returning int).

Definition at line 77 of file msm_defn.h.

#define GRID_TEMPLATE ( TYPE   ) 

Value:

typedef struct NL_Msmgrid_##TYPE##_t { \
    TYPE *buffer;       /* raw buffer */ \
    TYPE *data;         /* data access offset from buffer */ \
    size_t numbytes;    /* number of bytes in use by buffer */ \
    size_t maxbytes;    /* actual allocation for buffer */ \
    int i0, j0, k0;     /* starting index value for each dimension */ \
    int ni, nj, nk;     /* number of elements in each dimension */ \
  } NL_Msmgrid_##TYPE
Template to create a 3D grid to access data of given TYPE

Definition at line 43 of file msm_defn.h.

#define GRID_ZERO ( _p   )     memset((_p)->buffer, 0, (_p)->numbytes)

Definition at line 98 of file msm_defn.h.

Referenced by anterpolation().

#define NELEMS ( arr   )     (sizeof(arr)/sizeof(arr[0]))

Return number of elements in static array

Definition at line 39 of file msm_defn.h.

Referenced by NL_msm_approx(), NL_msm_approx_name(), NL_msm_split(), and NL_msm_split_name().

#define Q   3

Definition at line 35 of file msm_defn.h.

Referenced by bin_evaluation_1away(), and bin_evaluation_k_away().

#define SPOLY ( pg,
pdg,
ra,
split   ) 

SPOLY() calculates the polynomial part of the normalized smoothing of 1/r.

Returns g(R), where R=r/a, and (d/dR)g(R).

pg - float*, points to variable to receive g(R) pdg - float*, points to variable to receive (d/dR)g(R) ra - (r/a), assumed to be between 0 and 1 split - identify the type of smoothing used to split the potential

Definition at line 140 of file msm_defn.h.

Referenced by bin_evaluation_1away(), bin_evaluation_k_away(), and ComputeNonbondedUtil::select().

#define SPOLY_SPREC ( pg,
pdg,
ra,
split   ) 

SPOLY_SPREC() calculates the polynomial part of the normalized smoothing of 1/r. Single precision version.

Returns g(R), where R=r/a, and (d/dR)g(R).

pg - float*, points to variable to receive g(R) pdg - float*, points to variable to receive (d/dR)g(R) ra - (r/a), assumed to be between 0 and 1 split - identify the type of smoothing used to split the potential

Definition at line 351 of file msm_defn.h.

Referenced by bin_evaluation_1away(), and bin_evaluation_k_away().

#define X   0

Index vectors for x,y,z,q coordinates

Definition at line 29 of file msm_defn.h.

Referenced by bin_evaluation_1away(), bin_evaluation_k_away(), setup_bins_1away(), setup_bins_k_away(), setup_cell_vectors(), and spatial_hashing().

#define Y   1

Definition at line 31 of file msm_defn.h.

Referenced by bin_evaluation_1away(), bin_evaluation_k_away(), setup_bins_1away(), setup_bins_k_away(), setup_cell_vectors(), and spatial_hashing().

#define Z   2

Definition at line 33 of file msm_defn.h.

Referenced by bin_evaluation_1away(), bin_evaluation_k_away(), setup_bins_1away(), setup_bins_k_away(), setup_cell_vectors(), and spatial_hashing().


Function Documentation

GRID_TEMPLATE ( float   ) 

GRID_TEMPLATE ( double   ) 

void NL_msm_cleanup ( NL_Msm pm  ) 

Definition at line 7 of file msm_setup.c.

References NL_Msm_t::eh, NL_Msm_t::eh_f, NL_Msm_t::gc, NL_Msm_t::gc_f, GRID_DONE, NL_Msm_t::lyzd, NL_Msm_t::lyzd_f, NL_Msm_t::lzd, NL_Msm_t::lzd_f, NL_Msm_t::maxlevels, NL_Msm_t::msmflags, NL_MSM_COMPUTE_CUDA_GRID_CUTOFF, NL_MSM_COMPUTE_SPREC, NL_Msm_t::qh, and NL_Msm_t::qh_f.

Referenced by NL_msm_destroy().

00007                                 {
00008   int i;
00009 #ifdef NL_USE_CUDA
00010   if (pm->msmflags & NL_MSM_COMPUTE_CUDA_GRID_CUTOFF) {
00011     NL_msm_cuda_cleanup_gridcutoff(pm);
00012   }
00013 #endif /* NL_USE_CUDA */
00014   if (pm->msmflags & NL_MSM_COMPUTE_SPREC) {
00015     for (i = 0;  i < pm->maxlevels;  i++) {
00016       GRID_DONE( &(pm->qh_f[i]) );
00017       GRID_DONE( &(pm->eh_f[i]) );
00018       GRID_DONE( &(pm->gc_f[i]) );
00019     }
00020   }
00021   else {
00022     for (i = 0;  i < pm->maxlevels;  i++) {
00023       GRID_DONE( &(pm->qh[i]) );
00024       GRID_DONE( &(pm->eh[i]) );
00025       GRID_DONE( &(pm->gc[i]) );
00026     }
00027   }
00028   free(pm->lzd);
00029   free(pm->lyzd);
00030   free(pm->lzd_f);
00031   free(pm->lyzd_f);
00032   free(pm->qh);
00033   free(pm->eh);
00034   free(pm->gc);
00035   free(pm->qh_f);
00036   free(pm->eh_f);
00037   free(pm->gc_f);
00038 }

int NL_msm_compute_long_range ( NL_Msm pm  ) 

Definition at line 52 of file msm_longrng.c.

References anterpolation(), gridcutoff(), interpolation(), NL_Msm_t::msmflags, NL_MSM_COMPUTE_CUDA_FALL_BACK, NL_MSM_COMPUTE_CUDA_GRID_CUTOFF, NL_MSM_COMPUTE_NONFACTORED, NL_MSM_ERROR_SUPPORT, NL_MSM_SUCCESS, NL_Msm_t::nlevels, prolongation(), prolongation_factored(), NL_Msm_t::report_timings, restriction(), restriction_factored(), NL_Msm_t::timer_longrng, wkf_timer_start(), wkf_timer_stop(), and wkf_timer_time().

Referenced by NL_msm_compute_force().

00052                                            {
00053   double time_delta;
00054   int rc = 0;
00055   int level;
00056   int nlevels = msm->nlevels;
00057   int use_cuda_gridcutoff = (msm->msmflags & NL_MSM_COMPUTE_CUDA_GRID_CUTOFF);
00058   int fallback_cpu = (msm->msmflags & NL_MSM_COMPUTE_CUDA_FALL_BACK);
00059   int use_nonfactored = (msm->msmflags & NL_MSM_COMPUTE_NONFACTORED);
00060 
00061   wkf_timer_start(msm->timer_longrng);
00062   rc = anterpolation(msm);
00063   if (rc) return rc;
00064   wkf_timer_stop(msm->timer_longrng);
00065   time_delta = wkf_timer_time(msm->timer_longrng);
00066   if (msm->report_timings) {
00067     printf("MSM anterpolation:  %6.3f sec\n", time_delta);
00068   }
00069 
00070   wkf_timer_start(msm->timer_longrng);
00071   if (use_nonfactored) {
00072     for (level = 0;  level < nlevels - 1;  level++) {
00073       rc = restriction(msm, level);
00074       if (rc) return rc;
00075     }
00076   }
00077   else {
00078     for (level = 0;  level < nlevels - 1;  level++) {
00079       rc = restriction_factored(msm, level);
00080       if (rc) return rc;
00081     }
00082   }
00083   wkf_timer_stop(msm->timer_longrng);
00084   time_delta = wkf_timer_time(msm->timer_longrng);
00085   if (msm->report_timings) {
00086     printf("MSM restriction:    %6.3f sec\n", time_delta);
00087   }
00088 
00089   wkf_timer_start(msm->timer_longrng);
00090   if (use_cuda_gridcutoff && nlevels > 1) {
00091 #ifdef NL_USE_CUDA
00092     if ((rc = NL_msm_cuda_condense_qgrids(msm)) != NL_MSM_SUCCESS ||
00093         (rc = NL_msm_cuda_compute_gridcutoff(msm)) != NL_MSM_SUCCESS ||
00094         (rc = NL_msm_cuda_expand_egrids(msm)) != NL_MSM_SUCCESS) {
00095       if (fallback_cpu) {
00096         printf("Falling back on CPU for grid cutoff computation\n");
00097         use_cuda_gridcutoff = 0;
00098       }
00099       else return rc;
00100     }
00101 #else
00102     if (fallback_cpu) {
00103       printf("Falling back on CPU for grid cutoff computation\n");
00104       use_cuda_gridcutoff = 0;
00105     }
00106     else return NL_MSM_ERROR_SUPPORT;
00107 #endif
00108   }
00109 
00110   if ( ! use_cuda_gridcutoff ) {
00111     for (level = 0;  level < nlevels - 1;  level++) {
00112       rc = gridcutoff(msm, level);
00113       if (rc) return rc;
00114     }
00115   }
00116 
00117   rc = gridcutoff(msm, level);  /* top level */
00118   if (rc) return rc;
00119 
00120   wkf_timer_stop(msm->timer_longrng);
00121   time_delta = wkf_timer_time(msm->timer_longrng);
00122   if (msm->report_timings) {
00123     printf("MSM grid cutoff:    %6.3f sec\n", time_delta);
00124   }
00125 
00126   wkf_timer_start(msm->timer_longrng);
00127   if (use_nonfactored) {
00128     for (level--;  level >= 0;  level--) {
00129       rc = prolongation(msm, level);
00130       if (rc) return rc;
00131     }
00132   }
00133   else {
00134     for (level--;  level >= 0;  level--) {
00135       rc = prolongation_factored(msm, level);
00136       if (rc) return rc;
00137     }
00138   }
00139   wkf_timer_stop(msm->timer_longrng);
00140   time_delta = wkf_timer_time(msm->timer_longrng);
00141   if (msm->report_timings) {
00142     printf("MSM prolongation:   %6.3f sec\n", time_delta);
00143   }
00144 
00145   wkf_timer_start(msm->timer_longrng);
00146   rc = interpolation(msm);
00147   if (rc) return rc;
00148   wkf_timer_stop(msm->timer_longrng);
00149   time_delta = wkf_timer_time(msm->timer_longrng);
00150   if (msm->report_timings) {
00151     printf("MSM interpolation:  %6.3f sec\n", time_delta);
00152   }
00153 
00154   return 0;
00155 }

int NL_msm_compute_long_range_sprec ( NL_Msm pm  ) 

Definition at line 52 of file msm_longrng_sprec.c.

References anterpolation(), gridcutoff(), interpolation(), NL_Msm_t::msmflags, NL_MSM_COMPUTE_CUDA_FALL_BACK, NL_MSM_COMPUTE_CUDA_GRID_CUTOFF, NL_MSM_COMPUTE_NONFACTORED, NL_MSM_ERROR_SUPPORT, NL_MSM_SUCCESS, NL_Msm_t::nlevels, prolongation(), prolongation_factored(), NL_Msm_t::report_timings, restriction(), restriction_factored(), NL_Msm_t::timer_longrng, wkf_timer_start(), wkf_timer_stop(), and wkf_timer_time().

Referenced by NL_msm_compute_force_sprec().

00052                                                  {
00053   double time_delta;
00054   int rc = 0;
00055   int level;
00056   int nlevels = msm->nlevels;
00057   int use_cuda_gridcutoff = (msm->msmflags & NL_MSM_COMPUTE_CUDA_GRID_CUTOFF);
00058   int fallback_cpu = (msm->msmflags & NL_MSM_COMPUTE_CUDA_FALL_BACK);
00059   int use_nonfactored = (msm->msmflags & NL_MSM_COMPUTE_NONFACTORED);
00060 
00061   wkf_timer_start(msm->timer_longrng);
00062   rc = anterpolation(msm);
00063   if (rc) return rc;
00064   wkf_timer_stop(msm->timer_longrng);
00065   time_delta = wkf_timer_time(msm->timer_longrng);
00066   if (msm->report_timings) {
00067     printf("MSM anterpolation:  %6.3f sec\n", time_delta);
00068   }
00069 
00070   wkf_timer_start(msm->timer_longrng);
00071   if (use_nonfactored) {
00072     for (level = 0;  level < nlevels - 1;  level++) {
00073       rc = restriction(msm, level);
00074       if (rc) return rc;
00075     }
00076   }
00077   else {
00078     for (level = 0;  level < nlevels - 1;  level++) {
00079       rc = restriction_factored(msm, level);
00080       if (rc) return rc;
00081     }
00082   }
00083   wkf_timer_stop(msm->timer_longrng);
00084   time_delta = wkf_timer_time(msm->timer_longrng);
00085   if (msm->report_timings) {
00086     printf("MSM restriction:    %6.3f sec\n", time_delta);
00087   }
00088 
00089   wkf_timer_start(msm->timer_longrng);
00090   if (use_cuda_gridcutoff && nlevels > 1) {
00091 #ifdef NL_USE_CUDA
00092     if ((rc = NL_msm_cuda_condense_qgrids(msm)) != NL_MSM_SUCCESS ||
00093         (rc = NL_msm_cuda_compute_gridcutoff(msm)) != NL_MSM_SUCCESS ||
00094         (rc = NL_msm_cuda_expand_egrids(msm)) != NL_MSM_SUCCESS) {
00095       if (fallback_cpu) {
00096         printf("Falling back on CPU for grid cutoff computation\n");
00097         use_cuda_gridcutoff = 0;
00098       }
00099       else return rc;
00100     }
00101 #else
00102     if (fallback_cpu) {
00103       printf("Falling back on CPU for grid cutoff computation\n");
00104       use_cuda_gridcutoff = 0;
00105     }
00106     else return NL_MSM_ERROR_SUPPORT;
00107 #endif
00108   }
00109 
00110   if ( ! use_cuda_gridcutoff ) {
00111     for (level = 0;  level < nlevels - 1;  level++) {
00112       rc = gridcutoff(msm, level);
00113       if (rc) return rc;
00114     }
00115   }
00116 
00117   rc = gridcutoff(msm, level);  /* top level */
00118   if (rc) return rc;
00119 
00120   wkf_timer_stop(msm->timer_longrng);
00121   time_delta = wkf_timer_time(msm->timer_longrng);
00122   if (msm->report_timings) {
00123     printf("MSM grid cutoff:    %6.3f sec\n", time_delta);
00124   }
00125 
00126   wkf_timer_start(msm->timer_longrng);
00127   if (use_nonfactored) {
00128     for (level--;  level >= 0;  level--) {
00129       rc = prolongation(msm, level);
00130       if (rc) return rc;
00131     }
00132   }
00133   else {
00134     for (level--;  level >= 0;  level--) {
00135       rc = prolongation_factored(msm, level);
00136       if (rc) return rc;
00137     }
00138   }
00139   wkf_timer_stop(msm->timer_longrng);
00140   time_delta = wkf_timer_time(msm->timer_longrng);
00141   if (msm->report_timings) {
00142     printf("MSM prolongation:   %6.3f sec\n", time_delta);
00143   }
00144 
00145   wkf_timer_start(msm->timer_longrng);
00146   rc = interpolation(msm);
00147   if (rc) return rc;
00148   wkf_timer_stop(msm->timer_longrng);
00149   time_delta = wkf_timer_time(msm->timer_longrng);
00150   if (msm->report_timings) {
00151     printf("MSM interpolation:  %6.3f sec\n", time_delta);
00152   }
00153 
00154   return 0;
00155 }

int NL_msm_compute_short_range ( NL_Msm pm  ) 

Definition at line 37 of file msm_shortrng.c.

References bin_evaluation_1away(), bin_evaluation_k_away(), NL_Msm_t::maxatoms, NL_Msm_t::msmflags, NL_MSM_COMPUTE_1AWAY, NL_MSM_SUCCESS, NL_Msm_t::numatoms, setup_bin_data(), and spatial_hashing().

Referenced by NL_msm_compute_force().

00037                                            {
00038   int rc = 0;  /* return code */
00039 
00040   if (pm->maxatoms < pm->numatoms) {
00041     rc = setup_bin_data(pm);
00042     if (rc) return rc;
00043   }
00044   rc = spatial_hashing(pm);
00045   if (rc) return rc;
00046   if (pm->msmflags & NL_MSM_COMPUTE_1AWAY) {
00047     rc = bin_evaluation_1away(pm);
00048   }
00049   else {
00050     rc = bin_evaluation_k_away(pm);
00051   }
00052   if (rc) return rc;
00053   return NL_MSM_SUCCESS;
00054 }

int NL_msm_compute_short_range_sprec ( NL_Msm pm  ) 

Definition at line 37 of file msm_shortrng_sprec.c.

References bin_evaluation_1away(), bin_evaluation_k_away(), NL_Msm_t::maxatoms, NL_Msm_t::msmflags, NL_MSM_COMPUTE_1AWAY, NL_MSM_SUCCESS, NL_Msm_t::numatoms, setup_bin_data(), and spatial_hashing().

Referenced by NL_msm_compute_force_sprec().

00037                                                  {
00038   int rc = 0;  /* return code */
00039 
00040   if (pm->maxatoms < pm->numatoms) {
00041     rc = setup_bin_data(pm);
00042     if (rc) return rc;
00043   }
00044   rc = spatial_hashing(pm);
00045   if (rc) return rc;
00046   if (pm->msmflags & NL_MSM_COMPUTE_1AWAY) {
00047     rc = bin_evaluation_1away(pm);
00048   }
00049   else {
00050     rc = bin_evaluation_k_away(pm);
00051   }
00052   if (rc) return rc;
00053   return NL_MSM_SUCCESS;
00054 }


Generated on Wed Nov 22 01:17:18 2017 for NAMD by  doxygen 1.4.7