NAMD
Public Member Functions | List of all members
PmeAtomFiler Class Reference

#include <ComputePmeCUDAMgr.h>

Inheritance diagram for PmeAtomFiler:

Public Member Functions

 PmeAtomFiler ()
 
 PmeAtomFiler (CkMigrateMessage *)
 
 ~PmeAtomFiler ()
 
void fileAtoms (const int numAtoms, const CudaAtom *atoms, Lattice &lattice, const PmeGrid &pmeGrid, const int pencilIndexY, const int pencilIndexZ, const int ylo, const int yhi, const int zlo, const int zhi)
 
int getNumAtoms (int p)
 
int * getAtomIndex (int p)
 

Detailed Description

Definition at line 277 of file ComputePmeCUDAMgr.h.

Constructor & Destructor Documentation

PmeAtomFiler::PmeAtomFiler ( )

Definition at line 91 of file ComputePmeCUDAMgr.C.

91  {
92  for (int p=0;p < 10;p++) {
93  pencil[p] = NULL;
94  pencilCapacity[p] = 0;
95  }
96 }
PmeAtomFiler::PmeAtomFiler ( CkMigrateMessage *  m)

Definition at line 97 of file ComputePmeCUDAMgr.C.

97  {
98  for (int p=0;p < 10;p++) {
99  pencil[p] = NULL;
100  pencilCapacity[p] = 0;
101  }
102 }
PmeAtomFiler::~PmeAtomFiler ( )

Definition at line 103 of file ComputePmeCUDAMgr.C.

103  {
104  for (int p=0;p < 10;p++) {
105  if (pencil[p] != NULL) delete [] pencil[p];
106  }
107 }

Member Function Documentation

void PmeAtomFiler::fileAtoms ( const int  numAtoms,
const CudaAtom atoms,
Lattice lattice,
const PmeGrid pmeGrid,
const int  pencilIndexY,
const int  pencilIndexZ,
const int  ylo,
const int  yhi,
const int  zlo,
const int  zhi 
)

Definition at line 115 of file ComputePmeCUDAMgr.C.

References Lattice::a_r(), Lattice::b_r(), Lattice::c_r(), PmeRealSpaceCompute::calcGridCoord(), getPencilIndexY(), getPencilIndexZ(), PmeGrid::K1, PmeGrid::K2, PmeGrid::K3, PmeGrid::order, plist, Vector::x, x, Vector::y, y, PmeGrid::yBlocks, Vector::z, z, and PmeGrid::zBlocks.

Referenced by ComputePmeCUDADevice::recvAtoms().

