ReductionMgr Class Reference

#include <ReductionMgr.h>

List of all members.

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.

00279                            {
00280     if (CkpvAccess(ReductionMgr_instance) == 0) {
00281       CkpvAccess(ReductionMgr_instance) = this;
00282     } else {
00283       DebugM(1, "ReductionMgr::ReductionMgr() - another instance exists!\n");
00284     }
00285     
00286     buildSpanTree(CkMyPe(),REDUCTION_MAX_CHILDREN,REDUCTION_MAX_CHILDREN,
00287                   &myParent,&numChildren,&children);
00288     
00289 //    CkPrintf("TREE [%d] parent %d %d children\n",
00290 //      CkMyPe(),myParent,numChildren);
00291 //    if (numChildren > 0) {
00292 //      for(int i=0; i < numChildren; i++)  {
00293 //        CkPrintf("TREE [%d] child %d %d\n",CkMyPe(),i,children[i]);
00294 //      }
00295 //    }
00296     
00297     // fill in the spanning tree fields
00298 #if 0  // Old spanning tree
00299     if (CkMyPe() == 0) {
00300       myParent = -1;
00301     } else {
00302       myParent = (CkMyPe()-1)/REDUCTION_MAX_CHILDREN;
00303     }
00304     firstChild = CkMyPe()*REDUCTION_MAX_CHILDREN + 1;
00305     if (firstChild > CkNumPes()) firstChild = CkNumPes();
00306     lastChild = firstChild + REDUCTION_MAX_CHILDREN;
00307     if (lastChild > CkNumPes()) lastChild = CkNumPes();
00308 #endif
00309 
00310     // initialize data
00311     for(int i=0; i<REDUCTION_MAX_SET_ID; i++) {
00312       reductionSets[i] = 0;
00313     }
00314 
00315     DebugM(1,"ReductionMgr() instantiated.\n");
00316 }

ReductionMgr::~ReductionMgr (  ) 

Definition at line 319 of file ReductionMgr.C.

References REDUCTION_MAX_SET_ID.

00319                             {
00320     if (children != 0)
00321       delete [] children;
00322     for(int i=0; i<REDUCTION_MAX_SET_ID; i++) {
00323       delete reductionSets[i];
00324     }
00325 
00326 }


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 eabffunc::split().

Referenced by ReductionMgr().

00125 {
00126   // If pe is a first-node, children are same-node pes and perhaps some
00127   // other first-nodes, and parents are other first-nodes. If pe is not a 
00128   // first-node, build the spanning tree among the children, and the parent
00129   // is the corresponding first-node
00130 
00131   // No matter what, build list of PEs on my node first
00132   const int num_pes = CkNumPes();
00133   const int num_node_pes = CmiNumPesOnPhysicalNode(CmiPhysicalNodeID(pe)); 
00134   int *node_pes = new int[num_node_pes];
00135   int pe_index = -1;
00136   const int first_pe = CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
00137   int num_nodes = 0;
00138   int *node_ids = new int[num_pes];
00139   int first_pe_index = -1;
00140   int my_parent_index;
00141   
00142   // Make sure PE 0 is a first-node
00143   if (pe == 0 && first_pe != pe) {
00144     NAMD_die("PE 0 is not the first physical node. This shouldn't happen");
00145   }
00146   // Get all the PEs on my node, and also build the list of all first-nodes
00147   int i;
00148   int node_pe_count=0;
00149   for (i = 0; i < num_pes; i++) {
00150     // Save first-nodes
00151     if (CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(i)) == i) {
00152       node_ids[num_nodes] = i;
00153       if (i == first_pe)
00154         first_pe_index = num_nodes;
00155       num_nodes++;
00156     }
00157 
00158     // Also, find pes on my node
00159     const int i1 = (i + first_pe) % num_pes;
00160     if (CmiPeOnSamePhysicalNode(first_pe,i1)) {
00161       if ( node_pe_count == num_node_pes )
00162         NAMD_bug("ReductionMgr::buildSpanTree found inconsistent physical node data from Charm++ runtime");
00163       node_pes[node_pe_count] = i1;
00164       if (pe == i1)
00165         pe_index = node_pe_count;
00166       node_pe_count++;
00167     }
00168   }
00169   if ( pe_index < 0 || first_pe_index < 0 )
00170     NAMD_bug("ReductionMgr::buildSpanTree found inconsistent physical node data from Charm++ runtime");
00171   
00172   // Any PE might have children on the same node, plus, if its a first-node,
00173   // it may have several children on other nodes
00174 
00175   int first_loc_child_index = pe_index * max_intranode_children + 1;
00176   int last_loc_child_index 
00177     = first_loc_child_index + max_intranode_children - 1;
00178   if (first_loc_child_index > num_node_pes) {
00179     first_loc_child_index = num_node_pes;
00180     last_loc_child_index = num_node_pes;
00181   } else {
00182     if (last_loc_child_index >= num_node_pes) 
00183       last_loc_child_index = num_node_pes-1;
00184   }
00185 //  CkPrintf("Local [%d] firstpe %d max %d num %d firstloc %d lastloc %d\n",
00186 //           pe,pe_index,max_intranode_children,num_node_pes,
00187 //           first_loc_child_index,last_loc_child_index);
00188   
00189   int first_rem_child_index = num_nodes;
00190   int last_rem_child_index = num_nodes;
00191   int rem_children=0;
00192   int *rem_child_index = new int[max_internode_children];
00193   
00194   if (first_pe != pe) {
00195     // I'm not a first_pe, so I have no more children, and my parent
00196     // is someone else on my node
00197     my_parent_index = (pe_index-1)/max_intranode_children;
00198     *parent = node_pes[my_parent_index];
00199   } else {
00200     // I am a first_pe, so I may have additional children
00201     // on other nodes, and my parent will be on another node
00202 
00203     int range_begin = 0;
00204     int range_end = num_nodes;
00205 
00206     if (pe == 0) {
00207       my_parent_index = -1;
00208       *parent = -1;
00209     } else {
00210       my_parent_index = 0;
00211       while ( first_pe_index != range_begin ) {
00212         my_parent_index = range_begin;
00213         ++range_begin;
00214         for ( int i = 0; i < max_internode_children; ++i ) {
00215           int split = range_begin + ( range_end - range_begin ) / ( max_internode_children - i );
00216           if ( first_pe_index < split ) { range_end = split; break; } 
00217           else { range_begin = split; }
00218         }
00219       }
00220       *parent = node_ids[my_parent_index];
00221     }
00222 
00223     // now we know parent and need only repeat calculation of children
00224     int prev_child_index = range_begin;
00225     ++range_begin;
00226     for ( int i = 0; i < max_internode_children; ++i ) {
00227       if ( range_begin >= range_end ) break;
00228       if ( range_begin > prev_child_index ) {
00229         rem_child_index[rem_children++] = prev_child_index = range_begin;
00230       }
00231       range_begin += ( range_end - range_begin ) / ( max_internode_children - i );
00232     }
00233   }
00234 
00235   *num_children = 0;
00236   //CkPrintf("TREE pe %d my_parent %d %d\n",pe,my_parent_index,*parent);
00237 
00238   int loc_children=0;
00239   if (first_loc_child_index != num_node_pes) {
00240     loc_children = last_loc_child_index - first_loc_child_index + 1;
00241     *num_children += loc_children;
00242 //    CkPrintf("TREE pe %d %d local children\n",pe,loc_children);
00243 //  } else {
00244 //    CkPrintf("TREE pe %d No local children\n",pe);
00245   }
00246 
00247   if (rem_children) {
00248     *num_children += rem_children;
00249 //    CkPrintf("TREE pe %d %d rem children\n",pe,rem_children);
00250 //  } else {
00251 //    CkPrintf("TREE pe %d No rem children\n",pe);
00252   }
00253   if (*num_children == 0)
00254     *children = 0;
00255   else {
00256     *children = new int[*num_children];
00257 //    CkPrintf("TREE pe %d children %d\n",pe,*num_children);
00258     int k;
00259     int child=0;
00260     if (loc_children > 0) {
00261       for(k=first_loc_child_index; k <= last_loc_child_index; k++) {
00262 //        CkPrintf("TREE pe %d loc child[%d,%d] %d\n",pe,child,k,node_pes[k]);
00263         (*children)[child++]=node_pes[k];
00264       }
00265     }
00266     if (rem_children > 0) {
00267       for(k=0; k < rem_children; k++)  {
00268 //        CkPrintf("TREE pe %d rem child[%d,%d] %d\n",pe,child,k,node_ids[rem_child_index[k]]);
00269         (*children)[child++]=node_ids[rem_child_index[k]];
00270       }
00271     }
00272   }
00273   delete [] rem_child_index;
00274   delete [] node_ids;
00275   delete [] node_pes;
00276 }

