NAMD
GlobalMaster.h
Go to the documentation of this file.
1 
7 /* A ComputeGlobalMaster represents a bit of computation that needs to
8  be done on atoms or groups of atoms on several nodes. It is given
9  the positions of atoms and groups, and provides a list of requested
10  atoms, forces, and groups in return.
11 
12  I'm not going to do groups for now, because they were done badly
13  originally. A better solution is necessary. Hint: multiple
14  groups are required.
15 
16  The expected usage (by ComputeGlobalMasterServer) is:
17  1) receive and store the data message from all nodes
18  2) call processData with that data
19  3) collect new forces and atoms
20  4) send them as a message to all the nodes
21  Repeat until done.
22 */
23 
24 #ifndef GLOBALMASTER_H
25 #define GLOBALMASTER_H
26 
27 #include "NamdTypes.h"
28 class Lattice;
29 class SubmitReduction;
30 
31 class GlobalMaster {
32  public:
33 
34  /* This passes the atom and group data to the master, which then
35  performs any necessary calculations and updates its results. */
43  ForceList::iterator gtf_i,
44  ForceList::iterator gtf_e,
45  IntList::iterator goi_i,
46  IntList::iterator goi_e,
49  AtomIDList::iterator last_atoms_forced_i,
50  AtomIDList::iterator last_atoms_forced_e,
51  ForceList::iterator last_forces_i,
55 
56  int step; // set by server to current timestep before processData
57  int globalMasterStep; // set by server to current timestep / globalMasterFreq before processData
58  int old_num_groups_requested; // used for group forces
59 
60  bool changedAtoms(); // false if the atom IDs haven't changed
61  const AtomIDList &requestedAtoms(); // the atom ids requested
62  bool changedForces(); // false if the forces haven't changed
63  const AtomIDList &forcedAtoms(); // the atoms the forces are applied to
64  const ForceList &appliedForces(); // the corresponding applied forces
65  bool changedGroups(); // false if the groups haven't changed
66  const ResizeArray<AtomIDList> &requestedGroups(); // the requested groups
67  const ForceList &groupForces(); // the corresponding forces on groups
68  bool changedGridObjs(); // false if the groups haven't changed
69  const IntList &requestedGridObjs(); // the requested groups
70  const BigRealList &gridObjForces(); // the corresponding forces on groups
72 
73  /* sets changedAtoms and changedForces to false again */
74  void clearChanged();
75  virtual ~GlobalMaster(); // necessary for abstract classes '-P
76 
77  void check() const; // dies if there are problems with the rep invariants
78 
79  void setLattice(const Lattice *lat) { lattice = lat; }
80 
81  protected:
82  GlobalMaster();
83 
84  /* This will be called after the pointers to lists below have been
85  initialized correctly by processData. It should perform any
86  required caluation and update the atom/force lists. */
87  virtual void calculate();
88 
89  /* This function returns the list of requested atoms, but assumes
90  that you will change it. */
92 
93  /* These functions returns the list of requested forces, but assumes
94  that you will change it. The two lists must be kept at the same
95  length, since the forcedAtoms correspond directly to the
96  appliedForces. */
99 
100  /* This function lets you change the requested groups */
103 
104  /* Same here for grids */
107 
108  /* These return pointers to the lists of atom ids and positions, as
109  they were last passed to processData (see below) */
121 
122  /* these give you all the global forces being applied by masters */
123  /* again, here we only need one end iterator */
127 
128  /* These return the pointers to the lists of requested atom IDs
129  and total forces on these atoms */
133 
135  void requestTotalForce(bool yesno = true) { totalForceRequested = yesno; }
136 
137  /* This helpful function returns an array with the masses of each of
138  the groups whose positions we have. */
141 
142  void addReductionEnergy(int reductionTag, BigReal energy);
144  void submitReduction();
145 
146  protected:
147  const Lattice *lattice; // points to lattice in server
148 
149  /* These store the pointers to lists of atom ids and atom positions.
150  The list of atom positions has the same length as the list of
151  ids, so only three iterators are necessary. There are also
152  pointers to the beginning and end of the group position list
153  here. */
167 
168  /* these store all the global forces being applied by masters */
172 
173  /* These store all the total forces returned from the simulation */
177 
178  /* These store the requested atoms and forces, and the booleans
179  indicate whether they (may) have changed. */
181  AtomIDList reqAtoms; // atoms whose positions are requested
182 
184  AtomIDList fAtoms; // atoms that are being forced
185  ForceList appForces; // the corresponding forces
186 
188  ResizeArray<AtomIDList> reqGroups; // list of requested groups of atoms
189  ForceList grpForces; // the corresponding forces
190 
192  IntList reqGridObjs; // list of requested grids
193  BigRealList gridobjForces; // the corresponding forces
194 
195 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
197 #endif
199 
200 };
201 
202 #endif
ForceList grpForces
Definition: GlobalMaster.h:189
ForceList & modifyAppliedForces()
Definition: GlobalMaster.C:203
int old_num_groups_requested
Definition: GlobalMaster.h:58
AtomIDList & modifyRequestedAtoms()
Definition: GlobalMaster.C:168
const ForceList & groupForces()
Definition: GlobalMaster.C:182
BigRealList & modifyGridObjForces()
Definition: GlobalMaster.C:220
Elem * iterator
Definition: ResizeArray.h:35
bool totalForceRequested
Definition: GlobalMaster.h:134
BigRealList::iterator gridObjValueEnd
Definition: GlobalMaster.h:166
IntList::iterator gridObjIndexBegin
Definition: GlobalMaster.h:163
AtomIDList::const_iterator getForceIdEnd()
Definition: GlobalMaster.C:301
AtomIDList::const_iterator getAtomIdBegin()
Definition: GlobalMaster.C:231
PositionList::const_iterator getGroupPositionEnd()
Definition: GlobalMaster.C:247
AtomIDList reqAtoms
Definition: GlobalMaster.h:181
ResizeArray< AtomIDList > reqGroups
Definition: GlobalMaster.h:188
bool changedAtoms()
Definition: GlobalMaster.C:148
void submitReduction()
Definition: GlobalMaster.C:138
ForceList::const_iterator getGroupTotalForceBegin()
Definition: GlobalMaster.C:251
bool requestedTotalForces()
Definition: GlobalMaster.h:71
ForceList::iterator totalForceBegin
Definition: GlobalMaster.h:176
AtomIDList::iterator lastAtomsForcedEnd
Definition: GlobalMaster.h:171
ForceList::iterator lastForcesBegin
Definition: GlobalMaster.h:170
SubmitReduction * getCurrentReduction()
Definition: GlobalMaster.C:128
PositionList::const_iterator getAtomPositionBegin()
Definition: GlobalMaster.C:239
ForceList appForces
Definition: GlobalMaster.h:185
bool reqGroupsChanged
Definition: GlobalMaster.h:187
AtomIDList::iterator lastAtomsForcedBegin
Definition: GlobalMaster.h:169
BigRealList::const_iterator getGroupMassEnd()
Definition: GlobalMaster.C:280
bool reqGridObjsChanged
Definition: GlobalMaster.h:191
const ResizeArray< AtomIDList > & requestedGroups()
Definition: GlobalMaster.C:190
BigRealList gridobjForces
Definition: GlobalMaster.h:193
void processData(AtomIDList::iterator a_i, AtomIDList::iterator a_e, PositionList::iterator p_i, PositionList::iterator g_i, PositionList::iterator g_e, BigRealList::iterator gm_i, BigRealList::iterator gm_e, ForceList::iterator gtf_i, ForceList::iterator gtf_e, IntList::iterator goi_i, IntList::iterator goi_e, BigRealList::iterator gov_i, BigRealList::iterator gov_e, AtomIDList::iterator last_atoms_forced_i, AtomIDList::iterator last_atoms_forced_e, ForceList::iterator last_forces_i, AtomIDList::iterator, AtomIDList::iterator, ForceList::iterator)
Definition: GlobalMaster.C:19
AtomIDList::const_iterator getForceIdBegin()
Definition: GlobalMaster.C:296
virtual void calculate()
Definition: GlobalMaster.C:84
const ForceList & appliedForces()
Definition: GlobalMaster.C:178
void setLattice(const Lattice *lat)
Definition: GlobalMaster.h:79
PositionList::iterator atomPositionBegin
Definition: GlobalMaster.h:156
ForceList::iterator groupTotalForceEnd
Definition: GlobalMaster.h:162
SubmitReduction * reductionGpuResident
Definition: GlobalMaster.h:196
IntList::const_iterator getGridObjIndexBegin()
Definition: GlobalMaster.C:259
bool changedForces()
Definition: GlobalMaster.C:152
bool changedGridObjs()
Definition: GlobalMaster.C:160
SubmitReduction * reduction
Definition: GlobalMaster.h:198
const Elem * const_iterator
Definition: ResizeArray.h:38
BigRealList::iterator gridObjValueBegin
Definition: GlobalMaster.h:165
ForceList::const_iterator getLastForcesBegin()
Definition: GlobalMaster.C:292
bool reqAtomsChanged
Definition: GlobalMaster.h:180
AtomIDList::iterator atomIdEnd
Definition: GlobalMaster.h:155
IntList & modifyRequestedGridObjects()
Definition: GlobalMaster.C:214
BigRealList::iterator groupMassBegin
Definition: GlobalMaster.h:159
bool changedGroups()
Definition: GlobalMaster.C:156
AtomIDList & modifyForcedAtoms()
Definition: GlobalMaster.C:198
IntList reqGridObjs
Definition: GlobalMaster.h:192
ResizeArray< AtomIDList > & modifyRequestedGroups()
Definition: GlobalMaster.C:225
IntList::iterator gridObjIndexEnd
Definition: GlobalMaster.h:164
BigRealList::const_iterator getGroupMassBegin()
Definition: GlobalMaster.C:275
ForceList & modifyGroupForces()
Definition: GlobalMaster.C:208
AtomIDList::iterator atomIdBegin
Definition: GlobalMaster.h:154
BigRealList::const_iterator getGridObjValueBegin()
Definition: GlobalMaster.C:267
BigRealList::iterator groupMassEnd
Definition: GlobalMaster.h:160
IntList::const_iterator getGridObjIndexEnd()
Definition: GlobalMaster.C:263
const Lattice * lattice
Definition: GlobalMaster.h:147
PositionList::iterator groupPositionBegin
Definition: GlobalMaster.h:157
bool appForcesChanged
Definition: GlobalMaster.h:183
void requestTotalForce(bool yesno=true)
Definition: GlobalMaster.h:135
int globalMasterStep
Definition: GlobalMaster.h:57
AtomIDList::const_iterator getAtomIdEnd()
Definition: GlobalMaster.C:235
AtomIDList::iterator forceIdBegin
Definition: GlobalMaster.h:174
const BigRealList & gridObjForces()
Definition: GlobalMaster.C:186
AtomIDList::const_iterator getLastAtomsForcedBegin()
Definition: GlobalMaster.C:284
void clearChanged()
Definition: GlobalMaster.C:77
AtomIDList fAtoms
Definition: GlobalMaster.h:184
void addReductionEnergy(int reductionTag, BigReal energy)
Definition: GlobalMaster.C:143
const IntList & requestedGridObjs()
Definition: GlobalMaster.C:194
AtomIDList::iterator forceIdEnd
Definition: GlobalMaster.h:175
AtomIDList::const_iterator getLastAtomsForcedEnd()
Definition: GlobalMaster.C:288
const AtomIDList & forcedAtoms()
Definition: GlobalMaster.C:174
void check() const
Definition: GlobalMaster.C:67
PositionList::const_iterator getGroupPositionBegin()
Definition: GlobalMaster.C:243
ForceList::const_iterator getTotalForce()
Definition: GlobalMaster.C:306
ForceList::iterator groupTotalForceBegin
Definition: GlobalMaster.h:161
PositionList::iterator groupPositionEnd
Definition: GlobalMaster.h:158
virtual ~GlobalMaster()
Definition: GlobalMaster.C:120
double BigReal
Definition: common.h:123
BigRealList::const_iterator getGridObjValueEnd()
Definition: GlobalMaster.C:271
ForceList::const_iterator getGroupTotalForceEnd()
Definition: GlobalMaster.C:255
const AtomIDList & requestedAtoms()
Definition: GlobalMaster.C:164