116  {
117 
118  // Make sure there's enough room in the pencil arrays
119  for (int p=0;p < 10;p++) {
120  if (pencil[p] != NULL && pencilCapacity[p] < numAtoms) {
121  delete [] pencil[p];
122  pencil[p] = NULL;
123  pencilCapacity[p] = 0;
124  }
125  if (pencil[p] == NULL) {
126  int newSize = (int)(numAtoms*1.5);
127  pencil[p] = new int[newSize];
128  pencilCapacity[p] = newSize;
129  }
130  pencilSize[p] = 0;
131  }
132 
133  const float recip11 = lattice.a_r().x;
134  const float recip22 = lattice.b_r().y;
135  const float recip33 = lattice.c_r().z;
136  const int order1 = pmeGrid.order - 1;
137  const int K1 = pmeGrid.K1;
138  const int K2 = pmeGrid.K2;
139  const int K3 = pmeGrid.K3;
140  const int yBlocks = pmeGrid.yBlocks;
141  const int zBlocks = pmeGrid.zBlocks;
142 
143  for (int i=0;i < numAtoms;i++) {
144  float frx, fry, frz;
145  // PmeRealSpaceCompute::calcGridCoord(atoms[i].uix, atoms[i].uiy, atoms[i].uiz,
146  // K1, K2, K3, frx, fry, frz);
147  PmeRealSpaceCompute::calcGridCoord(atoms[i].x, atoms[i].y, atoms[i].z, K1, K2, K3, frx, fry, frz);
148  // Charge is spread in the region [y0 ... y0+order-1] x [z0 ... z0+order-1]
149  int y0 = (int)fry;
150  int z0 = (int)frz;
151  if (y0 < 0 || y0 >= K2 || z0 < 0 || z0 >= K3) {
152  // Add to "Stray pencil" and skip to next atom
153  pencil[9][pencilSize[9]++] = i;
154  continue;
155  // fprintf(stderr, "%lf %lf %lf\n", atoms[i].x, atoms[i].y, atoms[i].z);
156  // NAMD_bug("PmeAtomFiler::fileAtoms, charge out of bounds");
157  }
158  // Calculate pencil index for the four corners of the order X order area
159  // The corners determine the pencil indices for this atom.
160  int occupied = 0;
161  int plist[4];
162 #pragma unroll
163  for (int j=0;j < 4;j++) {
164 
165  int py = getPencilIndexY(pmeGrid, (y0 + (j%2)*order1) % K2) - pencilIndexY;
166  if (py < ylo) py += yBlocks;
167  if (py > yhi) py -= yBlocks;
168 
169  int pz = getPencilIndexZ(pmeGrid, (z0 + (j/2)*order1) % K3) - pencilIndexZ;
170  if (pz < zlo) pz += zBlocks;
171  if (pz > zhi) pz -= zBlocks;
172 
173  if (py < ylo || py > yhi || pz < zlo || pz > zhi) {
174  // Add to "Stray pencil" and skip to next atom
175  pencil[9][pencilSize[9]++] = i;
176  goto breakjloop;
177  // fprintf(stderr, "py %d [%d ... %d] pz %d [%d ... %d]\n", pz, zlo, zhi);
178  // NAMD_bug("PmeAtomFiler::fileAtoms, py,pz outside bounds");
179  }
180  // p = 0,1,2,3,4,5,6,7,8 (maximum range)
181  plist[j] = (py-ylo) + (pz-zlo)*3;
182  }
183 
184 #pragma unroll
185  for (int j=0;j < 4;j++) {
186  int p = plist[j];
187  // pbit = 0, 2, 4, 8, 16, 32, 64, 128, 256
188  int pbit = (1 << p);
189  if (!(occupied & pbit)) {
190  pencil[p][pencilSize[p]++] = i;
191  occupied |= pbit;
192  }
193  }
194 
195 breakjloop:
196  continue;
197  }
198 
199 }
int zBlocks
Definition: PmeBase.h:22
Vector a_r() const
Definition: Lattice.h:268
int K2
Definition: PmeBase.h:18
int K1
Definition: PmeBase.h:18
Vector c_r() const
Definition: Lattice.h:270
static __thread unsigned int * plist
BigReal z
Definition: Vector.h:66
static int getPencilIndexY(const PmeGrid &pmeGrid, const int y)
Definition: PmeSolverUtil.h:20
Vector b_r() const
Definition: Lattice.h:269
static double calcGridCoord(const double x, const double recip11, const int nfftx)
int yBlocks
Definition: PmeBase.h:22
int order
Definition: PmeBase.h:20
gridSize z
BigReal x
Definition: Vector.h:66
int K3
Definition: PmeBase.h:18
BigReal y
Definition: Vector.h:66
gridSize y
gridSize x
static int getPencilIndexZ(const PmeGrid &pmeGrid, const int z)
Definition: PmeSolverUtil.h:25
int* PmeAtomFiler::getAtomIndex ( int  p)
inline

Definition at line 287 of file ComputePmeCUDAMgr.h.

Referenced by ComputePmeCUDADevice::recvAtoms().

287 {return pencil[p];}
int PmeAtomFiler::getNumAtoms ( int  p)
inline

Definition at line 286 of file ComputePmeCUDAMgr.h.

Referenced by ComputePmeCUDADevice::recvAtoms().

286 {return pencilSize[p];}

The documentation for this class was generated from the following files: