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 234 of file ReductionMgr.h.

Constructor & Destructor Documentation

◆ ReductionMgr()

ReductionMgr::ReductionMgr ( )

Definition at line 280 of file ReductionMgr.C.

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

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

◆ ~ReductionMgr()

ReductionMgr::~ReductionMgr ( )

Definition at line 320 of file ReductionMgr.C.

References REDUCTION_MAX_SET_ID.

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

Member Function Documentation

◆ buildSpanTree()

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 120 of file ReductionMgr.C.

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

Referenced by ReductionMgr().

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

◆ Object()

static ReductionMgr* ReductionMgr::Object ( void  )
inlinestatic

◆ remoteRegister()

void ReductionMgr::remoteRegister ( ReductionRegisterMsg msg)

Definition at line 414 of file ReductionMgr.C.

References ReductionRegisterMsg::dataSize, NAMD_die(), ReductionRegisterMsg::reductionSetID, and ReductionRegisterMsg::sourceNode.

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

◆ remoteSubmit()

void ReductionMgr::remoteSubmit ( ReductionSubmitMsg msg)

Definition at line 448 of file ReductionMgr.C.

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

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

◆ remoteUnregister()

void ReductionMgr::remoteUnregister ( ReductionRegisterMsg msg)

Definition at line 433 of file ReductionMgr.C.

References NAMD_die(), and ReductionRegisterMsg::reductionSetID.

433  {
434 
435  int setID = msg->reductionSetID;
436  ReductionSet *set = reductionSets[setID];
437  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
438  NAMD_die("SubmitReduction deleted while reductions outstanding on parent!");
439  }
440 
441  set->submitsRegistered--;
442 
443  delSet(setID);
444  delete msg;
445 }
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ willRequire()

RequireReduction * ReductionMgr::willRequire ( int  setID,
int  size = -1 
)

Definition at line 527 of file ReductionMgr.C.

References NAMD_die(), and RequireReduction.

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

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

◆ willSubmit()

SubmitReduction * ReductionMgr::willSubmit ( int  setID,
int  size = -1 
)

Definition at line 366 of file ReductionMgr.C.

References ReductionSetData::data, NAMD_die(), SubmitReduction, and ReductionSetData::submitsRecorded.

Referenced by 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(), ComputeLjPmeSerial::ComputeLjPmeSerial(), 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().

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

Friends And Related Function Documentation

◆ RequireReduction

friend class RequireReduction
friend

Definition at line 238 of file ReductionMgr.h.

Referenced by willRequire().

◆ SubmitReduction

friend class SubmitReduction
friend

Definition at line 237 of file ReductionMgr.h.

Referenced by willSubmit().


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