NAMD
GlobalMaster.C
Go to the documentation of this file.
1 
7 #include "Node.h"
8 #include "Molecule.h"
9 #include "NamdTypes.h"
10 #include "GlobalMaster.h"
11 #include "NamdEventsProfiling.h"
12 #include "SimParameters.h"
13 
14 //#define DEBUGM
15 #define MIN_DEBUG_LEVEL 1
16 #include "Debug.h"
17 #include "ReductionMgr.h"
18 
26  ForceList::iterator gtf_i,
27  ForceList::iterator gtf_e,
28  IntList::iterator goi_i,
29  IntList::iterator goi_e,
32  AtomIDList::iterator last_atoms_forced_i,
33  AtomIDList::iterator last_atoms_forced_e,
34  ForceList::iterator last_forces_i,
35  AtomIDList::iterator forceid_i,
36  AtomIDList::iterator forceid_e,
37  ForceList::iterator totalforce_i) {
38  atomIdBegin = a_i;
39  atomIdEnd = a_e;
40  atomPositionBegin = p_i;
41  groupPositionBegin = g_i;
42  groupPositionEnd = g_e;
43  groupMassBegin = gm_i;
44  groupMassEnd = gm_e;
45  groupTotalForceBegin = gtf_i;
46  groupTotalForceEnd = gtf_e;
47  gridObjIndexBegin = goi_i;
48  gridObjIndexEnd = goi_e;
49  gridObjValueBegin = gov_i;
50  gridObjValueEnd = gov_e;
51  lastAtomsForcedBegin = last_atoms_forced_i;
52  lastAtomsForcedEnd = last_atoms_forced_e;
53  lastForcesBegin = last_forces_i;
54  forceIdBegin = forceid_i;
55  forceIdEnd = forceid_e;
56  totalForceBegin = totalforce_i;
57 
58  calculate();
60 
61  /* check to make sure the force arrays still match */
62  if(appForcesChanged) {
63  check();
64  }
65 }
66 
67 void GlobalMaster::check() const {
68  /* check to make sure the force arrays still match */
69  if(fAtoms.size() != appForces.size())
70  NAMD_die("# of atoms forced != # of forces given");
72  NAMD_die("# of groups forced != # of groups requested");
74  NAMD_die("# of grid objects forced != # of grid objects requested");
75 }
76 
78  reqAtomsChanged = false;
79  appForcesChanged = false;
80  reqGroupsChanged = false;
81  reqGridObjsChanged = false;
82 }
83 
85  NAMD_die("Internal error: pure virtual function called");
86 }
87 
89  step = -1;
91  clearChanged();
92  atomIdBegin = 0;
93  atomIdEnd = 0;
96  groupPositionEnd = 0;
97  groupMassBegin = 0;
98  groupMassEnd = 0;
100  gridObjValueEnd = 0;
102  lastAtomsForcedEnd = 0;
103  lastForcesBegin = 0;
104  forceIdBegin = 0;
105  forceIdEnd = 0;
106  totalForceBegin = 0;
107  lattice = 0;
108  totalForceRequested = false;
109 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
110  const SimParameters* simparams = Node::Object()->simParameters;
111  if (simparams->CUDASOAintegrateMode) {
113  } else {
114  reductionGpuResident = nullptr;
115  }
116 #endif
118 }
119 
121 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
123 #endif
124  // The reduction may be deleted by IMD
125  if (reduction) delete reduction;
126 }
127 
129 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
130  const SimParameters* simparams = Node::Object()->simParameters;
131  return (simparams->CUDASOAintegrate) ? reductionGpuResident :
132  reduction;
133 #else
134  return reduction;
135 #endif
136 }
137 
140  r->submit();
141 }
142 
143 void GlobalMaster::addReductionEnergy(int reductionTag, BigReal energy) {
145  r->item(reductionTag) += energy;
146 }
147 
149  return reqAtomsChanged;
150 }
151 
153  return appForcesChanged;
154 }
155 
157  return reqGroupsChanged;
158 }
159 
161  return reqGridObjsChanged;
162 }
163 
165  return reqAtoms;
166 }
167 
169  reqAtomsChanged = true;
170  DebugM(3,"modifyRequestedAtoms()\n" << endi);
171  return reqAtoms;
172 }
173 
175  return fAtoms;
176 }
177 
179  return appForces;
180 }
181 
183  return grpForces;
184 }
185 
187  return gridobjForces;
188 }
189 
191  return reqGroups;
192 }
193 
195  return reqGridObjs;
196 }
197 
199  appForcesChanged = true;
200  return fAtoms;
201 }
202 
204  appForcesChanged = true;
205  return appForces;
206 }
207 
209  // XXX should we mark something else here?
210  appForcesChanged = true;
211  return grpForces;
212 }
213 
215  reqGridObjsChanged = true;
216  DebugM(3,"modifyRequestedGridObjects()\n" << endi);
217  return reqGridObjs;
218 }
219 
221  appForcesChanged = true;
222  return gridobjForces;
223 }
224 
226  reqGroupsChanged = true;
227  DebugM(1,"Groups have changed.\n");
228  return reqGroups;
229 }
230 
232  return atomIdBegin;
233 }
234 
236  return atomIdEnd;
237 }
238 
240  return atomPositionBegin;
241 }
242 
244  return groupPositionBegin;
245 }
246 
248  return groupPositionEnd;
249 }
250 
252  return groupTotalForceBegin;
253 }
254 
256  return groupTotalForceEnd;
257 }
258 
260  return gridObjIndexBegin;
261 }
262 
264  return gridObjIndexEnd;
265 }
266 
268  return gridObjValueBegin;
269 }
270 
272  return gridObjValueEnd;
273 }
274 
276 {
277  return groupMassBegin;
278 }
279 
281  return groupMassEnd;
282 }
283 
285  return lastAtomsForcedBegin;
286 }
287 
289  return lastAtomsForcedEnd;
290 }
291 
293  return lastForcesBegin;
294 }
295 
297 {
298  return forceIdBegin;
299 }
300 
302 {
303  return forceIdEnd;
304 }
305 
307 {
308  return totalForceBegin;
309 }
static Node * Object()
Definition: Node.h:86
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
int size(void) const
Definition: ResizeArray.h:131
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
Definition: Vector.h:72
virtual void submit(void)=0
SimParameters * simParameters
Definition: Node.h:181
Bool CUDASOAintegrateMode
AtomIDList reqAtoms
Definition: GlobalMaster.h:181
ResizeArray< AtomIDList > reqGroups
Definition: GlobalMaster.h:188
bool changedAtoms()
Definition: GlobalMaster.C:148
BigReal & item(int i)
Definition: ReductionMgr.h:336
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
void submitReduction()
Definition: GlobalMaster.C:138
ForceList::const_iterator getGroupTotalForceBegin()
Definition: GlobalMaster.C:251
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:368
ForceList::iterator totalForceBegin
Definition: GlobalMaster.h:176
AtomIDList::iterator lastAtomsForcedEnd
Definition: GlobalMaster.h:171
ForceList::iterator lastForcesBegin
Definition: GlobalMaster.h:170
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:290
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
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 AtomID * 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
void NAMD_die(const char *err_msg)
Definition: common.C:147
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
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