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

#include <ComputeEwald.h>

Inheritance diagram for ComputeEwald:
ComputeHomePatches Compute

Public Member Functions

 ComputeEwald (ComputeID, ComputeMgr *)
 
virtual ~ComputeEwald ()
 
void doWork ()
 
void recvData (ComputeEwaldMsg *)
 
void recvResults (ComputeEwaldMsg *)
 
int getMasterNode () const
 
- Public Member Functions inherited from ComputeHomePatches
 ComputeHomePatches (ComputeID c)
 
virtual ~ComputeHomePatches ()
 
virtual void initialize ()
 
virtual void atomUpdate ()
 
FlagsgetFlags (void)
 
- Public Member Functions inherited from Compute
 Compute (ComputeID)
 
int type ()
 
virtual ~Compute ()
 
void setNumPatches (int n)
 
int getNumPatches ()
 
virtual void patchReady (PatchID, int doneMigration, int seq)
 
virtual int noWork ()
 
virtual void finishPatch (int)
 
int sequence (void)
 
int priority (void)
 
int getGBISPhase (void)
 
virtual void gbisP2PatchReady (PatchID, int seq)
 
virtual void gbisP3PatchReady (PatchID, int seq)
 

Additional Inherited Members

- Public Attributes inherited from Compute
const ComputeID cid
 
LDObjHandle ldObjHandle
 
LocalWorkMsg *const localWorkMsg
 
- Protected Member Functions inherited from Compute
void enqueueWork ()
 
- Protected Attributes inherited from ComputeHomePatches
int useAvgPositions
 
int hasPatchZero
 
ComputeHomePatchList patchList
 
PatchMappatchMap
 
- Protected Attributes inherited from Compute
int computeType
 
int basePriority
 
int gbisPhase
 
int gbisPhasePriority [3]
 

Detailed Description

Definition at line 78 of file ComputeEwald.h.

Constructor & Destructor Documentation

ComputeEwald::ComputeEwald ( ComputeID  c,
ComputeMgr m 
)

Definition at line 51 of file ComputeEwald.C.

References DebugM, ComputeNonbondedUtil::ewaldcof, generateAtomTypeTable(), PatchMap::Object(), Node::Object(), ReductionMgr::Object(), SimParameters::pressureProfileAtomTypes, SimParameters::pressureProfileEwaldX, SimParameters::pressureProfileEwaldY, SimParameters::pressureProfileEwaldZ, SimParameters::pressureProfileSlabs, REDUCTIONS_PPROF_NONBONDED, Node::simParameters, and ReductionMgr::willSubmit().

53 {
54  DebugM(3,"Constructing client\n");
55  comm = m;
57  kxmax = sp->pressureProfileEwaldX;
58  kymax = sp->pressureProfileEwaldY;
59  kzmax = sp->pressureProfileEwaldZ;
60 
61  ktot = (1+kxmax) * (2*kymax+1) * (2*kzmax+1);
63  pressureProfileSlabs = sp->pressureProfileSlabs;
64  numAtomTypes = sp->pressureProfileAtomTypes;
65  int nelements = 3*pressureProfileSlabs * (numAtomTypes*(numAtomTypes+1))/2;
66  pressureProfileData = new float[nelements];
67  reduction = ReductionMgr::Object()->willSubmit(
68  REDUCTIONS_PPROF_NONBONDED, nelements);
69 
70  // figure out who da masta be
71  numWorkingPes = (PatchMap::Object())->numNodesWithPatches();
72  masterNode = numWorkingPes - 1;
73 
74  recvCount = 0;
75  localAtoms = NULL;
76  localPartitions = NULL;
77 
78  expx = new float[kxmax+1];
79  expy = new float[kymax+1];
80  expz = new float[kzmax+1];
81 
82  if (CkMyPe() == masterNode) {
83  eiktotal = new float[2 * ktot * numAtomTypes];
84  memset(eiktotal, 0, 2 * ktot * numAtomTypes*sizeof(float));
85  } else {
86  eiktotal = NULL;
87  }
88  // space for exp(iky), k=-kymax, ..., kymax
89  eiky = new floatcomplex[2*kymax+1];
90  // space for exp(ikz), k=-kzmax, ..., kzmax
91  eikz = new floatcomplex[2*kzmax+1];
92  Qk = new float[3*ktot];
93 
94  gridsForAtomType = generateAtomTypeTable(numAtomTypes);
95 }
static Node * Object()
Definition: Node.h:86
int pressureProfileEwaldX
static int * generateAtomTypeTable(int ntypes)
Definition: ComputeEwald.C:40
static PatchMap * Object()
Definition: PatchMap.h:27
SimParameters * simParameters
Definition: Node.h:178
#define DebugM(x, y)
Definition: Debug.h:59
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
int pressureProfileSlabs
ComputeHomePatches(ComputeID c)
int pressureProfileEwaldY
int pressureProfileAtomTypes
int pressureProfileEwaldZ
ComputeEwald::~ComputeEwald ( )
virtual

