Add copyright and fix style

This commit is contained in:
Vsevak
2019-11-17 22:22:56 +03:00
parent ca8d1ac2ff
commit 4febc7f794
7 changed files with 684 additions and 589 deletions

View File

@ -102,6 +102,9 @@ pair\_style lj/cut/tip4p/long/omp command
pair\_style lj/cut/tip4p/long/opt command
=========================================
pair\_style lj/cut/tip4p/long/gpu command
=====================================
Syntax
""""""

View File

@ -1,3 +1,18 @@
/**************************************************************************
lj_tip4p_long.cpp
-------------------
V. Nikolskiy (HSE)
Class for acceleration of the lj/tip4p/long pair style
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : thevsevak@gmail.com
***************************************************************************/
#if defined(USE_OPENCL)
#include "lj_tip4p_long_cl.h"
#elif defined(USE_CUDART)
@ -29,21 +44,21 @@ int LJ_TIP4PLong<numtyp, acctyp>::bytes_per_atom(const int max_nbors) const {
template <class numtyp, class acctyp>
int LJ_TIP4PLong<numtyp, acctyp>::init(const int ntypes,
double **host_cutsq, double **host_lj1,
double **host_lj2, double **host_lj3,
double **host_lj4, double **host_offset,
double *host_special_lj, const int nlocal,
const int tH, const int tO,
const double a, const double qd,
const int nall, const int max_nbors,
const int maxspecial, const double cell_size,
const double gpu_split, FILE *_screen,
double **host_cut_ljsq,
const double host_cut_coulsq, const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same) {
double **host_cutsq, double **host_lj1,
double **host_lj2, double **host_lj3,
double **host_lj4, double **host_offset,
double *host_special_lj, const int nlocal,
const int tH, const int tO,
const double a, const double qd,
const int nall, const int max_nbors,
const int maxspecial, const double cell_size,
const double gpu_split, FILE *_screen,
double **host_cut_ljsq,
const double host_cut_coulsq, const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same) {
int success;
success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
_screen,lj_tip4p_long,"k_lj_tip4p_long");
@ -91,7 +106,7 @@ int LJ_TIP4PLong<numtyp, acctyp>::init(const int ntypes,
}
ucl_copy(sp_lj,host_write,8,false);
force_comp.alloc(72*72, *(this->ucl_device), UCL_READ_WRITE);
//force_comp.alloc(72*72, *(this->ucl_device), UCL_READ_WRITE);
_qqrd2e=qqrd2e;
_g_ewald=g_ewald;
@ -103,26 +118,26 @@ int LJ_TIP4PLong<numtyp, acctyp>::init(const int ntypes,
ansO.alloc(nall,*(this->ucl_device), UCL_READ_WRITE);
// Allocate a host write buffer for data initialization
UCL_H_Vec<int> host_tag_write(nall,*(this->ucl_device),UCL_WRITE_ONLY);
this->tag.alloc(nall,*(this->ucl_device), UCL_READ_WRITE);
UCL_H_Vec<int> host_tag_write(nall,*(this->ucl_device),UCL_READ_WRITE);
this->tag.alloc(nall,*(this->ucl_device), UCL_READ_ONLY);
for(int i=0; i<nall; ++i) host_tag_write[i] = tag[i];
ucl_copy(this->tag, host_tag_write, nall, false);
//if(max_same>host_tag_write.cols()) host_tag_write.resize(max_same);
this->atom_sametag.alloc(nall, *(this->ucl_device), UCL_READ_WRITE);
this->atom_sametag.alloc(nall, *(this->ucl_device), UCL_READ_ONLY);
for(int i=0; i<nall; ++i) host_tag_write[i] = sametag[i];
ucl_copy(this->atom_sametag, host_tag_write, nall, false);
if(map_size>host_tag_write.cols()) host_tag_write.resize(map_size);
this->map_array.alloc(map_size,*(this->ucl_device), UCL_READ_WRITE);
host_tag_write.resize_ib(map_size);
this->map_array.alloc(map_size,*(this->ucl_device), UCL_READ_ONLY);
for(int i=0; i<map_size; ++i) host_tag_write[i] = map_array[i];
ucl_copy(this->map_array, host_tag_write, map_size, false);
_allocated=true;
this->_max_bytes=lj1.row_bytes()+lj3.row_bytes()+cutsq.row_bytes()+
sp_lj.row_bytes() + hneight.row_bytes()+m.row_bytes()+
this->tag.row_bytes()+this->atom_sametag.row_bytes() +
this->map_array.row_bytes();
sp_lj.row_bytes() + hneight.row_bytes()+m.row_bytes()+
this->tag.row_bytes()+this->atom_sametag.row_bytes() +
this->map_array.row_bytes();
return 0;
}
@ -143,7 +158,7 @@ void LJ_TIP4PLong<numtyp, acctyp>::clear() {
atom_sametag.clear();
map_array.clear();
ansO.clear();
force_comp.clear();
//force_comp.clear();
k_pair_distrib.clear();
@ -192,47 +207,47 @@ void LJ_TIP4PLong<numtyp, acctyp>::loop(const bool _eflag, const bool _vflag) {
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&this->ans->force, &this->ans->engv, &eflag, &vflag,
&ainum, &nbor_pitch, &this->_threads_per_atom,
&hneight, &m, &TypeO, &TypeH, &alpha,
&this->atom->q, &cutsq, &_qqrd2e, &_g_ewald,
&cut_coulsq, &cut_coulsqplus, &tag, &map_array,
&atom_sametag, &this->ansO);
&hneight, &m, &TypeO, &TypeH, &alpha,
&this->atom->q, &cutsq, &_qqrd2e, &_g_ewald,
&cut_coulsq, &cut_coulsqplus, &tag, &map_array,
&atom_sametag, &this->ansO);
GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/BX));
this->k_pair_distrib.set_size(GX,BX);
this->k_pair_distrib.run(&this->atom->x, &this->ans->force, &this->ans->engv, &eflag, &vflag,
&ainum, &nbor_pitch, &this->_threads_per_atom,
&hneight, &m, &TypeO, &TypeH, &alpha,
&this->atom->q, &this->ansO);
&ainum, &nbor_pitch, &this->_threads_per_atom,
&hneight, &m, &TypeO, &TypeH, &alpha,
&this->atom->q, &this->ansO);
this->time_pair.stop();
}
template <class numtyp, class acctyp>
void LJ_TIP4PLong<numtyp, acctyp>::copy_relations_data(int **hn, double **newsite, int n,
int* tag, int *map_array, int map_size, int *sametag, int max_same, int ago){
int nall = n;
const int hn_sz = n*4; // matrix size = col size * col number
hneight.resize_ib(hn_sz+1);
if (ago == 0)
hneight.zero();
m.resize_ib(n+1);
m.zero();
int* tag, int *map_array, int map_size, int *sametag, int max_same, int ago){
int nall = n;
const int hn_sz = n*4; // matrix size = col size * col number
hneight.resize_ib(hn_sz);
if (ago == 0)
hneight.zero();
m.resize_ib(n);
m.zero();
UCL_H_Vec<int> host_tag_write(nall,*(this->ucl_device),UCL_WRITE_ONLY);
this->tag.resize_ib(nall);
for(int i=0; i<nall; ++i) host_tag_write[i] = tag[i];
ucl_copy(this->tag, host_tag_write, nall, false);
UCL_H_Vec<int> host_tag_write(nall,*(this->ucl_device),UCL_WRITE_ONLY);
this->tag.resize_ib(nall);
for(int i=0; i<nall; ++i) host_tag_write[i] = tag[i];
ucl_copy(this->tag, host_tag_write, nall, false);
if(max_same>host_tag_write.cols()) host_tag_write.resize(max_same);
this->atom_sametag.resize_ib(nall);
for(int i=0; i<nall; ++i) host_tag_write[i] = sametag[i];
ucl_copy(this->atom_sametag, host_tag_write, nall, false);
host_tag_write.resize_ib(max_same);
this->atom_sametag.resize_ib(nall);
for(int i=0; i<nall; ++i) host_tag_write[i] = sametag[i];
ucl_copy(this->atom_sametag, host_tag_write, nall, false);
if(map_size>host_tag_write.cols()) host_tag_write.resize(map_size);
this->map_array.resize_ib(map_size);
for(int i=0; i<map_size; ++i) host_tag_write[i] = map_array[i];
ucl_copy(this->map_array, host_tag_write, map_size, false);
host_tag_write.resize_ib(map_size);
this->map_array.resize_ib(map_size);
for(int i=0; i<map_size; ++i) host_tag_write[i] = map_array[i];
ucl_copy(this->map_array, host_tag_write, map_size, false);
host_tag_write.clear();
host_tag_write.clear();
}
template class LJ_TIP4PLong<PRECISION,ACC_PRECISION>;

View File

@ -1,3 +1,18 @@
// **************************************************************************
// lj_tip4p_long.cu
// -------------------
// V. Nikolskiy (HSE)
//
// Device code for acceleration of the lj/tip4p/long pair style
//
// __________________________________________________________________________
// This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
// __________________________________________________________________________
//
// begin :
// email : thevsevak@gmail.com
// ***************************************************************************/
#ifdef NV_KERNEL
#include "lal_aux_fun1.h"
@ -14,6 +29,8 @@ texture<int2> q_tex;
#define q_tex q_
#endif
#include <float.h>
ucl_inline int atom_mapping(const __global int *map, int glob){
return map[glob];
}
@ -50,484 +67,487 @@ ucl_inline int closest_image(int i, int j, const __global int* sametag,
}
ucl_inline void compute_newsite(int iO, int iH1, int iH2,
__global numtyp4 *xM,
numtyp alpha, const __global numtyp4 *restrict x_){
numtyp4 xO; fetch4(xO,iO,pos_tex);
numtyp4 xH1; fetch4(xH1,iH1,pos_tex);
numtyp4 xH2; fetch4(xH2,iH2,pos_tex);
__global numtyp4 *xM,
numtyp alpha, const __global numtyp4 *restrict x_){
numtyp4 xO; fetch4(xO,iO,pos_tex);
numtyp4 xH1; fetch4(xH1,iH1,pos_tex);
numtyp4 xH2; fetch4(xH2,iH2,pos_tex);
numtyp delx1 = xH1.x - xO.x;
numtyp dely1 = xH1.y - xO.y;
numtyp delz1 = xH1.z - xO.z;
numtyp delx1 = xH1.x - xO.x;
numtyp dely1 = xH1.y - xO.y;
numtyp delz1 = xH1.z - xO.z;
numtyp delx2 = xH2.x - xO.x;
numtyp dely2 = xH2.y - xO.y;
numtyp delz2 = xH2.z - xO.z;
numtyp delx2 = xH2.x - xO.x;
numtyp dely2 = xH2.y - xO.y;
numtyp delz2 = xH2.z - xO.z;
numtyp ap = alpha * (numtyp)0.5;
numtyp ap = alpha * (numtyp)0.5;
(*xM).x = xO.x + ap * (delx1 + delx2);
(*xM).y = xO.y + ap * (dely1 + dely2);
(*xM).z = xO.z + ap * (delz1 + delz2);
(*xM).x = xO.x + ap * (delx1 + delx2);
(*xM).y = xO.y + ap * (dely1 + dely2);
(*xM).z = xO.z + ap * (delz1 + delz2);
}
__kernel void k_lj_tip4p_long_distrib(const __global numtyp4 *restrict x_,
__global acctyp4 *restrict ans,
__global acctyp *restrict engv,
const int eflag, const int vflag, const int inum,
const int nbor_pitch, const int t_per_atom,
__global int *restrict hneigh,
__global numtyp4 *restrict m,
const int typeO, const int typeH,
const numtyp alpha,
const __global numtyp *restrict q_, const __global acctyp4 *restrict ansO) {
int tid, ii, offset;
atom_info(t_per_atom,ii,tid,offset);
int i = BLOCK_ID_X*(BLOCK_SIZE_X)+tid;
__global acctyp4 *restrict ans,
__global acctyp *restrict engv,
const int eflag, const int vflag, const int inum,
const int nbor_pitch, const int t_per_atom,
__global int *restrict hneigh,
__global numtyp4 *restrict m,
const int typeO, const int typeH,
const numtyp alpha,
const __global numtyp *restrict q_, const __global acctyp4 *restrict ansO) {
int tid, ii, offset;
atom_info(t_per_atom,ii,tid,offset);
int i = BLOCK_ID_X*(BLOCK_SIZE_X)+tid;
acctyp4 f;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
acctyp4 f;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
if (i<inum) {
numtyp4 ix; fetch4(ix,i,pos_tex);// = x_[i];
int itype = ix.w;
acctyp4 fM, vM;
acctyp eM;
if (itype == typeH) {
int iO = hneigh[i*4];
if (iO < inum) {
fM = ansO[iO];
f.x += fM.x * (acctyp)0.5 * alpha;
f.y += fM.y * (acctyp)0.5 * alpha;
f.z += fM.z * (acctyp)0.5 * alpha;
if (vflag > 0) {
vM = ansO[inum +iO];
engv[inum*2 + i] += vM.x * (acctyp)0.5 * alpha;
engv[inum*3 + i] += vM.y * (acctyp)0.5 * alpha;
engv[inum*4 + i] += vM.z * (acctyp)0.5 * alpha;
vM = ansO[inum*2+iO];
engv[inum*5 + i] += vM.x * (acctyp)0.5 * alpha;
engv[inum*6 + i] += vM.y * (acctyp)0.5 * alpha;
engv[inum*7 + i] += vM.z * (acctyp)0.5 * alpha;
}
}
} else {
fM = ansO[i];
int iH1 = hneigh[i*4 ];
int iH2 = hneigh[i*4+1];
f.x += fM.x * (acctyp)(1 - alpha);
f.y += fM.y * (acctyp)(1 - alpha);
f.z += fM.z * (acctyp)(1 - alpha);
if (eflag > 0) {
eM = engv[i+inum];
engv[inum+i] = eM*(acctyp)(1 - alpha);
if (iH1 < inum) engv[inum+iH1] += eM * (acctyp)0.5 * alpha;
if (iH2 < inum) engv[inum+iH2] += eM * (acctyp)0.5 * alpha;
}
if (vflag > 0) {
vM = ansO[inum + i];
engv[inum*2 + i] += vM.x * (acctyp)(1 - alpha);
engv[inum*3 + i] += vM.y * (acctyp)(1 - alpha);
engv[inum*4 + i] += vM.z * (acctyp)(1 - alpha);
vM = ansO[inum*2 + i];
engv[inum*5 + i] += vM.x * (acctyp)(1 - alpha);
engv[inum*6 + i] += vM.y * (acctyp)(1 - alpha);
engv[inum*7 + i] += vM.z * (acctyp)(1 - alpha);
}
}
acctyp4 old=ans[i];
old.x+=f.x;
old.y+=f.y;
old.z+=f.z;
ans[i]=old;
} // if ii
if (i<inum) {
numtyp4 ix; fetch4(ix,i,pos_tex);// = x_[i];
int itype = ix.w;
acctyp4 fM, vM;
acctyp eM;
if (itype == typeH) {
int iO = hneigh[i*4];
if (iO < inum) {
fM = ansO[iO];
f.x += fM.x * (acctyp)0.5 * alpha;
f.y += fM.y * (acctyp)0.5 * alpha;
f.z += fM.z * (acctyp)0.5 * alpha;
if (vflag > 0) {
vM = ansO[inum +iO];
engv[inum*2 + i] += vM.x * (acctyp)0.5 * alpha;
engv[inum*3 + i] += vM.y * (acctyp)0.5 * alpha;
engv[inum*4 + i] += vM.z * (acctyp)0.5 * alpha;
vM = ansO[inum*2+iO];
engv[inum*5 + i] += vM.x * (acctyp)0.5 * alpha;
engv[inum*6 + i] += vM.y * (acctyp)0.5 * alpha;
engv[inum*7 + i] += vM.z * (acctyp)0.5 * alpha;
}
}
} else {
fM = ansO[i];
int iH1 = hneigh[i*4 ];
int iH2 = hneigh[i*4+1];
f.x += fM.x * (acctyp)(1 - alpha);
f.y += fM.y * (acctyp)(1 - alpha);
f.z += fM.z * (acctyp)(1 - alpha);
if (eflag > 0) {
eM = engv[i+inum];
engv[inum+i] = eM*(acctyp)(1 - alpha);
if (iH1 < inum) engv[inum+iH1] += eM * (acctyp)0.5 * alpha;
if (iH2 < inum) engv[inum+iH2] += eM * (acctyp)0.5 * alpha;
}
if (vflag > 0) {
vM = ansO[inum + i];
engv[inum*2 + i] += vM.x * (acctyp)(1 - alpha);
engv[inum*3 + i] += vM.y * (acctyp)(1 - alpha);
engv[inum*4 + i] += vM.z * (acctyp)(1 - alpha);
vM = ansO[inum*2 + i];
engv[inum*5 + i] += vM.x * (acctyp)(1 - alpha);
engv[inum*6 + i] += vM.y * (acctyp)(1 - alpha);
engv[inum*7 + i] += vM.z * (acctyp)(1 - alpha);
}
}
acctyp4 old=ans[i];
old.x+=f.x;
old.y+=f.y;
old.z+=f.z;
ans[i]=old;
} // if ii
}
__kernel void k_lj_tip4p_long(const __global numtyp4 *restrict x_,
const __global numtyp4 *restrict lj1,
const __global numtyp4 *restrict lj3,
const int lj_types,
const __global numtyp *restrict sp_lj,
const __global int * dev_nbor,
const __global int * dev_packed,
__global acctyp4 *restrict ans,
__global acctyp *restrict engv,
const int eflag, const int vflag, const int inum,
const int nbor_pitch, const int t_per_atom,
__global int *restrict hneigh,
__global numtyp4 *restrict m,
const int typeO, const int typeH,
const numtyp alpha,
const __global numtyp *restrict q_,
const __global numtyp *restrict cutsq,
const numtyp qqrd2e, const numtyp g_ewald,
const numtyp cut_coulsq, const numtyp cut_coulsqplus,
const __global int *restrict tag, const __global int *restrict map,
const __global int *restrict sametag, __global acctyp4 *restrict ansO) {
int tid, ii, offset;
atom_info(t_per_atom,ii,tid,offset);
const __global numtyp4 *restrict lj1,
const __global numtyp4 *restrict lj3,
const int lj_types,
const __global numtyp *restrict sp_lj,
const __global int * dev_nbor,
const __global int * dev_packed,
__global acctyp4 *restrict ans,
__global acctyp *restrict engv,
const int eflag, const int vflag, const int inum,
const int nbor_pitch, const int t_per_atom,
__global int *restrict hneigh,
__global numtyp4 *restrict m,
const int typeO, const int typeH,
const numtyp alpha,
const __global numtyp *restrict q_,
const __global numtyp *restrict cutsq,
const numtyp qqrd2e, const numtyp g_ewald,
const numtyp cut_coulsq, const numtyp cut_coulsqplus,
const __global int *restrict tag, const __global int *restrict map,
const __global int *restrict sametag, __global acctyp4 *restrict ansO) {
int tid, ii, offset;
atom_info(t_per_atom,ii,tid,offset);
acctyp energy = (acctyp)0;
acctyp e_coul = (acctyp)0;
acctyp4 f, fO;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
fO.x=(acctyp)0; fO.y=(acctyp)0; fO.z=(acctyp)0;
acctyp virial[6],vO[6];
for (int i=0; i<6; i++) {
virial[i]=(acctyp)0;
vO[i]=(acctyp)0;
}
acctyp energy = (acctyp)0;
acctyp e_coul = (acctyp)0;
acctyp4 f, fO;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
fO.x=(acctyp)0; fO.y=(acctyp)0; fO.z=(acctyp)0;
acctyp virial[6],vO[6];
for (int i=0; i<6; i++) {
virial[i]=(acctyp)0;
vO[i]=(acctyp)0;
}
if (ii<inum) {
int i, numj, nbor, nbor_end;
__local int n_stride;
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
n_stride,nbor_end,nbor);
if (ii<inum) {
int i, numj, nbor, nbor_end;
__local int n_stride;
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
n_stride,nbor_end,nbor);
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
numtyp qtmp; fetch(qtmp,i,q_tex);
int itype = ix.w;
numtyp4 x1 = ix;
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
numtyp qtmp; fetch(qtmp,i,q_tex);
int itype = ix.w;
numtyp4 x1 = ix;
int non_local_oxy = 0;
int iH1, iH2, iO;
int non_local_oxy = 0;
int iH1, iH2, iO;
if(itype == typeO) {
iO = i;
if (hneigh[i*4+2] != -1) {
iH1 = atom_mapping(map, tag[i] + 1);
iH2 = atom_mapping(map, tag[i] + 2);
// set iH1,iH2 to closest image to O
iH1 = closest_image(i, iH1, sametag, x_);
iH2 = closest_image(i, iH2, sametag, x_);
hneigh[ i*4 ] = iH1;
hneigh[ i*4+1] = iH2;
hneigh[ i*4+2] = -1;
hneigh[iH1*4 ] = i;
hneigh[iH1*4+1] += -1;
hneigh[iH1*4+2] = -1;
hneigh[iH2*4 ] = i;
hneigh[iH2*4+1] += -1;
hneigh[iH2*4+2] = -1;
} else {
iH1 = hneigh[i*4 ];
iH2 = hneigh[i*4+1];
}
if(m[iO].w == 0) {
compute_newsite(iO,iH1,iH2, &m[iO], alpha, x_);
m[iO].w = qtmp;
}
x1 = m[iO];
} else {
if (hneigh[i*4+2] != -1) {
int iI, iH;
iI = atom_mapping(map,tag[i] - 1);
numtyp4 iIx; fetch4(iIx,iI,pos_tex); //x_[iI];
if (iIx.w == typeH) {
iO = atom_mapping(map,tag[i] - 2);
iO = closest_image(i, iO, sametag, x_);
iH1 = closest_image(i, iI, sametag, x_);
iH2 = i;
} else if (iIx.w == typeO) {
iH = atom_mapping(map, tag[i] + 1);
iO = closest_image(i,iI,sametag, x_);
iH1 = i;
iH2 = closest_image(i,iH,sametag, x_);
}
if(itype == typeO) {
iO = i;
if (hneigh[i*4+2] != -1) {
iH1 = atom_mapping(map, tag[i] + 1);
iH2 = atom_mapping(map, tag[i] + 2);
// set iH1,iH2 to closest image to O
iH1 = closest_image(i, iH1, sametag, x_);
iH2 = closest_image(i, iH2, sametag, x_);
hneigh[ i*4 ] = iH1;
hneigh[ i*4+1] = iH2;
hneigh[ i*4+2] = -1;
hneigh[iH1*4 ] = i;
hneigh[iH1*4+1] += -1;
hneigh[iH1*4+2] = -1;
hneigh[iH2*4 ] = i;
hneigh[iH2*4+1] += -1;
hneigh[iH2*4+2] = -1;
} else {
iH1 = hneigh[i*4 ];
iH2 = hneigh[i*4+1];
}
if(fabs(m[iO].w) <= FLT_EPSILON) {
compute_newsite(iO,iH1,iH2, &m[iO], alpha, x_);
m[iO].w = qtmp;
}
x1 = m[iO];
} else {
if (hneigh[i*4+2] != -1) {
int iI, iH;
iI = atom_mapping(map,tag[i] - 1);
numtyp4 iIx; fetch4(iIx,iI,pos_tex); //x_[iI];
if ((int)iIx.w == typeH) {
iO = atom_mapping(map,tag[i] - 2);
iO = closest_image(i, iO, sametag, x_);
iH1 = closest_image(i, iI, sametag, x_);
iH2 = i;
} else { //if ((int)iIx.w == typeO)
iH = atom_mapping(map, tag[i] + 1);
iO = closest_image(i,iI,sametag, x_);
iH1 = i;
iH2 = closest_image(i,iH,sametag, x_);
}
hneigh[iH1*4+0] = iO;
hneigh[iH1*4+1] += -1;
hneigh[iH1*4+2] = -1;
hneigh[iH1*4+0] = iO;
hneigh[iH1*4+1] += -1;
hneigh[iH1*4+2] = -1;
hneigh[iH2*4+0] = iO;
hneigh[iH2*4+1] += -1;
hneigh[iH2*4+2] = -1;
hneigh[iH2*4+0] = iO;
hneigh[iH2*4+1] += -1;
hneigh[iH2*4+2] = -1;
hneigh[iO*4+0] = iH1;
hneigh[iO*4+1] = iH2;
hneigh[iO*4+2] = -1;
} else {
iO = hneigh[i *4 ];
iH1 = hneigh[iO*4 ];
iH2 = hneigh[iO*4+1];
}
if (iO >= inum) {
non_local_oxy = 1;
if(m[iO].w == 0) {
compute_newsite(iO,iH1,iH2, &m[iO], alpha, x_);
numtyp qO; fetch(qO,iO,q_tex);
m[iO].w = qO;
}
}
}
hneigh[iO*4+0] = iH1;
hneigh[iO*4+1] = iH2;
hneigh[iO*4+2] = -1;
} else {
iO = hneigh[i *4 ];
iH1 = hneigh[iO*4 ];
iH2 = hneigh[iO*4+1];
}
if (iO >= inum) {
non_local_oxy = 1;
if(fabs(m[iO].w) <= FLT_EPSILON) {
compute_newsite(iO,iH1,iH2, &m[iO], alpha, x_);
numtyp qO; fetch(qO,iO,q_tex);
m[iO].w = qO;
}
}
}
for ( ; nbor<nbor_end; nbor+=n_stride) {
int j=dev_packed[nbor];
for ( ; nbor<nbor_end; nbor+=n_stride) {
int j=dev_packed[nbor];
numtyp factor_lj,factor_coul;
factor_lj = sp_lj[sbmask(j)];
factor_coul = (numtyp)1.0-sp_lj[sbmask(j)+4];
j &= NEIGHMASK;
numtyp factor_lj,factor_coul;
factor_lj = sp_lj[sbmask(j)];
factor_coul = (numtyp)1.0-sp_lj[sbmask(j)+4];
j &= NEIGHMASK;
numtyp4 jx; fetch4(jx,j,pos_tex); //x_[j];
int jtype = jx.w;
numtyp4 jx; fetch4(jx,j,pos_tex); //x_[j];
int jtype = jx.w;
// Compute r12
numtyp delx = ix.x-jx.x;
numtyp dely = ix.y-jx.y;
numtyp delz = ix.z-jx.z;
numtyp rsq = delx*delx+dely*dely+delz*delz;
// Compute r12
numtyp delx = ix.x-jx.x;
numtyp dely = ix.y-jx.y;
numtyp delz = ix.z-jx.z;
numtyp rsq = delx*delx+dely*dely+delz*delz;
int mtype = itype*lj_types+jtype;
if (rsq < lj1[mtype].z) { // cut_ljsq
numtyp r2inv = ucl_recip(rsq);
numtyp r6inv = r2inv*r2inv*r2inv;
numtyp forcelj = r6inv*(lj1[mtype].x*r6inv-lj1[mtype].y);
forcelj *= r2inv*factor_lj;
int mtype = itype*lj_types+jtype;
if (rsq < lj1[mtype].z) { // cut_ljsq
numtyp r2inv = ucl_recip(rsq);
numtyp r6inv = r2inv*r2inv*r2inv;
numtyp forcelj = r6inv*(lj1[mtype].x*r6inv-lj1[mtype].y);
forcelj *= r2inv*factor_lj;
f.x += delx*forcelj;
f.y += dely*forcelj;
f.z += delz*forcelj;
f.x += delx*forcelj;
f.y += dely*forcelj;
f.z += delz*forcelj;
if (eflag>0) {
numtyp e = r6inv * (lj3[mtype].x*r6inv-lj3[mtype].y);
energy += factor_lj * (e - lj3[mtype].z);
}
if (vflag>0) {
virial[0] += delx*delx*forcelj;
virial[1] += dely*dely*forcelj;
virial[2] += delz*delz*forcelj;
virial[3] += delx*dely*forcelj;
virial[4] += delx*delz*forcelj;
virial[5] += dely*delz*forcelj;
}
} // if LJ
if (eflag>0) {
numtyp e = r6inv * (lj3[mtype].x*r6inv-lj3[mtype].y);
energy += factor_lj * (e - lj3[mtype].z);
}
if (vflag>0) {
virial[0] += delx*delx*forcelj;
virial[1] += dely*dely*forcelj;
virial[2] += delz*delz*forcelj;
virial[3] += delx*dely*forcelj;
virial[4] += delx*delz*forcelj;
virial[5] += dely*delz*forcelj;
}
} // if LJ
if (rsq < cut_coulsqplus) { //cut_coulsqplus
int jH1, jH2, jO;
numtyp qj; fetch(qj,j,q_tex);
numtyp4 x2 = jx;
if(itype == typeO || jtype == typeO) {
if (jtype == typeO) {
jO = j;
if (hneigh[j*4+2] != -1) {
jH1 = atom_mapping(map,tag[j] + 1);
jH2 = atom_mapping(map,tag[j] + 2);
// set iH1,iH2 to closest image to O
jH1 = closest_image(j, jH1, sametag, x_);
jH2 = closest_image(j, jH2, sametag, x_);
hneigh[j*4 ] = jH1;
hneigh[j*4+1] = jH2;
hneigh[j*4+2] = -1;
hneigh[jH1*4 ] = j;
hneigh[jH1*4+1] += -1;
hneigh[jH1*4+2] = -1;
hneigh[jH2*4 ] = j;
hneigh[jH2*4+1] += -1;
hneigh[jH2*4+2] = -1;
} else {
jH1 = hneigh[j*4 ];
jH2 = hneigh[j*4+1];
}
if (m[j].w == 0) {
compute_newsite(j, jH1, jH2, &m[j], alpha, x_);
m[j].w = qj;
}
x2 = m[j];
}
delx = x1.x-x2.x;
dely = x1.y-x2.y;
delz = x1.z-x2.z;
rsq = delx*delx+dely*dely+delz*delz;
}
if (rsq < cut_coulsq) {
numtyp r2inv = ucl_recip(rsq);
numtyp r = ucl_rsqrt(r2inv);
numtyp grij = g_ewald * r;
numtyp expm2 = ucl_exp(-grij*grij);
numtyp t = ucl_recip((numtyp)1.0 + EWALD_P*grij);
numtyp _erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
if (rsq < cut_coulsqplus) { //cut_coulsqplus
int jH1, jH2, jO;
numtyp qj; fetch(qj,j,q_tex);
numtyp4 x2 = jx;
if(itype == typeO || jtype == typeO) {
if (jtype == typeO) {
jO = j;
if (hneigh[j*4+2] != -1) {
jH1 = atom_mapping(map,tag[j] + 1);
jH2 = atom_mapping(map,tag[j] + 2);
// set iH1,iH2 to closest image to O
jH1 = closest_image(j, jH1, sametag, x_);
jH2 = closest_image(j, jH2, sametag, x_);
hneigh[j*4 ] = jH1;
hneigh[j*4+1] = jH2;
hneigh[j*4+2] = -1;
hneigh[jH1*4 ] = j;
hneigh[jH1*4+1] += -1;
hneigh[jH1*4+2] = -1;
hneigh[jH2*4 ] = j;
hneigh[jH2*4+1] += -1;
hneigh[jH2*4+2] = -1;
} else {
jH1 = hneigh[j*4 ];
jH2 = hneigh[j*4+1];
}
if (fabs(m[j].w) <= FLT_EPSILON) {
compute_newsite(j, jH1, jH2, &m[j], alpha, x_);
m[j].w = qj;
}
x2 = m[j];
}
delx = x1.x-x2.x;
dely = x1.y-x2.y;
delz = x1.z-x2.z;
rsq = delx*delx+dely*dely+delz*delz;
}
if (rsq < cut_coulsq) {
numtyp r2inv = ucl_recip(rsq);
numtyp r = ucl_rsqrt(r2inv);
numtyp grij = g_ewald * r;
numtyp expm2 = ucl_exp(-grij*grij);
numtyp t = ucl_recip((numtyp)1.0 + EWALD_P*grij);
numtyp _erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
numtyp prefactor = qj;
prefactor *= qqrd2e*qtmp/r;
numtyp force_coul = r2inv*prefactor * (_erfc + EWALD_F*grij*expm2 - factor_coul);
numtyp prefactor = qj;
prefactor *= qqrd2e*qtmp/r;
numtyp force_coul = r2inv*prefactor * (_erfc + EWALD_F*grij*expm2 - factor_coul);
if (itype == typeH) {
f.x += delx * force_coul;
f.y += dely * force_coul;
f.z += delz * force_coul;
} else {
fO.x += delx * force_coul;
fO.y += dely * force_coul;
fO.z += delz * force_coul;
fO.w += -1;
}
if (eflag>0) {
e_coul += prefactor*(_erfc-factor_coul);
}
if (vflag>0) {
acctyp4 fd;
fd.x = delx*force_coul;
fd.y = dely*force_coul;
fd.z = delz*force_coul;
if (itype == typeH) {
if (jtype == typeH){
virial[0] += delx*fd.x;
virial[1] += dely*fd.y;
virial[2] += delz*fd.z;
virial[3] += delx*fd.y;
virial[4] += delx*fd.z;
virial[5] += dely*fd.z;
} else {
numtyp cO = 1 - alpha, cH = 0.5*alpha;
numtyp4 vdj;
numtyp4 xjH1; fetch4(xjH1,jH1,pos_tex);
numtyp4 xjH2; fetch4(xjH2,jH2,pos_tex);
numtyp4 xjO; fetch4(xjO,jO,pos_tex);
vdj.x = xjO.x*cO + xjH1.x*cH + xjH2.x*cH;
vdj.y = xjO.y*cO + xjH1.y*cH + xjH2.y*cH;
vdj.z = xjO.z*cO + xjH1.z*cH + xjH2.z*cH;
virial[0] += (ix.x - vdj.x)*fd.x;
virial[1] += (ix.y - vdj.y)*fd.y;
virial[2] += (ix.z - vdj.z)*fd.z;
virial[3] += (ix.x - vdj.x)*fd.y;
virial[4] += (ix.x - vdj.x)*fd.z;
virial[5] += (ix.y - vdj.y)*fd.z;
}
} else {
numtyp cO = 1 - alpha, cH = 0.5*alpha;
numtyp4 vdi, vdj;
numtyp4 xH1; fetch4(xH1,iH1,pos_tex);
numtyp4 xH2; fetch4(xH2,iH2,pos_tex);
numtyp4 xO; fetch4(xO,iO,pos_tex);
vdi.x = xO.x*cO + xH1.x*cH + xH2.x*cH;
vdi.y = xO.y*cO + xH1.y*cH + xH2.y*cH;
vdi.z = xO.z*cO + xH1.z*cH + xH2.z*cH;
if (jtype != typeH){
numtyp4 xjH1; fetch4(xjH1,jH1,pos_tex);
numtyp4 xjH2; fetch4(xjH2,jH2,pos_tex);
numtyp4 xjO; fetch4(xjO,jO,pos_tex);
vdj.x = xjO.x*cO + xjH1.x*cH + xjH2.x*cH;
vdj.y = xjO.y*cO + xjH1.y*cH + xjH2.y*cH;
vdj.z = xjO.z*cO + xjH1.z*cH + xjH2.z*cH;
} else vdj = jx;
vO[0] += 0.5*(vdi.x - vdj.x)*fd.x;
vO[1] += 0.5*(vdi.y - vdj.y)*fd.y;
vO[2] += 0.5*(vdi.z - vdj.z)*fd.z;
vO[3] += 0.5*(vdi.x - vdj.x)*fd.y;
vO[4] += 0.5*(vdi.x - vdj.x)*fd.z;
vO[5] += 0.5*(vdi.y - vdj.y)*fd.z;
}
}
}
if (non_local_oxy == 1) {
if (iO == j) {
x2 = ix;
qj = qtmp;
}
numtyp4 x1m = m[iO];
delx = x1m.x-x2.x;
dely = x1m.y-x2.y;
delz = x1m.z-x2.z;
rsq = delx*delx+dely*dely+delz*delz;
if (rsq < cut_coulsq) {
numtyp r2inv = ucl_recip(rsq);
numtyp r = ucl_rsqrt(r2inv);
numtyp grij = g_ewald * r;
numtyp expm2 = ucl_exp(-grij*grij);
numtyp t = ucl_recip((numtyp)1.0 + EWALD_P*grij);
numtyp _erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
if (itype == typeH) {
f.x += delx * force_coul;
f.y += dely * force_coul;
f.z += delz * force_coul;
f.w += 0;
} else {
fO.x += delx * force_coul;
fO.y += dely * force_coul;
fO.z += delz * force_coul;
fO.w += 0;
}
if (eflag>0) {
e_coul += prefactor*(_erfc-factor_coul);
}
if (vflag>0) {
acctyp4 fd;
fd.x = delx*force_coul;
fd.y = dely*force_coul;
fd.z = delz*force_coul;
if (itype == typeH) {
if (jtype == typeH){
virial[0] += delx*fd.x;
virial[1] += dely*fd.y;
virial[2] += delz*fd.z;
virial[3] += delx*fd.y;
virial[4] += delx*fd.z;
virial[5] += dely*fd.z;
} else {
numtyp cO = 1 - alpha, cH = 0.5*alpha;
numtyp4 vdj;
numtyp4 xjH1; fetch4(xjH1,jH1,pos_tex);
numtyp4 xjH2; fetch4(xjH2,jH2,pos_tex);
numtyp4 xjO; fetch4(xjO,jO,pos_tex);
vdj.x = xjO.x*cO + xjH1.x*cH + xjH2.x*cH;
vdj.y = xjO.y*cO + xjH1.y*cH + xjH2.y*cH;
vdj.z = xjO.z*cO + xjH1.z*cH + xjH2.z*cH;
vdj.w = vdj.w;
virial[0] += (ix.x - vdj.x)*fd.x;
virial[1] += (ix.y - vdj.y)*fd.y;
virial[2] += (ix.z - vdj.z)*fd.z;
virial[3] += (ix.x - vdj.x)*fd.y;
virial[4] += (ix.x - vdj.x)*fd.z;
virial[5] += (ix.y - vdj.y)*fd.z;
}
} else {
numtyp cO = 1 - alpha, cH = 0.5*alpha;
numtyp4 vdi, vdj;
numtyp4 xH1; fetch4(xH1,iH1,pos_tex);
numtyp4 xH2; fetch4(xH2,iH2,pos_tex);
numtyp4 xO; fetch4(xO,iO,pos_tex);
vdi.x = xO.x*cO + xH1.x*cH + xH2.x*cH;
vdi.y = xO.y*cO + xH1.y*cH + xH2.y*cH;
vdi.z = xO.z*cO + xH1.z*cH + xH2.z*cH;
vdi.w = vdi.w;
if (jtype != typeH){
numtyp4 xjH1; fetch4(xjH1,jH1,pos_tex);
numtyp4 xjH2; fetch4(xjH2,jH2,pos_tex);
numtyp4 xjO; fetch4(xjO,jO,pos_tex);
vdj.x = xjO.x*cO + xjH1.x*cH + xjH2.x*cH;
vdj.y = xjO.y*cO + xjH1.y*cH + xjH2.y*cH;
vdj.z = xjO.z*cO + xjH1.z*cH + xjH2.z*cH;
vdj.w = vdj.w;
} else vdj = jx;
vO[0] += 0.5*(vdi.x - vdj.x)*fd.x;
vO[1] += 0.5*(vdi.y - vdj.y)*fd.y;
vO[2] += 0.5*(vdi.z - vdj.z)*fd.z;
vO[3] += 0.5*(vdi.x - vdj.x)*fd.y;
vO[4] += 0.5*(vdi.x - vdj.x)*fd.z;
vO[5] += 0.5*(vdi.y - vdj.y)*fd.z;
}
}
}
if (non_local_oxy == 1) {
if (iO == j) {
x2 = ix;
qj = qtmp;
}
numtyp4 x1m = m[iO];
delx = x1m.x-x2.x;
dely = x1m.y-x2.y;
delz = x1m.z-x2.z;
rsq = delx*delx+dely*dely+delz*delz;
if (rsq < cut_coulsq) {
numtyp r2inv = ucl_recip(rsq);
numtyp r = ucl_rsqrt(r2inv);
numtyp grij = g_ewald * r;
numtyp expm2 = ucl_exp(-grij*grij);
numtyp t = ucl_recip((numtyp)1.0 + EWALD_P*grij);
numtyp _erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
numtyp prefactor = qj;
prefactor *= qqrd2e*x1m.w/r;
numtyp force_coul = r2inv*prefactor * (_erfc + EWALD_F*grij*expm2 - factor_coul);
numtyp prefactor = qj;
prefactor *= qqrd2e*x1m.w/r;
numtyp force_coul = r2inv*prefactor * (_erfc + EWALD_F*grij*expm2 - factor_coul);
numtyp cO = 1 - alpha, cH = 0.5*alpha;
numtyp4 fd;
fd.x = delx * force_coul * cH;
fd.y = dely * force_coul * cH;
fd.z = delz * force_coul * cH;
numtyp cO = 1 - alpha, cH = 0.5*alpha;
numtyp4 fd;
fd.x = delx * force_coul * cH;
fd.y = dely * force_coul * cH;
fd.z = delz * force_coul * cH;
f.x += fd.x;
f.y += fd.y;
f.z += fd.z;
f.x += fd.x;
f.y += fd.y;
f.z += fd.z;
if (eflag>0) {
e_coul += prefactor*(_erfc-factor_coul) * (acctyp)0.5 * alpha;
}
if (vflag>0) {
numtyp4 xH1; fetch4(xH1,iH1,pos_tex);
numtyp4 xH2; fetch4(xH2,iH2,pos_tex);
numtyp4 xO; fetch4(xO,iO,pos_tex);
if (eflag>0) {
e_coul += prefactor*(_erfc-factor_coul) * (acctyp)0.5 * alpha;
}
if (vflag>0) {
numtyp4 xH1; fetch4(xH1,iH1,pos_tex);
numtyp4 xH2; fetch4(xH2,iH2,pos_tex);
numtyp4 xO; fetch4(xO,iO,pos_tex);
virial[0] += ((xO.x*cO + xH1.x*cH + xH2.x*cH) - x2.x) * fd.x;
virial[1] += ((xO.y*cO + xH1.y*cH + xH2.y*cH) - x2.y) * fd.y;
virial[2] += ((xO.z*cO + xH1.z*cH + xH2.z*cH) - x2.z) * fd.z;
virial[3] += ((xO.x*cO + xH1.x*cH + xH2.x*cH) - x2.x) * fd.y;
virial[4] += ((xO.x*cO + xH1.x*cH + xH2.x*cH) - x2.x) * fd.z;
virial[5] += ((xO.y*cO + xH1.y*cH + xH2.y*cH) - x2.y) * fd.z;
}
}
}
} // if cut_coulsqplus
} // for nbor
if (t_per_atom>1) {
virial[0] += ((xO.x*cO + xH1.x*cH + xH2.x*cH) - x2.x) * fd.x;
virial[1] += ((xO.y*cO + xH1.y*cH + xH2.y*cH) - x2.y) * fd.y;
virial[2] += ((xO.z*cO + xH1.z*cH + xH2.z*cH) - x2.z) * fd.z;
virial[3] += ((xO.x*cO + xH1.x*cH + xH2.x*cH) - x2.x) * fd.y;
virial[4] += ((xO.x*cO + xH1.x*cH + xH2.x*cH) - x2.x) * fd.z;
virial[5] += ((xO.y*cO + xH1.y*cH + xH2.y*cH) - x2.y) * fd.z;
}
}
}
} // if cut_coulsqplus
} // for nbor
if (t_per_atom>1) {
#if (ARCH < 300)
__local acctyp red_acc[6][BLOCK_PAIR];
red_acc[0][tid]=fO.x;
red_acc[1][tid]=fO.y;
red_acc[2][tid]=fO.z;
red_acc[3][tid]=fO.w;
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
if (offset < s) {
for (int r=0; r<4; r++)
red_acc[r][tid] += red_acc[r][tid+s];
}
}
fO.x=red_acc[0][tid];
fO.y=red_acc[1][tid];
fO.z=red_acc[2][tid];
fO.w=red_acc[3][tid];
if (vflag>0) {
for (int r=0; r<6; r++) red_acc[r][tid]=vO[r];
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
if (offset < s) {
for (int r=0; r<6; r++)
red_acc[r][tid] += red_acc[r][tid+s];
}
}
for (int r=0; r<6; r++) vO[r]=red_acc[r][tid];
}
__local acctyp red_acc[6][BLOCK_PAIR];
red_acc[0][tid]=fO.x;
red_acc[1][tid]=fO.y;
red_acc[2][tid]=fO.z;
red_acc[3][tid]=fO.w;
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
if (offset < s) {
for (int r=0; r<4; r++)
red_acc[r][tid] += red_acc[r][tid+s];
}
}
fO.x=red_acc[0][tid];
fO.y=red_acc[1][tid];
fO.z=red_acc[2][tid];
fO.w=red_acc[3][tid];
if (vflag>0) {
for (int r=0; r<6; r++) red_acc[r][tid]=vO[r];
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
if (offset < s) {
for (int r=0; r<6; r++)
red_acc[r][tid] += red_acc[r][tid+s];
}
}
for (int r=0; r<6; r++) vO[r]=red_acc[r][tid];
}
#else
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
fO.x += shfl_xor(fO.x, s, t_per_atom);
fO.y += shfl_xor(fO.y, s, t_per_atom);
fO.z += shfl_xor(fO.z, s, t_per_atom);
fO.w += shfl_xor(fO.w, s, t_per_atom);
}
if (vflag>0) {
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
for (int r=0; r<6; r++)
vO[r] += shfl_xor(vO[r], s, t_per_atom);
}
}
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
fO.x += shfl_xor(fO.x, s, t_per_atom);
fO.y += shfl_xor(fO.y, s, t_per_atom);
fO.z += shfl_xor(fO.z, s, t_per_atom);
fO.w += shfl_xor(fO.w, s, t_per_atom);
}
if (vflag>0) {
for (unsigned int s=t_per_atom/2; s>0; s>>=1) {
for (int r=0; r<6; r++)
vO[r] += shfl_xor(vO[r], s, t_per_atom);
}
}
#endif
}
if(offset == 0) {
ansO[i] = fO;
if (vflag>0) {
ansO[inum + i].x = vO[0];
ansO[inum + i].y = vO[1];
ansO[inum + i].z = vO[2];
ansO[inum*2 + i].x = vO[3];
ansO[inum*2 + i].y = vO[4];
ansO[inum*2 + i].z = vO[5];
}
}
store_answers_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag,
vflag,ans,engv);
} // if ii
}
if(offset == 0) {
ansO[i] = fO;
if (vflag>0) {
ansO[inum + i].x = vO[0];
ansO[inum + i].y = vO[1];
ansO[inum + i].z = vO[2];
ansO[inum*2 + i].x = vO[3];
ansO[inum*2 + i].y = vO[4];
ansO[inum*2 + i].z = vO[5];
}
}
store_answers_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag,
vflag,ans,engv);
} // if ii
}
__kernel void k_lj_tip4p_long_fast(){}

