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 SubmitReductionCharm
 
class SubmitReductionShared
 
class RequireReduction
 
class RequireReductionCharm
 
class RequireReductionShared
 

Detailed Description

Definition at line 241 of file ReductionMgr.h.

Constructor & Destructor Documentation

◆ ReductionMgr()

ReductionMgr::ReductionMgr ( )

Definition at line 282 of file ReductionMgr.C.

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

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

◆ ~ReductionMgr()

ReductionMgr::~ReductionMgr ( )

Definition at line 322 of file ReductionMgr.C.

References REDUCTION_MAX_SET_ID.

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

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

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

Referenced by ReductionMgr().

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

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

426  {
427 
428  int setID = msg->reductionSetID;
429  int size = msg->dataSize;
430  ReductionSet *set = getSet(setID,size);
431  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
432  NAMD_die("ReductionMgr::remoteRegister called while reductions outstanding on parent!");
433  }
434 
435  set->submitsRegistered++;
436  set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)]
437  = set->nextSequenceNumber;
438 // CkPrintf("[%d] reduction register received from node[%d] %d\n",
439 // CkMyPe(),childIndex(msg->sourceNode),msg->sourceNode);
440 
441  delete msg;
442 }
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ remoteSubmit()

void ReductionMgr::remoteSubmit ( ReductionSubmitMsg msg)

Definition at line 460 of file ReductionMgr.C.

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

460  {
461  int setID = msg->reductionSetID;
462  ReductionSet *set = reductionSets[setID];
463  int seqNum = msg->sequenceNumber
464  + set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)];
465 
466 //iout << "seq " << seqNum << " from " << msg->sourceNode << " received on " << CkMyPe() << "\n" << endi;
467  int size = msg->dataSize;
468  if ( size != set->dataSize ) {
469  NAMD_bug("ReductionMgr::remoteSubmit data sizes do not match.");
470  }
471 
472  BigReal *newData = msg->data;
473  ReductionSetData *data = set->getData(seqNum);
474  BigReal *curData = data->data;
475 #ifdef ARCH_POWERPC
476 #pragma disjoint (*curData, *newData)
477 #pragma unroll(4)
478 #endif
479  if ( setID == REDUCTIONS_MINIMIZER ) {
480  for ( int i = 0; i < size; ++i ) {
481  if ( newData[i] > curData[i] ) {
482  curData[i] = newData[i];
483  }
484  }
485  } else {
486  for ( int i = 0; i < size; ++i ) {
487  curData[i] += newData[i];
488  }
489  }
490 // CkPrintf("[%d] reduction Submit received from node[%d] %d\n",
491 // CkMyPe(),childIndex(msg->sourceNode),msg->sourceNode);
492  delete msg;
493 
494  data->submitsRecorded++;
495  if ( data->submitsRecorded == set->submitsRegistered ) {
496  mergeAndDeliver(set,seqNum);
497  }
498 }
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 445 of file ReductionMgr.C.

References NAMD_die(), and ReductionRegisterMsg::reductionSetID.

445  {
446 
447  int setID = msg->reductionSetID;
448  ReductionSet *set = reductionSets[setID];
449  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
450  NAMD_die("SubmitReduction deleted while reductions outstanding on parent!");
451  }
452 
453  set->submitsRegistered--;
454 
455  delSet(setID);
456  delete msg;
457 }
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ willRequire()

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

Definition at line 539 of file ReductionMgr.C.

References NAMD_die(), Node::Object(), REDUCTIONS_GPURESIDENT, RequireReductionCharm, RequireReductionShared, Node::simParameters, and simParams.

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

539  {
541  RequireReduction *handle;
542  // Only use the shared memory reductions for GPU-resident dynamics
543  if (simParams->GPUresidentSingleProcessMode && setID == REDUCTIONS_GPURESIDENT) {
544  handle = new RequireReductionShared;
545  } else {
546  ReductionSet *set = getSet(setID,size);
547  set->requireRegistered++;
548  if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
549  NAMD_die("ReductionMgr::willRequire called while reductions outstanding!");
550  }
551 
552  RequireReductionCharm* charm_handle = new RequireReductionCharm;
553  charm_handle->reductionSetID = setID;
554  charm_handle->sequenceNumber = set->nextSequenceNumber;
555  charm_handle->master = this;
556 
557  handle = (RequireReduction*) charm_handle;
558 
559  }
560  return handle;
561 }
static Node * Object()
Definition: Node.h:86
friend class RequireReductionCharm
Definition: ReductionMgr.h:248
SimParameters * simParameters
Definition: Node.h:181
void NAMD_die(const char *err_msg)
Definition: common.C:147
#define simParams
Definition: Output.C:131
friend class RequireReductionShared
Definition: ReductionMgr.h:249

◆ willSubmit()

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

Definition at line 368 of file ReductionMgr.C.

References ReductionSetData::data, SubmitReduction::data, SubmitReductionCharm::master, NAMD_die(), Node::Object(), REDUCTIONS_GPURESIDENT, SubmitReductionCharm::reductionSetID, SubmitReductionCharm::sequenceNumber, Node::simParameters, simParams, SubmitReductionCharm, SubmitReductionShared, 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(), CudaPmeOneDevice::CudaPmeOneDevice(), GlobalMaster::GlobalMaster(), ComputePmeCUDA::initialize(), CudaComputeNonbonded::initialize(), ComputePmeMgr::initialize_computes(), Patch::Patch(), PmePencilXYZ::PmePencilXYZ(), PmePencilZ::PmePencilZ(), and Sequencer::Sequencer().

368  {
370 
371  SubmitReduction *handle;
372  // Only use the shared memory reductions for GPU-resident dynamics
373  if (simParams->GPUresidentSingleProcessMode && setID == REDUCTIONS_GPURESIDENT) {
374  handle = new SubmitReductionShared;
375  } else {
376  ReductionSet *set = getSet(setID, size);
377  ReductionSetData *data = set->getData(set->nextSequenceNumber);
378  if ( data->submitsRecorded ) {
379  NAMD_die("ReductionMgr::willSubmit called while reductions outstanding!");
380  }
381 
382  set->submitsRegistered++;
383 
384  SubmitReductionCharm* charm_handle = new SubmitReductionCharm;
385  charm_handle->reductionSetID = setID;
386  charm_handle->sequenceNumber = set->nextSequenceNumber;
387  charm_handle->master = this;
388  charm_handle->data = data->data;
389 
390  handle = (SubmitReduction*) charm_handle;
391  }
392 
393  return handle;
394 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
friend class SubmitReductionShared
Definition: ReductionMgr.h:246
void NAMD_die(const char *err_msg)
Definition: common.C:147
#define simParams
Definition: Output.C:131
friend class SubmitReductionCharm
Definition: ReductionMgr.h:245
ReductionMgr * master
Definition: ReductionMgr.h:388
BigReal * data
Definition: ReductionMgr.h:328

Friends And Related Function Documentation

◆ RequireReduction

friend class RequireReduction
friend

Definition at line 247 of file ReductionMgr.h.

◆ RequireReductionCharm

friend class RequireReductionCharm
friend

Definition at line 248 of file ReductionMgr.h.

Referenced by willRequire().

◆ RequireReductionShared

friend class RequireReductionShared
friend

Definition at line 249 of file ReductionMgr.h.

Referenced by willRequire().

◆ SubmitReduction

friend class SubmitReduction
friend

Definition at line 244 of file ReductionMgr.h.

◆ SubmitReductionCharm

friend class SubmitReductionCharm
friend

Definition at line 245 of file ReductionMgr.h.

Referenced by willSubmit().

◆ SubmitReductionShared

friend class SubmitReductionShared
friend

Definition at line 246 of file ReductionMgr.h.

Referenced by willSubmit().


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