Definition at line 97 of file ComputeEwald.C.

98 {
99  delete reduction;
100  delete [] expx;
101  delete [] expy;
102  delete [] expz;
103  delete [] eiktotal;
104  delete [] eiky;
105  delete [] eikz;
106  delete [] pressureProfileData;
107  delete [] Qk;
108  delete [] gridsForAtomType;
109 
110  if (localAtoms) free(localAtoms);
111  if (localPartitions) free(localPartitions);
112 }

Member Function Documentation

void ComputeEwald::doWork ( void  )
virtual

Reimplemented from Compute.

Definition at line 114 of file ComputeEwald.C.

References ResizeArrayIter< Type >::begin(), Lattice::c(), EwaldParticle::cg, CompAtom::charge, COULOMB, ComputeNonbondedUtil::dielectric_1, ComputeEwaldMsg::eik, ResizeArrayIter< Type >::end(), Lattice::origin(), CompAtom::partition, ComputeHomePatches::patchList, CompAtom::position, ComputeNonbondedUtil::scaling, ComputeMgr::sendComputeEwaldData(), SubmitReduction::submit(), Lattice::wrap_delta(), EwaldParticle::x, Vector::x, x, EwaldParticle::y, Vector::y, EwaldParticle::z, and Vector::z.

114  {
116  // Skip computations if nothing to do.
117  if ( ! patchList[0].p->flags.doFullElectrostatics )
118  {
119  for (ap = ap.begin(); ap != ap.end(); ap++) {
120  CompAtom *x = (*ap).positionBox->open();
121  Results *r = (*ap).forceBox->open();
122  (*ap).positionBox->close(&x);
123  (*ap).forceBox->close(&r);
124  }
125  reduction->submit();
126  return;
127  }
128 
129 
130  lattice = patchList[0].p->lattice;
131  Vector o = lattice.origin();
132 
133  // recompute pressure profile cell parameters based on current lattice
134  pressureProfileThickness = lattice.c().z / pressureProfileSlabs;
135  pressureProfileMin = lattice.origin().z - 0.5*lattice.c().z;
136 
137  const BigReal coulomb_sqrt = sqrt( COULOMB * ComputeNonbondedUtil::scaling
139 
140  // get coordinates and store them
141  numLocalAtoms = 0;
142  for (ap = ap.begin(); ap != ap.end(); ap++) {
143  numLocalAtoms += (*ap).p->getNumAtoms();
144  }
145  localAtoms = (EwaldParticle *)realloc(localAtoms, numLocalAtoms*sizeof(EwaldParticle));
146  localPartitions = (int *)realloc(localPartitions, numLocalAtoms*sizeof(int));
147 
148  EwaldParticle *data_ptr = localAtoms;
149  int *part_ptr = localPartitions;
150 
151  for (ap = ap.begin(); ap != ap.end(); ap++) {
152  CompAtom *x = (*ap).positionBox->open();
153  // CompAtomExt *xExt = (*ap).p->getCompAtomExtInfo();
154  Results *r = (*ap).forceBox->open();
155  if ( patchList[0].p->flags.doMolly ) {
156  (*ap).positionBox->close(&x);
157  x = (*ap).avgPositionBox->open();
158  }
159  int numAtoms = (*ap).p->getNumAtoms();
160 
161  for(int i=0; i<numAtoms; ++i) {
162  // wrap back to unit cell, centered on origin
163  Vector pos = x[i].position;
164  pos += lattice.wrap_delta(pos) - o;
165  *part_ptr++ = x[i].partition;
166  data_ptr->x = pos.x;
167  data_ptr->y = pos.y;
168  data_ptr->z = pos.z;
169  data_ptr->cg = coulomb_sqrt * x[i].charge;
170  ++data_ptr;
171  }
172  (*ap).positionBox->close(&x);
173  (*ap).forceBox->close(&r);
174  }
175 
176  // compute structure factor contribution from local atoms
177  // 2*ktot since charm++ uses float instead of floatcomplex
178  int msgsize = 2 * numAtomTypes * ktot;
179  ComputeEwaldMsg *msg = new (msgsize,0) ComputeEwaldMsg;
180  memset(msg->eik, 0, msgsize*sizeof(float));
181  compute_structurefactor(msg->eik);
182 
183  // send our partial sum
184  comm->sendComputeEwaldData(msg);
185 }
unsigned char partition
Definition: NamdTypes.h:56
Definition: Vector.h:64
ComputeHomePatchList patchList
Vector wrap_delta(const Position &pos1) const
Definition: Lattice.h:206
#define COULOMB
Definition: common.h:46
BigReal z
Definition: Vector.h:66
Position position
Definition: NamdTypes.h:53
Vector origin() const
Definition: Lattice.h:262
Charge charge
Definition: NamdTypes.h:54
void sendComputeEwaldData(ComputeEwaldMsg *)
Definition: ComputeMgr.C:1325
BigReal x
Definition: Vector.h:66
BigReal y
Definition: Vector.h:66
void submit(void)
Definition: ReductionMgr.h:323
gridSize x
Vector c() const
Definition: Lattice.h:254
double BigReal
Definition: common.h:114
int ComputeEwald::getMasterNode ( ) const
inline

Definition at line 86 of file ComputeEwald.h.

Referenced by ComputeMgr::sendComputeEwaldData().

86 { return masterNode; }
void ComputeEwald::recvData ( ComputeEwaldMsg msg)

Definition at line 187 of file ComputeEwald.C.

References ComputeEwaldMsg::eik, and ComputeMgr::sendComputeEwaldResults().

Referenced by ComputeMgr::recvComputeEwaldData().

187  {
188  // sum the data...
189  int nvecs = 2 * ktot * numAtomTypes;
190  for (int i=0; i<nvecs; i++) {
191  eiktotal[i] += msg->eik[i];
192  }
193  delete msg;
194  if (++recvCount == numWorkingPes) {
195  recvCount = 0;
196  int msgsize = 2 * ktot * numAtomTypes;
197  msg = new (msgsize,0) ComputeEwaldMsg;
198  memcpy(msg->eik, eiktotal, msgsize*sizeof(float));
199  memset(eiktotal, 0, msgsize*sizeof(float));
200  comm->sendComputeEwaldResults(msg);
201  }
202 }
void sendComputeEwaldResults(ComputeEwaldMsg *)
Definition: ComputeMgr.C:1348
void ComputeEwald::recvResults ( ComputeEwaldMsg msg)

Definition at line 204 of file ComputeEwald.C.

References ComputeEwaldMsg::eik, SubmitReduction::item(), M_PI, SubmitReduction::submit(), and Lattice::volume().

Referenced by ComputeMgr::recvComputeEwaldResults().

204  {
205  // receive total sum
206  computePprofile(msg->eik);
207  delete msg;
208  float scalefac = 1.0 / (2 * M_PI * lattice.volume());
209 
210  int nelements = 3*pressureProfileSlabs * (numAtomTypes*(numAtomTypes+1))/2;
211  for (int i=0; i<nelements; i++) {
212  reduction->item(i) += pressureProfileData[i] * scalefac;
213  }
214  reduction->submit();
215 }
#define M_PI
Definition: GoMolecule.C:39
BigReal & item(int i)
Definition: ReductionMgr.h:312
BigReal volume(void) const
Definition: Lattice.h:277
void submit(void)
Definition: ReductionMgr.h:323

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