NAMD
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
CollectionMaster Class Reference

#include <CollectionMaster.h>

Inheritance diagram for CollectionMaster:

Classes

class  CollectVectorInstance
 
class  CollectVectorSequence
 

Public Types

enum  OperationStatus { NOT_PROCESSED, IN_PROCESS, HAS_PROCESSED }
 

Public Member Functions

 CollectionMaster ()
 
 ~CollectionMaster (void)
 
void receivePositions (CollectVectorMsg *msg)
 
void receiveVelocities (CollectVectorMsg *msg)
 
void receiveForces (CollectVectorMsg *msg)
 
void receiveDataStream (DataStreamMsg *msg)
 
void enqueuePositions (int seq, Lattice &lattice)
 
void enqueueVelocities (int seq)
 
void enqueueForces (int seq)
 
void disposePositions (CollectVectorInstance *c)
 
void disposeVelocities (CollectVectorInstance *c)
 
void disposeForces (CollectVectorInstance *c)
 
void blockPositions ()
 
void unblockPositions ()
 
void receiveOutputPosReady (int seq)
 
void receiveOutputVelReady (int seq)
 
void receiveOutputForceReady (int seq)
 
void startNextRoundOutputPos (double totalT)
 
void startNextRoundOutputVel (double totalT)
 
void startNextRoundOutputForce (double totalT)
 
void wrapCoorFinished ()
 

Static Public Member Functions

static CollectionMasterObject ()
 

Detailed Description

Definition at line 40 of file CollectionMaster.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CollectionMaster::CollectionMaster ( )

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 22 of file CollectionMaster.C.

References DebugM.

23 {
24  if (CkpvAccess(CollectionMaster_instance) == 0) {
25  CkpvAccess(CollectionMaster_instance) = this;
26  } else {
27  DebugM(1, "CollectionMaster::CollectionMaster() - another instance of CollectionMaster exists!\n");
28  }
29  dataStreamFile = 0;
30 
31 #ifdef MEM_OPT_VERSION
32  wrapCoorDoneCnt = 0;
33  posDoneCnt = 0;
34  velDoneCnt = 0;
35  parOut = new ParOutput();
36 #endif
37 
38  posTimings = 10; velTimings = forceTimings = 5;
39 }
#define DebugM(x, y)
Definition: Debug.h:59
CollectionMaster::~CollectionMaster ( void  )

Definition at line 42 of file CollectionMaster.C.

43 {
44 }

Member Function Documentation

void CollectionMaster::blockPositions ( )
inline
void CollectionMaster::disposeForces ( CollectVectorInstance c)

Definition at line 157 of file CollectionMaster.C.

References ResizeArray< T >::begin(), CollectionMaster::CollectVectorInstance::data, DebugM, Output::force(), CollectionMaster::CollectVectorInstance::free(), memusage_MB(), Node::Object(), Node::output, CollectionMaster::CollectVectorInstance::seq, and ResizeArray< T >::size().

Referenced by enqueueForces(), and receiveForces().

158 {
159 #ifndef MEM_OPT_VERSION
160  DebugM(3,"Collected forces at " << c->seq << std::endl);
161  int seq = c->seq;
162  int size = c->data.size();
163  Vector *data = c->data.begin();
164  double exectime = CmiWallTimer();
165  double mem = memusage_MB();
166  Node::Object()->output->force(seq,size,data);
167  c->free();
168  exectime = CmiWallTimer()-exectime;
169  if ( forceTimings ) {
170  CkPrintf("The last force output (seq=%d) takes %.3f seconds, %.3f MB of memory in use\n", seq, exectime, mem);
171  --forceTimings;
172  }
173 #endif
174 }
static Node * Object()
Definition: Node.h:86
Definition: Vector.h:64
Output * output
Definition: Node.h:182
#define DebugM(x, y)
Definition: Debug.h:59
double memusage_MB()
Definition: memusage.h:13
void force(int, int, Vector *)
Definition: Output.C:486
void CollectionMaster::disposePositions ( CollectVectorInstance c)

Definition at line 69 of file CollectionMaster.C.

