NAMD
Public Member Functions | Static Public Member Functions | Friends | List of all members
ReductionMgr Class Reference

#include <ReductionMgr.h>

Inheritance diagram for ReductionMgr:

Public Member Functions

 ReductionMgr ()
 
 ~ReductionMgr ()
 
void buildSpanTree (const int pe, const int max_intranode_children, const int max_internode_children, int *parent, int *num_children, int **children)
 
SubmitReductionwillSubmit (int setID, int size=-1)
 
RequireReductionwillRequire (int setID, int size=-1)
 
void remoteRegister (ReductionRegisterMsg *msg)
 
void remoteUnregister (ReductionRegisterMsg *msg)
 
void remoteSubmit (ReductionSubmitMsg *msg)
 

Static Public Member Functions

static ReductionMgrObject (void)
 

Friends

class SubmitReduction
 
class RequireReduction
 

Detailed Description

Definition at line 233 of file ReductionMgr.h.

Constructor & Destructor Documentation

ReductionMgr::ReductionMgr ( )

Definition at line 279 of file ReductionMgr.C.

References buildSpanTree(), DebugM, REDUCTION_MAX_CHILDREN, and REDUCTION_MAX_SET_ID.

279  {
280  if (CkpvAccess(ReductionMgr_instance) == 0) {
281  CkpvAccess(ReductionMgr_instance) = this;
282  } else {
283  DebugM(1, "ReductionMgr::ReductionMgr() - another instance exists!\n");
284  }
285 
287  &myParent,&numChildren,&children);
288 
289 // CkPrintf("TREE [%d] parent %d %d children\n",
290 // CkMyPe(),myParent,numChildren);
291 // if (numChildren > 0) {
292 // for(int i=0; i < numChildren; i++) {
293 // CkPrintf("TREE [%d] child %d %d\n",CkMyPe(),i,children[i]);
294 // }
295 // }
296 
297  // fill in the spanning tree fields
298 #if 0 // Old spanning tree
299  if (CkMyPe() == 0) {
300  myParent = -1;
301  } else {
302  myParent = (CkMyPe()-1)/REDUCTION_MAX_CHILDREN;
303  }
304  firstChild = CkMyPe()*REDUCTION_MAX_CHILDREN + 1;
305  if (firstChild > CkNumPes()) firstChild = CkNumPes();
306  lastChild = firstChild + REDUCTION_MAX_CHILDREN;
307  if (lastChild > CkNumPes()) lastChild = CkNumPes();
308 #endif
309 
310  // initialize data
311  for(int i=0; i<REDUCTION_MAX_SET_ID; i++) {
312  reductionSets[i] = 0;
313  }
314 
315  DebugM(1,"ReductionMgr() instantiated.\n");
316 }
void buildSpanTree(const int pe, const int max_intranode_children, const int max_internode_children, int *parent, int *num_children, int **children)
Definition: ReductionMgr.C:119
#define DebugM(x, y)
Definition: Debug.h:59
#define REDUCTION_MAX_CHILDREN
Definition: ReductionMgr.h:186
ReductionMgr::~ReductionMgr ( )

Definition at line 319 of file ReductionMgr.C.

References REDUCTION_MAX_SET_ID.

319  {
320  if (children != 0)
321  delete [] children;
322  for(int i=0; i<REDUCTION_MAX_SET_ID; i++) {
323  delete reductionSets[i];
324  }
325 
326 }

Member Function Documentation

void ReductionMgr::buildSpanTree ( const int  pe,
const int  max_intranode_children,
const int  max_internode_children,
int *  parent,
int *  num_children,
int **  children 
)

Definition at line 119 of file ReductionMgr.C.

References NAMD_bug(), NAMD_die(), and split().

Referenced by ReductionMgr().

125 {
126  // If pe is a first-node, children are same-node pes and perhaps some
127  // other first-nodes, and parents are other first-nodes. If pe is not a
128  // first-node, build the spanning tree among the children, and the parent
129  // is the corresponding first-node
130 
131  // No matter what, build list of PEs on my node first
132  const int num_pes = CkNumPes();
133  const int num_node_pes = CmiNumPesOnPhysicalNode(CmiPhysicalNodeID(pe));
134  int *node_pes = new int[num_node_pes];
135  int pe_index = -1;
136  const int first_pe = CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
137  int num_nodes = 0;
138  int *node_ids = new int[num_pes];
139  int first_pe_index = -1;
140  int my_parent_index;
141 
142  // Make sure PE 0 is a first-node
143  if (pe == 0 && first_pe != pe) {
144  NAMD_die("PE 0 is not the first physical node. This shouldn't happen");
145  }
146  // Get all the PEs on my node, and also build the list of all first-nodes
147  int i;
148  int node_pe_count=0;
149  for (i = 0; i < num_pes; i++) {
150  // Save first-nodes
151  if (CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(i)) == i) {
152  node_ids[num_nodes] = i;
153  if (i == first_pe)
154  first_pe_index = num_nodes;
155  num_nodes++;
156  }
157 
158  // Also, find pes on my node
159  const int i1 = (i + first_pe) % num_pes;
160  if (CmiPeOnSamePhysicalNode(first_pe,i1)) {
161  if ( node_pe_count == num_node_pes )
162  NAMD_bug("ReductionMgr::buildSpanTree found inconsistent physical node data from Charm++ runtime");
163  node_pes[node_pe_count] = i1;
164  if (pe == i1)
165  pe_index = node_pe_count;
166  node_pe_count++;
167  }
168  }
169  if ( pe_index < 0 || first_pe_index < 0 )
170  NAMD_bug("ReductionMgr::buildSpanTree found inconsistent physical node data from Charm++ runtime");
171 
172  // Any PE might have children on the same node, plus, if its a first-node,
173  // it may have several children on other nodes
174 
175  int first_loc_child_index = pe_index * max_intranode_children + 1;
176  int last_loc_child_index
177  = first_loc_child_index + max_intranode_children - 1;
178  if (first_loc_child_index > num_node_pes) {
179  first_loc_child_index = num_node_pes;
180  last_loc_child_index = num_node_pes;
181  } else {
182  if (last_loc_child_index >= num_node_pes)
183  last_loc_child_index = num_node_pes-1;
184  }
185 // CkPrintf("Local [%d] firstpe %d max %d num %d firstloc %d lastloc %d\n",
186 // pe,pe_index,max_intranode_children,num_node_pes,
187 // first_loc_child_index,last_loc_child_index);
188 
189  int first_rem_child_index = num_nodes;
190  int last_rem_child_index = num_nodes;
191  int rem_children=0;
192  int *rem_child_index = new int[max_internode_children];
193 
194  if (first_pe != pe) {
195  // I'm not a first_pe, so I have no more children, and my parent
196  // is someone else on my node
197  my_parent_index = (pe_index-1)/max_intranode_children;
198  *parent = node_pes[my_parent_index];
199  } else {
200  // I am a first_pe, so I may have additional children
201  // on other nodes, and my parent will be on another node
202 
203  int range_begin = 0;
204  int range_end = num_nodes;
205 
206  if (pe == 0) {
207  my_parent_index = -1;
208  *parent = -1;
209  } else {
210  my_parent_index = 0;
211  while ( first_pe_index != range_begin ) {
212  my_parent_index = range_begin;
213  ++range_begin;
214  for ( int i = 0; i < max_internode_children; ++i ) {
215  int split = range_begin + ( range_end - range_begin ) / ( max_internode_children - i );
216  if ( first_pe_index < split ) { range_end = split; break; }
217  else { range_begin = split; }
218  }
219  }
220  *parent = node_ids[my_parent_index];
221  }
222 
223  // now we know parent and need only repeat calculation of children
224  int prev_child_index = range_begin;
225  ++range_begin;
226  for ( int i = 0; i < max_internode_children; ++i ) {
227  if ( range_begin >= range_end ) break;
228  if ( range_begin > prev_child_index ) {
229  rem_child_index[rem_children++] = prev_child_index = range_begin;
230  }
231  range_begin += ( range_end - range_begin ) / ( max_internode_children - i );
232  }
233  }
234 
235  *num_children = 0;
236  //CkPrintf("TREE pe %d my_parent %d %d\n",pe,my_parent_index,*parent);
237 
238  int loc_children=0;
239  if (first_loc_child_index != num_node_pes) {
240  loc_children = last_loc_child_index - first_loc_child_index + 1;
241  *num_children += loc_children;
242 // CkPrintf("TREE pe %d %d local children\n",pe,loc_children);
243 // } else {
244 // CkPrintf("TREE pe %d No local children\n",pe);
245  }
246 
247  if (rem_children) {
248  *num_children += rem_children;
249 // CkPrintf("TREE pe %d %d rem children\n",pe,rem_children);
250 // } else {
251 // CkPrintf("TREE pe %d No rem children\n",pe);
252  }
253  if (*num_children == 0)
254  *children = 0;
255  else {
256  *children = new int[*num_children];
257 // CkPrintf("TREE pe %d children %d\n",pe,*num_children);
258  int k;
259  int child=0;
260  if (loc_children > 0) {
261  for(k=first_loc_child_index; k <= last_loc_child_index; k++) {
262 // CkPrintf("TREE pe %d loc child[%d,%d] %d\n",pe,child,k,node_pes[k]);
263  (*children)[child++]=node_pes[k];
264  }
265  }
266  if (rem_children > 0) {
267  for(k=0; k < rem_children; k++) {
268 // CkPrintf("TREE pe %d rem child[%d,%d] %d\n",pe,child,k,node_ids[rem_child_index[k]]);
269  (*children)[child++]=node_ids[rem_child_index[k]];
270  }
271  }
272  }
273  delete [] rem_child_index;
274  delete [] node_ids;
275  delete [] node_pes;
276 }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void NAMD_die(const char *err_msg)
Definition: common.C:83
std::vector< std::string > split(const std::string &text, std::string delimiter)
Definition: MoleculeQM.C:73
static ReductionMgr* ReductionMgr::Object ( void  )
inlinestatic
void ReductionMgr::remoteRegister ( ReductionRegisterMsg msg)

Definition at line 413 of file ReductionMgr.C.

References ReductionSet::addToRemoteSequenceNumber, ReductionRegisterMsg::dataSize, ReductionSet::getData(), NAMD_die(), ReductionSet::nextSequenceNumber, ReductionRegisterMsg::reductionSetID, ReductionRegisterMsg::sourceNode, ReductionSetData::submitsRecorded, and ReductionSet::submitsRegistered.

413  {
414 
415  int setID = msg->reductionSetID;
416  int size = msg->dataSize;
417  ReductionSet *set = getSet(setID,size);
418  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
419  NAMD_die("ReductionMgr::remoteRegister called while reductions outstanding on parent!");
420  }
421 
422  set->submitsRegistered++;
423  set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)]
424  = set->nextSequenceNumber;
425 // CkPrintf("[%d] reduction register received from node[%d] %d\n",
426 // CkMyPe(),childIndex(msg->sourceNode),msg->sourceNode);
427 
428  delete msg;
429 }
int nextSequenceNumber
Definition: ReductionMgr.h:216
int * addToRemoteSequenceNumber
Definition: ReductionMgr.h:228
ReductionSetData * getData(int seqNum)
Definition: ReductionMgr.C:88
int submitsRegistered
Definition: ReductionMgr.h:217
void NAMD_die(const char *err_msg)
Definition: common.C:83
void ReductionMgr::remoteSubmit ( ReductionSubmitMsg msg)

Definition at line 447 of file ReductionMgr.C.

References ReductionSet::addToRemoteSequenceNumber, ReductionSubmitMsg::data, ReductionSetData::data, ReductionSubmitMsg::dataSize, ReductionSet::dataSize, ReductionSet::getData(), NAMD_bug(), REDUCTIONS_MINIMIZER, ReductionSubmitMsg::reductionSetID, ReductionSubmitMsg::sequenceNumber, ReductionSubmitMsg::sourceNode, ReductionSetData::submitsRecorded, and ReductionSet::submitsRegistered.

447  {
448  int setID = msg->reductionSetID;
449  ReductionSet *set = reductionSets[setID];
450  int seqNum = msg->sequenceNumber
451  + set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)];
452 
453 //iout << "seq " << seqNum << " from " << msg->sourceNode << " received on " << CkMyPe() << "\n" << endi;
454  int size = msg->dataSize;
455  if ( size != set->dataSize ) {
456  NAMD_bug("ReductionMgr::remoteSubmit data sizes do not match.");
457  }
458 
459  BigReal *newData = msg->data;
460  ReductionSetData *data = set->getData(seqNum);
461  BigReal *curData = data->data;
462 #ifdef ARCH_POWERPC
463 #pragma disjoint (*curData, *newData)
464 #pragma unroll(4)
465 #endif
466  if ( setID == REDUCTIONS_MINIMIZER ) {
467  for ( int i = 0; i < size; ++i ) {
468  if ( newData[i] > curData[i] ) {
469  curData[i] = newData[i];
470  }
471  }
472  } else {
473  for ( int i = 0; i < size; ++i ) {
474  curData[i] += newData[i];
475  }
476  }
477 // CkPrintf("[%d] reduction Submit received from node[%d] %d\n",
478 // CkMyPe(),childIndex(msg->sourceNode),msg->sourceNode);
479  delete msg;
480 
481  data->submitsRecorded++;
482  if ( data->submitsRecorded == set->submitsRegistered ) {
483  mergeAndDeliver(set,seqNum);
484  }
485 }
int * addToRemoteSequenceNumber
Definition: ReductionMgr.h:228
ReductionSetData * getData(int seqNum)
Definition: ReductionMgr.C:88
void NAMD_bug(const char *err_msg)
Definition: common.C:123
int submitsRegistered
Definition: ReductionMgr.h:217
double BigReal
Definition: common.h:114
void ReductionMgr::remoteUnregister ( ReductionRegisterMsg msg)

Definition at line 432 of file ReductionMgr.C.

References ReductionSet::getData(), NAMD_die(), ReductionSet::nextSequenceNumber, ReductionRegisterMsg::reductionSetID, ReductionSetData::submitsRecorded, and ReductionSet::submitsRegistered.

432  {
433 
434  int setID = msg->reductionSetID;
435  ReductionSet *set = reductionSets[setID];
436  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
437  NAMD_die("SubmitReduction deleted while reductions outstanding on parent!");
438  }
439 
440  set->submitsRegistered--;
441 
442  delSet(setID);
443  delete msg;
444 }
int nextSequenceNumber
Definition: ReductionMgr.h:216
ReductionSetData * getData(int seqNum)
Definition: ReductionMgr.C:88
int submitsRegistered
Definition: ReductionMgr.h:217
void NAMD_die(const char *err_msg)
Definition: common.C:83
RequireReduction * ReductionMgr::willRequire ( int  setID,
int  size = -1 
)

Definition at line 526 of file ReductionMgr.C.

References ReductionSet::getData(), NAMD_die(), ReductionSet::nextSequenceNumber, RequireReduction, ReductionSet::requireRegistered, and ReductionSetData::submitsRecorded.

Referenced by Controller::Controller(), and PressureProfileReduction::PressureProfileReduction().