View File

@ -1,3 +1,18 @@
/**************************************************************************
lj_tip4p_long.h
-------------------
V. Nikolskiy (HSE)
Class for acceleration of the lj/tip4p/long pair style
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : thevsevak@gmail.com
***************************************************************************/
#ifndef LAL_LJ_TIP4P_LONG_H
#define LAL_LJ_TIP4P_LONG_H
@ -26,16 +41,16 @@ public:
double **host_lj1, double **host_lj2, double **host_lj3,
double **host_lj4, double **host_offset, double *host_special_lj,
const int nlocal, const int tH, const int tO,
const double alpha, const double qdist,
const int nall, const int max_nbors,
const double alpha, const double qdist,
const int nall, const int max_nbors,
const int maxspecial, const double cell_size,
const double gpu_split, FILE *screen,
double **host_cut_ljsq,
const double host_cut_coulsq, const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same);
double **host_cut_ljsq,
const double host_cut_coulsq, const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same);
/// Clear all host and device data
/** \note This is called at the beginning of the init() routine **/
@ -49,7 +64,7 @@ public:
/// Copy data which is easier to compute in LAMMPS_NS
void copy_relations_data(int **hn, double **m, int n,int* tag, int *map_array, int map_size,
int *sametag, int max_same, int ago);
int *sametag, int max_same, int ago);
// --------------------------- TYPE DATA --------------------------
@ -77,7 +92,7 @@ public:
UCL_D_Vec<int> hneight;
UCL_D_Vec<numtyp4> m; // position and charge of virtual particle
UCL_D_Vec<acctyp4> ansO; // force applied to virtual particle
UCL_D_Vec<acctyp4> force_comp;
// UCL_D_Vec<acctyp4> force_comp;
UCL_D_Vec<int> tag;
UCL_D_Vec<int> map_array;