References ResizeArray< T >::begin(), Output::coordinate(), CollectionMaster::CollectVectorInstance::data, DebugM, CollectionMaster::CollectVectorInstance::fdata, CollectionMaster::CollectVectorInstance::free(), CollectionMaster::CollectVectorInstance::lattice, memusage_MB(), Node::Object(), Node::output, CollectionMaster::CollectVectorInstance::seq, and ResizeArray< T >::size().

Referenced by enqueuePositions(), and receivePositions().

70 {
71 #ifndef MEM_OPT_VERSION
72  DebugM(3,"Collected positions at " << c->seq << std::endl);
73  int seq = c->seq;
74  int size = c->data.size();
75  if ( ! size ) size = c->fdata.size();
76  Vector *data = c->data.begin();
77  FloatVector *fdata = c->fdata.begin();
78  double exectime = CmiWallTimer();
79  double mem = memusage_MB();
80  Node::Object()->output->coordinate(seq,size,data,fdata,c->lattice);
81  c->free();
82  exectime = CmiWallTimer()-exectime;
83  if ( posTimings ) {
84  CkPrintf("The last position output (seq=%d) takes %.3f seconds, %.3f MB of memory in use\n", seq, exectime, mem);
85  --posTimings;
86  }
87 #endif
88 }
static Node * Object()
Definition: Node.h:86
Definition: Vector.h:64
Output * output
Definition: Node.h:182
#define DebugM(x, y)
Definition: Debug.h:59
void coordinate(int, int, Vector *, FloatVector *, Lattice &)
Definition: Output.C:277
double memusage_MB()
Definition: memusage.h:13
void CollectionMaster::disposeVelocities ( CollectVectorInstance c)

Definition at line 114 of file CollectionMaster.C.

References ResizeArray< T >::begin(), CollectionMaster::CollectVectorInstance::data, DebugM, CollectionMaster::CollectVectorInstance::free(), memusage_MB(), Node::Object(), Node::output, CollectionMaster::CollectVectorInstance::seq, ResizeArray< T >::size(), and Output::velocity().

Referenced by enqueueVelocities(), and receiveVelocities().

115 {
116 #ifndef MEM_OPT_VERSION
117  DebugM(3,"Collected velocities at " << c->seq << std::endl);
118  int seq = c->seq;
119  int size = c->data.size();
120  Vector *data = c->data.begin();
121  double exectime = CmiWallTimer();
122  double mem = memusage_MB();
123  Node::Object()->output->velocity(seq,size,data);
124  c->free();
125  exectime = CmiWallTimer()-exectime;
126  if ( velTimings ) {
127  CkPrintf("The last velocity output (seq=%d) takes %.3f seconds, %.3f MB of memory in use\n", seq, exectime, mem);
128  --velTimings;
129  }
130 #endif
131 }
static Node * Object()
Definition: Node.h:86
Definition: Vector.h:64
Output * output
Definition: Node.h:182
#define DebugM(x, y)
Definition: Debug.h:59
double memusage_MB()
Definition: memusage.h:13
void velocity(int, int, Vector *)
Definition: Output.C:396
void CollectionMaster::enqueueForces ( int  seq)

Definition at line 145 of file CollectionMaster.C.

References disposeForces(), CollectionMaster::CollectVectorSequence::enqueue(), and CollectionMaster::CollectVectorSequence::removeReady().

Referenced by Controller::enqueueCollections().

146 {
147  Lattice dummy;
148  forces.enqueue(seq,dummy);
149 #ifndef MEM_OPT_VERSION
150  CollectVectorInstance *c;
151  while ( ( c = forces.removeReady() ) ) { disposeForces(c); }
152 #else
153  checkForceReady();
154 #endif
155 }
void disposeForces(CollectVectorInstance *c)
static __thread float4 * forces
void CollectionMaster::enqueuePositions ( int  seq,
Lattice lattice 
)

Definition at line 57 of file CollectionMaster.C.

References disposePositions(), CollectionMaster::CollectVectorSequence::enqueue(), and CollectionMaster::CollectVectorSequence::removeReady().

Referenced by Controller::enqueueCollections().

58 {
59  positions.enqueue(seq,lattice);
60 
61 #ifndef MEM_OPT_VERSION
62  CollectVectorInstance *c;
63  while ( ( c = positions.removeReady() ) ) { disposePositions(c); }
64 #else
65  checkPosReady();
66 #endif
67 }
CollectVectorInstance * removeReady(void)
void enqueue(int seq, Lattice &lattice)
void disposePositions(CollectVectorInstance *c)
void CollectionMaster::enqueueVelocities ( int  seq)

Definition at line 102 of file CollectionMaster.C.

References disposeVelocities(), CollectionMaster::CollectVectorSequence::enqueue(), and CollectionMaster::CollectVectorSequence::removeReady().

Referenced by Controller::enqueueCollections().

103 {
104  Lattice dummy;
105  velocities.enqueue(seq,dummy);
106 #ifndef MEM_OPT_VERSION
107  CollectVectorInstance *c;
108  while ( ( c = velocities.removeReady() ) ) { disposeVelocities(c); }
109 #else
110  checkVelReady();
111 #endif
112 }
CollectVectorInstance * removeReady(void)
void enqueue(int seq, Lattice &lattice)
void disposeVelocities(CollectVectorInstance *c)
static CollectionMaster* CollectionMaster::Object ( )
inlinestatic

Definition at line 43 of file CollectionMaster.h.

Referenced by recvReplicaDcdAck(), sendReplicaDcdData(), and sendReplicaDcdInit().

43  {
44  return CkpvAccess(CollectionMaster_instance);
45  }
void CollectionMaster::receiveDataStream ( DataStreamMsg msg)

Definition at line 177 of file CollectionMaster.C.

References SimParameters::auxFilename, ResizeArray< T >::begin(), DataStreamMsg::data, NAMD_backup_file(), NAMD_die(), Node::Object(), and Node::simParameters.

177  {
178  if ( ! dataStreamFile ) {
179  char *fname = Node::Object()->simParameters->auxFilename;
180  // iout has large file linking issues on AIX
181  // iout << iINFO << "OPENING AUXILIARY DATA STREAM FILE "
182  // << fname << "\n" << endi;
183  CkPrintf("Info: OPENING AUXILIARY DATA STREAM FILE %s\n", fname);
184  NAMD_backup_file(fname);
185  dataStreamFile = fopen(fname,"w");
186  if ( ! dataStreamFile )
187  NAMD_die("Can't open auxiliary data stream file!");
188  }
189  fprintf(dataStreamFile,"%s",msg->data.begin());
190  fflush(dataStreamFile);
191  delete msg;
192 }
static Node * Object()
Definition: Node.h:86
char auxFilename[128]
SimParameters * simParameters
Definition: Node.h:178
void NAMD_die(const char *err_msg)
Definition: common.C:83
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:159
ResizeArray< char > data
iterator begin(void)
Definition: ResizeArray.h:36
void CollectionMaster::receiveForces ( CollectVectorMsg msg)

Definition at line 134 of file CollectionMaster.C.

References disposeForces(), Node::Object(), CollectionMaster::CollectVectorSequence::removeReady(), and CollectionMaster::CollectVectorSequence::submitData().

135 {
136 #ifndef MEM_OPT_VERSION
137  forces.submitData(msg,Node::Object()->molecule->numAtoms);
138  delete msg;
139 
140  CollectVectorInstance *c;
141  while ( ( c = forces.removeReady() ) ) { disposeForces(c); }
142 #endif
143 }
static Node * Object()
Definition: Node.h:86
void disposeForces(CollectVectorInstance *c)
static __thread float4 * forces
void CollectionMaster::receiveOutputForceReady ( int  seq)

Definition at line 217 of file CollectionMaster.C.

References CollectionMaster::CollectVectorSequence::submitData().

217  {
218 #ifdef MEM_OPT_VERSION
219  forces.submitData(seq);
220  checkForceReady();
221 #endif
222 }
static __thread float4 * forces
void CollectionMaster::receiveOutputPosReady ( int  seq)
void CollectionMaster::receiveOutputVelReady ( int  seq)

Definition at line 210 of file CollectionMaster.C.

References CollectionMaster::CollectVectorSequence::submitData().

210  {
211 #ifdef MEM_OPT_VERSION
212  velocities.submitData(seq);
213  checkVelReady();
214 #endif
215 }
void submitData(CollectVectorMsg *msg, int max_index)
void CollectionMaster::receivePositions ( CollectVectorMsg msg)

Definition at line 46 of file CollectionMaster.C.

References disposePositions(), Node::Object(), CollectionMaster::CollectVectorSequence::removeReady(), and CollectionMaster::CollectVectorSequence::submitData().

47 {
48 #ifndef MEM_OPT_VERSION
49  positions.submitData(msg,Node::Object()->molecule->numAtoms);
50  delete msg;
51 
52  CollectVectorInstance *c;
53  while ( ( c = positions.removeReady() ) ) { disposePositions(c); }
54 #endif
55 }
static Node * Object()
Definition: Node.h:86
CollectVectorInstance * removeReady(void)
void submitData(CollectVectorMsg *msg, int max_index)
void disposePositions(CollectVectorInstance *c)
void CollectionMaster::receiveVelocities ( CollectVectorMsg msg)

Definition at line 91 of file CollectionMaster.C.

References disposeVelocities(), Node::Object(), CollectionMaster::CollectVectorSequence::removeReady(), and CollectionMaster::CollectVectorSequence::submitData().

92 {
93 #ifndef MEM_OPT_VERSION
94  velocities.submitData(msg,Node::Object()->molecule->numAtoms);
95  delete msg;
96 
97  CollectVectorInstance *c;
98  while ( ( c = velocities.removeReady() ) ) { disposeVelocities(c); }
99 #endif
100 }
static Node * Object()
Definition: Node.h:86
CollectVectorInstance * removeReady(void)
void submitData(CollectVectorMsg *msg, int max_index)
void disposeVelocities(CollectVectorInstance *c)
void CollectionMaster::startNextRoundOutputForce ( double  totalT)

Definition at line 293 of file CollectionMaster.C.

References CollectionMaster::CollectVectorInstance::free(), IN_PROCESS, memusage_MB(), Node::Object(), and CollectionMaster::CollectVectorInstance::seq.

293  {
294 #ifdef MEM_OPT_VERSION
295 
296  if(totalT > forceIOTime) forceIOTime = totalT;
297 
298 #if OUTPUT_SINGLE_FILE
299  if(++forceDoneCnt < Node::Object()->simParameters->numoutputwrts) return;
300 #else
301  if(++forceDoneCnt < Node::Object()->simParameters->numoutputprocs) return;
302 #endif
303 
304  forceDoneCnt = 0;
305 
306  //retrieve the last ready instance
307  CollectVectorInstance *c = forces.getReady();
308  int seq = c->seq;
309  CmiAssert(c->status == IN_PROCESS);
310  double mem = memusage_MB();
311  forces.removeFirstReady();
312  c->free();
313  forceOutTime = CmiWallTimer()-forceOutTime;
314  if ( forceTimings ) {
315  CkPrintf("The last force output (seq=%d) takes %.3f seconds(file I/O: %.3f secs), %.3f MB of memory in use\n", seq, forceOutTime, forceIOTime, mem);
316  --forceTimings;
317  }
318 
319  //Actually the c->status doesn't need to be checked because it is
320  //certain that the new ready one will not be in IN_PROCESS status
321  checkForceReady();
322 #endif
323 }
static Node * Object()
Definition: Node.h:86
static __thread float4 * forces
double memusage_MB()
Definition: memusage.h:13
void CollectionMaster::startNextRoundOutputPos ( double  totalT)

Definition at line 225 of file CollectionMaster.C.

References CollectionMaster::CollectVectorInstance::free(), IN_PROCESS, memusage_MB(), Node::Object(), and CollectionMaster::CollectVectorInstance::seq.