static ReductionMgr* ReductionMgr::Object ( void   )  [inline, static]

Definition at line 278 of file ReductionMgr.h.

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< AnisoElem, aniso, aniso >::ComputeHomeTuples(), ComputeLCPO::ComputeLCPO(), ComputeMsm::ComputeMsm(), ComputeMsmSerial::ComputeMsmSerial(), ComputeNonbondedPair::ComputeNonbondedPair(), ComputeNonbondedSelf::ComputeNonbondedSelf(), ComputeQM::ComputeQM(), ComputeRestraints::ComputeRestraints(), ComputeSphericalBC::ComputeSphericalBC(), ComputeStir::ComputeStir(), ComputeTclBC::ComputeTclBC(), Controller::Controller(), OptPmeXPencil::fft_init(), GlobalMasterEasy::GlobalMasterEasy(), GlobalMasterTcl::GlobalMasterTcl(), OptPmeMgr::initialize(), CudaComputeNonbonded::initialize(), ComputePmeMgr::initialize_computes(), OptPmeCompute::OptPmeCompute(), Patch::Patch(), PmePencilXYZ::PmePencilXYZ(), PmePencilZ::PmePencilZ(), PressureProfileReduction::PressureProfileReduction(), and Sequencer::Sequencer().

00278                                            {
00279     return CkpvAccess(ReductionMgr_instance);
00280   }

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.

00413                                                            {
00414 
00415   int setID = msg->reductionSetID;
00416   int size = msg->dataSize;
00417   ReductionSet *set = getSet(setID,size);
00418   if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
00419     NAMD_die("ReductionMgr::remoteRegister called while reductions outstanding on parent!");
00420   }
00421 
00422   set->submitsRegistered++;
00423   set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)]
00424                                         = set->nextSequenceNumber;
00425 //  CkPrintf("[%d] reduction register received from node[%d] %d\n",
00426 //    CkMyPe(),childIndex(msg->sourceNode),msg->sourceNode);
00427     
00428   delete msg;
00429 }

void ReductionMgr::remoteSubmit ( ReductionSubmitMsg msg  ) 

Definition at line 447 of file ReductionMgr.C.

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

00447                                                        {
00448   int setID = msg->reductionSetID;
00449   ReductionSet *set = reductionSets[setID];
00450   int seqNum = msg->sequenceNumber
00451         + set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)];
00452 
00453 //iout << "seq " << seqNum << " from " << msg->sourceNode << " received on " << CkMyPe() << "\n" << endi;
00454   int size = msg->dataSize;
00455   if ( size != set->dataSize ) {
00456     NAMD_bug("ReductionMgr::remoteSubmit data sizes do not match.");
00457   }
00458 
00459   BigReal *newData = msg->data;
00460   ReductionSetData *data = set->getData(seqNum);
00461   BigReal *curData = data->data;
00462 #ifdef ARCH_POWERPC
00463 #pragma disjoint (*curData,  *newData)
00464 #pragma unroll(4)
00465 #endif
00466   if ( setID == REDUCTIONS_MINIMIZER ) {
00467     for ( int i = 0; i < size; ++i ) {
00468       if ( newData[i] > curData[i] ) {
00469         curData[i] = newData[i];
00470       }
00471     }
00472   } else {
00473     for ( int i = 0; i < size; ++i ) {
00474       curData[i] += newData[i];
00475     }
00476   }
00477 //  CkPrintf("[%d] reduction Submit received from node[%d] %d\n",
00478 //    CkMyPe(),childIndex(msg->sourceNode),msg->sourceNode);
00479   delete msg;
00480 
00481   data->submitsRecorded++;
00482   if ( data->submitsRecorded == set->submitsRegistered ) {
00483     mergeAndDeliver(set,seqNum);
00484   }
00485 }

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.