View File

@ -1,3 +1,18 @@
/***************************************************************************
lj_tip4p_long_ext.cpp
-------------------
V. Nikolskiy (HSE)
Functions for LAMMPS access to lj/tip4p/long acceleration functions
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : thevsevak@gmail.com
***************************************************************************/
#include <iostream>
#include <cassert>
#include <cmath>
@ -13,18 +28,18 @@ static LJ_TIP4PLong<PRECISION,ACC_PRECISION> LJTIP4PLMF;
// Allocate memory on host and device and copy constants to device
// ---------------------------------------------------------------------------
int ljtip4p_long_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double *special_lj, const int inum,
const int tH, const int tO,
const double alpha, const double qdist,
const int nall, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen,
double **host_cut_ljsq,
const double host_cut_coulsq, const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same) {
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double *special_lj, const int inum,
const int tH, const int tO,
const double alpha, const double qdist,
const int nall, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen,
double **host_cut_ljsq,
const double host_cut_coulsq, const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same) {
LJTIP4PLMF.clear();
gpu_mode=LJTIP4PLMF.device->gpu_mode();
double gpu_split=LJTIP4PLMF.device->particle_split();
@ -48,13 +63,13 @@ int ljtip4p_long_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
int init_ok=0;
if (world_me==0)
init_ok=LJTIP4PLMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3,
host_lj4, offset, special_lj, inum,
tH, tO, alpha, qdist, nall, 300,
maxspecial, cell_size, gpu_split, screen,
host_cut_ljsq, host_cut_coulsq, host_cut_coulsqplus,
host_special_coul, qqrd2e, g_ewald, tag,
map_array, map_size,
sametag, max_same);
host_lj4, offset, special_lj, inum,
tH, tO, alpha, qdist, nall, 300,
maxspecial, cell_size, gpu_split, screen,
host_cut_ljsq, host_cut_coulsq, host_cut_coulsqplus,
host_special_coul, qqrd2e, g_ewald, tag,
map_array, map_size,
sametag, max_same);
LJTIP4PLMF.device->world_barrier();
if (message)
@ -71,13 +86,13 @@ int ljtip4p_long_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
}
if (gpu_rank==i && world_me!=0)
init_ok=LJTIP4PLMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
offset, special_lj, inum,
tH, tO, alpha, qdist, nall, 300, maxspecial,
cell_size, gpu_split, screen, host_cut_ljsq,
host_cut_coulsq, host_cut_coulsqplus,
host_special_coul, qqrd2e, g_ewald,tag,
map_array, map_size,
sametag, max_same);
offset, special_lj, inum,
tH, tO, alpha, qdist, nall, 300, maxspecial,
cell_size, gpu_split, screen, host_cut_ljsq,
host_cut_coulsq, host_cut_coulsqplus,
host_special_coul, qqrd2e, g_ewald,tag,
map_array, map_size,
sametag, max_same);
LJTIP4PLMF.device->gpu_barrier();
if (message)
@ -91,8 +106,6 @@ int ljtip4p_long_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
return init_ok;
}
void ljtip4p_long_gpu_clear() {
LJTIP4PLMF.clear();
}
@ -108,7 +121,7 @@ int ** ljtip4p_long_gpu_compute_n(const int ago, const int inum_full,
return LJTIP4PLMF.compute(ago, inum_full, nall, host_x, host_type, sublo,
subhi, tag, nspecial, special, eflag, vflag, eatom,
vatom, host_start, ilist, jnum, cpu_time, success,
host_q,boxlo, prd);
host_q,boxlo, prd);
}
void ljtip4p_long_gpu_compute(const int ago, const int inum_full, const int nall,
@ -116,10 +129,10 @@ void ljtip4p_long_gpu_compute(const int ago, const int inum_full, const int nall
int **firstneigh, const bool eflag, const bool vflag,
const bool eatom, const bool vatom, int &host_start,
const double cpu_time, bool &success,double *host_q,
const int nlocal, double *boxlo, double *prd) {
const int nlocal, double *boxlo, double *prd) {
LJTIP4PLMF.compute(ago,inum_full,nall,host_x,host_type,ilist,numj,
firstneigh,eflag,vflag,eatom,vatom,host_start,cpu_time,success,host_q,
nlocal,boxlo,prd);
firstneigh,eflag,vflag,eatom,vatom,host_start,cpu_time,success,host_q,
nlocal,boxlo,prd);
}
double ljtip4p_long_gpu_bytes() {
@ -127,9 +140,9 @@ double ljtip4p_long_gpu_bytes() {
}
void ljtip4p_long_copy_molecule_data(int **hn, double **m, int n, int* tag,
int *map_array, int map_size,
int *sametag, int max_same, int ago){
LJTIP4PLMF.copy_relations_data(hn, m, n, tag,map_array,map_size,sametag, max_same, ago);
int *map_array, int map_size,
int *sametag, int max_same, int ago){
LJTIP4PLMF.copy_relations_data(hn, m, n, tag,map_array,map_size,sametag, max_same, ago);
}

View File

@ -1,3 +1,20 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Vsevolod Nikolskiy (HSE)
------------------------------------------------------------------------- */
#include <cmath>
#include <cstdio>
#include <cstdlib>
@ -34,35 +51,35 @@ using namespace LAMMPS_NS;
// External functions from cuda library for atom decomposition
int ljtip4p_long_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double *special_lj, const int nlocal,
const int tH, const int tO, const double alpha, const double qdist,
const int nall, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen,
double **host_cut_ljsq, const double host_cut_coulsq,
const double host_cut_coulsqplus,
double *host_special_coul, const double qqrd2e,
const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same);
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double *special_lj, const int nlocal,
const int tH, const int tO, const double alpha, const double qdist,
const int nall, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen,
double **host_cut_ljsq, const double host_cut_coulsq,
const double host_cut_coulsqplus, double *host_special_coul,
const double qqrd2e, const double g_ewald, int* tag,
int *map_array, int map_size,
int *sametag, int max_same);
void ljtip4p_long_gpu_clear();
int ** ljtip4p_long_gpu_compute_n(const int ago, const int inum,
const int nall, double **host_x, int *host_type,
double *sublo, double *subhi, tagint *tag, int **nspecial,
tagint **special, const bool eflag, const bool vflag,
const bool eatom, const bool vatom, int &host_start,
int **ilist, int **jnum,
const double cpu_time, bool &success, double *host_q,
double *boxlo, double *prd);
const int nall, double **host_x, int *host_type,
double *sublo, double *subhi, tagint *tag, int **nspecial,
tagint **special, const bool eflag, const bool vflag,
const bool eatom, const bool vatom, int &host_start,
int **ilist, int **jnum,
const double cpu_time, bool &success, double *host_q,
double *boxlo, double *prd);
void ljtip4p_long_gpu_compute(const int ago, const int inum, const int nall,
double **host_x, int *host_type, int *ilist, int *numj,
int **firstneigh, const bool eflag, const bool vflag,
const bool eatom, const bool vatom, int &host_start,
const double cpu_time,
bool &success, double *host_q, const int nlocal,
double *boxlo, double *prd);
double **host_x, int *host_type, int *ilist, int *numj,
int **firstneigh, const bool eflag, const bool vflag,
const bool eatom, const bool vatom, int &host_start,
const double cpu_time,
bool &success, double *host_q, const int nlocal,
double *boxlo, double *prd);
double ljtip4p_long_gpu_bytes();
void ljtip4p_long_copy_molecule_data(int **, double **, int, int* , int *, int, int *, int , int);
void ljtip4p_long_copy_molecule_data(int **, double **, int, int* , int *,
int, int *, int , int);
/* ---------------------------------------------------------------------- */
@ -81,7 +98,7 @@ PairLJCutTIP4PLongGPU::PairLJCutTIP4PLongGPU(LAMMPS *lmp)
PairLJCutTIP4PLongGPU::~PairLJCutTIP4PLongGPU()
{
ljtip4p_long_gpu_clear();
ljtip4p_long_gpu_clear();
}
/* ---------------------------------------------------------------------- */
@ -96,29 +113,29 @@ void PairLJCutTIP4PLongGPU::compute(int eflag, int vflag)
int inum, host_start;
ljtip4p_long_copy_molecule_data(hneigh, newsite, nall, atom->tag,
atom->get_map_array(), atom->get_map_size(),
atom->sametag, atom->get_max_same(), neighbor->ago);
atom->get_map_array(), atom->get_map_size(),
atom->sametag, atom->get_max_same(), neighbor->ago);
bool success = true;
int *ilist, *numneigh, **firstneigh;
if (gpu_mode != GPU_FORCE) {
inum = atom->nlocal;
firstneigh = ljtip4p_long_gpu_compute_n(neighbor->ago, inum, nall,
atom->x, atom->type, domain->sublo,
domain->subhi, atom->tag, atom->nspecial,
atom->special, eflag, vflag, eflag_atom,
vflag_atom, host_start, &ilist, &numneigh,
cpu_time, success, atom->q, domain->boxlo,
domain->prd);
atom->x, atom->type, domain->sublo,
domain->subhi, atom->tag, atom->nspecial,
atom->special, eflag, vflag, eflag_atom,
vflag_atom, host_start, &ilist, &numneigh,
cpu_time, success, atom->q, domain->boxlo,
domain->prd);
} else {
inum = list->inum;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
ljtip4p_long_gpu_compute(neighbor->ago, inum, nall, atom->x, atom->type,
ilist, numneigh, firstneigh, eflag, vflag, eflag_atom,
vflag_atom, host_start, cpu_time, success, atom->q,
atom->nlocal, domain->boxlo, domain->prd);
ilist, numneigh, firstneigh, eflag, vflag, eflag_atom,
vflag_atom, host_start, cpu_time, success, atom->q,
atom->nlocal, domain->boxlo, domain->prd);
}
if (!success)
error->one(FLERR,"Insufficient memory on accelerator");
@ -149,7 +166,8 @@ void PairLJCutTIP4PLongGPU::init_style()
error->all(FLERR,"Must use an angle style with TIP4P potential");
if (atom->map_style == 2)
error->all(FLERR,"GPU-accelerated lj/cut/tip4p/long currently requires map style 'array' (atom_modify map array)");
error->all(FLERR,"GPU-accelerated lj/cut/tip4p/long currently"
" requires map style 'array' (atom_modify map array)");
//PairLJCutCoulLong::init_style();
// Repeat cutsq calculation because done after call to init_style
@ -189,25 +207,24 @@ void PairLJCutTIP4PLongGPU::init_style()
cut_coulsq = cut_coul * cut_coul;
double cut_coulsqplus = (cut_coul+qdist+blen) * (cut_coul+qdist+blen);
if (maxcut < cut_coulsqplus) {
cell_size = (cut_coul+qdist+blen) + neighbor->skin;
cell_size = (cut_coul+qdist+blen) + neighbor->skin;
}
if (comm->cutghostuser < cell_size) {
comm->cutghostuser = cell_size;
if (comm->me == 0)
error->warning(FLERR,"Increasing communication cutoff for TIP4P GPU style");
error->warning(FLERR,"Increasing communication cutoff for TIP4P GPU style");
}
int success = ljtip4p_long_gpu_init(atom->ntypes+1, cutsq, lj1, lj2, lj3, lj4,
offset, force->special_lj, atom->nlocal,
typeH, typeO, alpha, qdist,
typeH, typeO, alpha, qdist,
atom->nlocal+atom->nghost, 300, maxspecial,
cell_size, gpu_mode, screen, cut_ljsq,
cut_coulsq, cut_coulsqplus,
cut_coulsq, cut_coulsqplus,
force->special_coul, force->qqrd2e,
g_ewald,
atom->tag,
atom->get_map_array(), atom->get_map_size(),
atom->sametag, atom->get_max_same());
g_ewald,
atom->tag, atom->get_map_array(), atom->get_map_size(),
atom->sametag, atom->get_max_same());
GPU_EXTRA::check_flag(success,error,world);
if (gpu_mode == GPU_FORCE) {
int irequest = neighbor->request(this,instance_me);
@ -228,7 +245,3 @@ double PairLJCutTIP4PLongGPU::memory_usage()
/* ---------------------------------------------------------------------- */
//void PairLJCutTIP4PLongGPU::cpu_compute(int start, int inum, int eflag, int vflag,
// int *ilist, int *numneigh, int **firstneigh) {
// error->all(FLERR,"PairLJCutTIP4PLongGPU::cpu_compute not implemented");
//}

View File

@ -1,3 +1,20 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Vsevolod Nikolskiy (HSE)
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
PairStyle(lj/cut/tip4p/long/gpu,PairLJCutTIP4PLongGPU)
@ -15,7 +32,6 @@ class PairLJCutTIP4PLongGPU : public PairLJCutTIP4PLong {
public:
PairLJCutTIP4PLongGPU(LAMMPS *lmp);
~PairLJCutTIP4PLongGPU();
// void cpu_compute(int, int, int, int, int *, int *, int **);
void compute(int, int);
void init_style();
double memory_usage();