526  {
527  ReductionSet *set = getSet(setID,size);
528  set->requireRegistered++;
529  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
530  NAMD_die("ReductionMgr::willRequire called while reductions outstanding!");
531  }
532 
533  RequireReduction *handle = new RequireReduction;
534  handle->reductionSetID = setID;
535  handle->sequenceNumber = set->nextSequenceNumber;
536  handle->master = this;
537 
538  return handle;
539 }
int nextSequenceNumber
Definition: ReductionMgr.h:216
ReductionSetData * getData(int seqNum)
Definition: ReductionMgr.C:88
int requireRegistered
Definition: ReductionMgr.h:222
void NAMD_die(const char *err_msg)
Definition: common.C:83
friend class RequireReduction
Definition: ReductionMgr.h:237
SubmitReduction * ReductionMgr::willSubmit ( int  setID,
int  size = -1 
)

Definition at line 365 of file ReductionMgr.C.

References ReductionSetData::data, ReductionSet::getData(), NAMD_die(), ReductionSet::nextSequenceNumber, SubmitReduction, ReductionSetData::submitsRecorded, and ReductionSet::submitsRegistered.

Referenced by ComputeNonbondedCUDA::assignPatches(), colvarproxy_namd::colvarproxy_namd(), ComputeConsForce::ComputeConsForce(), ComputeConsTorque::ComputeConsTorque(), ComputeCylindricalBC::ComputeCylindricalBC(), ComputeEField::ComputeEField(), ComputeEwald::ComputeEwald(), ComputeExt::ComputeExt(), ComputeFmmSerial::ComputeFmmSerial(), ComputeFullDirect::ComputeFullDirect(), ComputeGBISser::ComputeGBISser(), ComputeGlobal::ComputeGlobal(), ComputeGridForce::ComputeGridForce(), ComputeHomeTuples< TholeElem, Thole, TholeValue >::ComputeHomeTuples(), ComputeLCPO::ComputeLCPO(), ComputeMsm::ComputeMsm(), ComputeMsmSerial::ComputeMsmSerial(), ComputeNonbondedPair::ComputeNonbondedPair(), ComputeNonbondedSelf::ComputeNonbondedSelf(), ComputeQM::ComputeQM(), ComputeRestraints::ComputeRestraints(), ComputeSphericalBC::ComputeSphericalBC(), ComputeStir::ComputeStir(), ComputeTclBC::ComputeTclBC(), Controller::Controller(), GlobalMasterEasy::GlobalMasterEasy(), GlobalMasterTcl::GlobalMasterTcl(), ComputePmeCUDA::initialize(), CudaComputeNonbonded::initialize(), ComputePmeMgr::initialize_computes(), Patch::Patch(), PmePencilXYZ::PmePencilXYZ(), PmePencilZ::PmePencilZ(), and Sequencer::Sequencer().

365  {
366  ReductionSet *set = getSet(setID, size);
367  ReductionSetData *data = set->getData(set->nextSequenceNumber);
368  if ( data->submitsRecorded ) {
369  NAMD_die("ReductionMgr::willSubmit called while reductions outstanding!");
370  }
371 
372  set->submitsRegistered++;
373 
374  SubmitReduction *handle = new SubmitReduction;
375  handle->reductionSetID = setID;
376  handle->sequenceNumber = set->nextSequenceNumber;
377  handle->master = this;
378  handle->data = data->data;
379 
380  return handle;
381 }
int nextSequenceNumber
Definition: ReductionMgr.h:216
ReductionSetData * getData(int seqNum)
Definition: ReductionMgr.C:88
friend class SubmitReduction
Definition: ReductionMgr.h:236
int submitsRegistered
Definition: ReductionMgr.h:217
void NAMD_die(const char *err_msg)
Definition: common.C:83

Friends And Related Function Documentation

friend class RequireReduction
friend

Definition at line 237 of file ReductionMgr.h.

Referenced by willRequire().

friend class SubmitReduction
friend

Definition at line 236 of file ReductionMgr.h.

Referenced by willSubmit().


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