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) {
112  reductionGpuResident = ReductionMgr::Object()->willSubmit(REDUCTIONS_GPURESIDENT);
113  } else {
114  reductionGpuResident = nullptr;
115  }
116 #endif
118 }
119 
121 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
122  if (reductionGpuResident) delete reductionGpuResident;
123 #endif
124  delete reduction;
125 }
126 
128 #if (defined (NAMD_CUDA) || defined (NAMD_HIP))
129  const SimParameters* simparams = Node::Object()->simParameters;
130  return (simparams->CUDASOAintegrate) ? reductionGpuResident :
131  reduction;
132 #else
133  return reduction;
134 #endif
135 }
136 
139  r->submit();
140 }
141 
142 void GlobalMaster::addReductionEnergy(int reductionTag, BigReal energy) {
144  r->item(reductionTag) += energy;
145 }
146 
148  return reqAtomsChanged;
149 }
150 
152  return appForcesChanged;
153 }
154 
156  return reqGroupsChanged;
157 }
158 
160  return reqGridObjsChanged;
161 }
162 
164  return reqAtoms;
165 }
166 
168  reqAtomsChanged = true;
169  DebugM(3,"modifyRequestedAtoms()\n" << endi);
170  return reqAtoms;
171 }
172 
174  return fAtoms;
175 }
176 
178  return appForces;
179 }
180 
182  return grpForces;
183 }
184 
186  return gridobjForces;
187 }
188 
190  return reqGroups;
191 }
192 
194  return reqGridObjs;
195 }
196 
198  appForcesChanged = true;
199  return fAtoms;
200 }
201 
203  appForcesChanged = true;
204  return appForces;
205 }
206 
208  // XXX should we mark something else here?
209  appForcesChanged = true;
210  return grpForces;
211 }
212 
214  reqGridObjsChanged = true;
215  DebugM(3,"modifyRequestedGridObjects()\n" << endi);
216  return reqGridObjs;
217 }
218 
220  appForcesChanged = true;
221  return gridobjForces;
222 }
223 
225  reqGroupsChanged = true;
226  DebugM(1,"Groups have changed.\n");
227  return reqGroups;
228 }
229 
231  return atomIdBegin;
232 }
233 
235  return atomIdEnd;
236 }
237 
239  return atomPositionBegin;
240 }
241 
243  return groupPositionBegin;
244 }
245 
247  return groupPositionEnd;
248 }
249 
251  return groupTotalForceBegin;
252 }
253 
255  return groupTotalForceEnd;
256 }
257 
259  return gridObjIndexBegin;
260 }
261 
263  return gridObjIndexEnd;
264 }
265 
267  return gridObjValueBegin;
268 }
269 
271  return gridObjValueEnd;
272 }
273 
275 {
276  return groupMassBegin;
277 }
278 
280  return groupMassEnd;
281 }
282 
284  return lastAtomsForcedBegin;
285 }
286 
288  return lastAtomsForcedEnd;
289 }
290 
292  return lastForcesBegin;
293 }
294 
296 {
297  return forceIdBegin;
298 }
299 
301 {
302  return forceIdEnd;
303 }
304 
306 {
307  return totalForceBegin;
308 }
static Node * Object()
Definition: Node.h:86
ForceList grpForces
Definition: GlobalMaster.h:189
ForceList & modifyAppliedForces()
Definition: GlobalMaster.C:202
int old_num_groups_requested
Definition: GlobalMaster.h:58
AtomIDList & modifyRequestedAtoms()
Definition: GlobalMaster.C:167
const ForceList & groupForces()
Definition: GlobalMaster.C:181
BigRealList & modifyGridObjForces()
Definition: GlobalMaster.C:219
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:300
AtomIDList::const_iterator getAtomIdBegin()
Definition: GlobalMaster.C:230
PositionList::const_iterator getGroupPositionEnd()
Definition: GlobalMaster.C:246
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:147
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:137
ForceList::const_iterator getGroupTotalForceBegin()
Definition: GlobalMaster.C:250
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:127
PositionList::const_iterator getAtomPositionBegin()
Definition: GlobalMaster.C:238
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:279
bool reqGridObjsChanged
Definition: GlobalMaster.h:191
const ResizeArray< AtomIDList > & requestedGroups()
Definition: GlobalMaster.C:189
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:295
virtual void calculate()
Definition: GlobalMaster.C:84
const ForceList & appliedForces()
Definition: GlobalMaster.C:177
PositionList::iterator atomPositionBegin
Definition: GlobalMaster.h:156
ForceList::iterator groupTotalForceEnd
Definition: GlobalMaster.h:162
IntList::const_iterator getGridObjIndexBegin()
Definition: GlobalMaster.C:258
bool changedForces()
Definition: GlobalMaster.C:151
bool changedGridObjs()
Definition: GlobalMaster.C:159
const AtomID * const_iterator
Definition: ResizeArray.h:38
BigRealList::iterator gridObjValueBegin
Definition: GlobalMaster.h:165
ForceList::const_iterator getLastForcesBegin()
Definition: GlobalMaster.C:291
bool reqAtomsChanged
Definition: GlobalMaster.h:180
AtomIDList::iterator atomIdEnd
Definition: GlobalMaster.h:155
IntList & modifyRequestedGridObjects()
Definition: GlobalMaster.C:213
BigRealList::iterator groupMassBegin
Definition: GlobalMaster.h:159
bool changedGroups()
Definition: GlobalMaster.C:155
AtomIDList & modifyForcedAtoms()
Definition: GlobalMaster.C:197
IntList reqGridObjs
Definition: GlobalMaster.h:192
ResizeArray< AtomIDList > & modifyRequestedGroups()
Definition: GlobalMaster.C:224
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:274
ForceList & modifyGroupForces()
Definition: GlobalMaster.C:207
AtomIDList::iterator atomIdBegin
Definition: GlobalMaster.h:154
BigRealList::const_iterator getGridObjValueBegin()
Definition: GlobalMaster.C:266
BigRealList::iterator groupMassEnd
Definition: GlobalMaster.h:160
IntList::const_iterator getGridObjIndexEnd()
Definition: GlobalMaster.C:262
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:234
AtomIDList::iterator forceIdBegin
Definition: GlobalMaster.h:174
const BigRealList & gridObjForces()
Definition: GlobalMaster.C:185
AtomIDList::const_iterator getLastAtomsForcedBegin()
Definition: GlobalMaster.C:283
void clearChanged()
Definition: GlobalMaster.C:77
AtomIDList fAtoms
Definition: GlobalMaster.h:184
void addReductionEnergy(int reductionTag, BigReal energy)
Definition: GlobalMaster.C:142
const IntList & requestedGridObjs()
Definition: GlobalMaster.C:193
AtomIDList::iterator forceIdEnd
Definition: GlobalMaster.h:175
AtomIDList::const_iterator getLastAtomsForcedEnd()
Definition: GlobalMaster.C:287
const AtomIDList & forcedAtoms()
Definition: GlobalMaster.C:173
void check() const
Definition: GlobalMaster.C:67
PositionList::const_iterator getGroupPositionBegin()
Definition: GlobalMaster.C:242
ForceList::const_iterator getTotalForce()
Definition: GlobalMaster.C:305
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:270
ForceList::const_iterator getGroupTotalForceEnd()
Definition: GlobalMaster.C:254
const AtomIDList & requestedAtoms()
Definition: GlobalMaster.C:163