00432                                                              {
00433 
00434   int setID = msg->reductionSetID;
00435   ReductionSet *set = reductionSets[setID];
00436   if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
00437     NAMD_die("SubmitReduction deleted while reductions outstanding on parent!");
00438   }
00439 
00440   set->submitsRegistered--;
00441 
00442   delSet(setID);
00443   delete msg;
00444 }

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

Definition at line 526 of file ReductionMgr.C.

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

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

00526                                                                {
00527   ReductionSet *set = getSet(setID,size);
00528   set->requireRegistered++;
00529   if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
00530     NAMD_die("ReductionMgr::willRequire called while reductions outstanding!");
00531   }
00532 
00533   RequireReduction *handle = new RequireReduction;
00534   handle->reductionSetID = setID;
00535   handle->sequenceNumber = set->nextSequenceNumber;
00536   handle->master = this;
00537 
00538   return handle;
00539 }

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

Definition at line 365 of file ReductionMgr.C.

References ReductionSetData::data, SubmitReduction::data, ReductionSet::getData(), SubmitReduction::master, NAMD_die(), ReductionSet::nextSequenceNumber, SubmitReduction::reductionSetID, SubmitReduction::sequenceNumber, 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< AnisoElem, aniso, aniso >::ComputeHomeTuples(), ComputeLCPO::ComputeLCPO(), ComputeMsm::ComputeMsm(), ComputeMsmSerial::ComputeMsmSerial(), ComputeNonbondedPair::ComputeNonbondedPair(), ComputeNonbondedSelf::ComputeNonbondedSelf(), ComputeQM::ComputeQM(), ComputeRestraints::ComputeRestraints(), ComputeSphericalBC::ComputeSphericalBC(), ComputeStir::ComputeStir(), ComputeTclBC::ComputeTclBC(), Controller::Controller(), OptPmeXPencil::fft_init(), GlobalMasterEasy::GlobalMasterEasy(), GlobalMasterTcl::GlobalMasterTcl(), OptPmeMgr::initialize(), CudaComputeNonbonded::initialize(), ComputePmeMgr::initialize_computes(), OptPmeCompute::OptPmeCompute(), Patch::Patch(), PmePencilXYZ::PmePencilXYZ(), PmePencilZ::PmePencilZ(), and Sequencer::Sequencer().

00365                                                              {
00366   ReductionSet *set = getSet(setID, size);
00367   ReductionSetData *data = set->getData(set->nextSequenceNumber);
00368   if ( data->submitsRecorded ) {
00369     NAMD_die("ReductionMgr::willSubmit called while reductions outstanding!");
00370   }
00371 
00372   set->submitsRegistered++;
00373 
00374   SubmitReduction *handle = new SubmitReduction;
00375   handle->reductionSetID = setID;
00376   handle->sequenceNumber = set->nextSequenceNumber;
00377   handle->master = this;
00378   handle->data = data->data;
00379 
00380   return handle;
00381 }


Friends And Related Function Documentation

friend class RequireReduction [friend]

Definition at line 237 of file ReductionMgr.h.

friend class SubmitReduction [friend]

Definition at line 236 of file ReductionMgr.h.


The documentation for this class was generated from the following files:
Generated on Mon Sep 25 01:17:20 2017 for NAMD by  doxygen 1.4.7