225  {
226 #ifdef MEM_OPT_VERSION
227 
228  if(totalT > posIOTime) posIOTime = totalT;
229 
230 #ifndef OUTPUT_SINGLE_FILE
231 #error OUTPUT_SINGLE_FILE not defined!
232 #endif
233 
234 #if OUTPUT_SINGLE_FILE
235  if(++posDoneCnt < Node::Object()->simParameters->numoutputwrts) return;
236 #else
237  if(++posDoneCnt < Node::Object()->simParameters->numoutputprocs) return;
238 #endif
239 
240  posDoneCnt = 0;
241 
242  //retrieve the last ready instance
243  CollectVectorInstance *c = positions.getReady();
244  int seq = c->seq;
245  CmiAssert(c->status == IN_PROCESS);
246  double mem = memusage_MB();
247  positions.removeFirstReady();
248  c->free();
249  posOutTime = CmiWallTimer()-posOutTime;
250  if ( posTimings ) {
251  CkPrintf("The last position output (seq=%d) takes %.3f seconds(file I/O: %.3f secs), %.3f MB of memory in use\n", seq, posOutTime, posIOTime, mem);
252  --posTimings;
253  }
254 
255  //Actually the c->status doesn't need to be checked because it is
256  //certain that the new ready one will not be in IN_PROCESS status
257  checkPosReady();
258 #endif
259 }
static Node * Object()
Definition: Node.h:86
double memusage_MB()
Definition: memusage.h:13
void CollectionMaster::startNextRoundOutputVel ( double  totalT)

Definition at line 261 of file CollectionMaster.C.

References CollectionMaster::CollectVectorInstance::free(), IN_PROCESS, memusage_MB(), Node::Object(), and CollectionMaster::CollectVectorInstance::seq.

261  {
262 #ifdef MEM_OPT_VERSION
263 
264  if(totalT > velIOTime) velIOTime = totalT;
265 
266 #if OUTPUT_SINGLE_FILE
267  if(++velDoneCnt < Node::Object()->simParameters->numoutputwrts) return;
268 #else
269  if(++velDoneCnt < Node::Object()->simParameters->numoutputprocs) return;
270 #endif
271 
272  velDoneCnt = 0;
273 
274  //retrieve the last ready instance
275  CollectVectorInstance *c = velocities.getReady();
276  int seq = c->seq;
277  CmiAssert(c->status == IN_PROCESS);
278  double mem = memusage_MB();
279  velocities.removeFirstReady();
280  c->free();
281  velOutTime = CmiWallTimer()-velOutTime;
282  if ( velTimings ) {
283  CkPrintf("The last velocity output (seq=%d) takes %.3f seconds(file I/O: %.3f secs), %.3f MB of memory in use\n", seq, velOutTime, velIOTime, mem);
284  --velTimings;
285  }
286 
287  //Actually the c->status doesn't need to be checked because it is
288  //certain that the new ready one will not be in IN_PROCESS status
289  checkVelReady();
290 #endif
291 }
static Node * Object()
Definition: Node.h:86
double memusage_MB()
Definition: memusage.h:13
void CollectionMaster::unblockPositions ( )
inline
void CollectionMaster::wrapCoorFinished ( )

Definition at line 326 of file CollectionMaster.C.

References Node::Object(), and CollectionMaster::CollectVectorInstance::seq.

326  {
327 #ifdef MEM_OPT_VERSION
328  if(++wrapCoorDoneCnt == Node::Object()->simParameters->numoutputprocs){
329  wrapCoorDoneCnt = 0;
330 
331  //count the wrapping-coor time into master writing time
332  posIOTime = CmiWallTimer()-posOutTime;
333 
334  //it's ready to output positions
335  CollectVectorInstance *c = positions.getReady();
336 
337  CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
338  ParallelIOMgr *ioMgr = io.ckLocalBranch();
339 
340 #if OUTPUT_SINGLE_FILE
341  //notify output procs to do Token based output
342  int grpsize = ioMgr->numOutputProcs / ioMgr->numOutputWrts;
343  int remains = ioMgr->numOutputProcs % ioMgr->numOutputWrts;
344  int outrank = 0;
345  int i;
346  for(i=0; i<remains; i++){
347  io[ioMgr->outputProcArray[outrank]].disposePositions(c->seq, posIOTime);
348  outrank += (grpsize+1);
349  }
350  for(; i<ioMgr->numOutputWrts; i++){
351  io[ioMgr->outputProcArray[outrank]].disposePositions(c->seq, posIOTime);
352  outrank += grpsize;
353  }
354 #else
355  //output multiple files
356  for(int i=0; i<ioMgr->numOutputProcs; i++) {
357  io[ioMgr->outputProcArray[i]].disposePositions(c->seq, posIOTime);
358  }
359 #endif
360 
361  }
362 #endif
363 }
static Node * Object()
Definition: Node.h:86

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