Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ReductionMgr Class Reference

#include <ReductionMgr.h>

Inheritance diagram for ReductionMgr:

BOCclass 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

ReductionMgrObject (void)

Friends

class SubmitReduction
class RequireReduction

Constructor & Destructor Documentation

ReductionMgr::ReductionMgr  ) 
 

Definition at line 291 of file ReductionMgr.C.

References buildSpanTree(), DebugM, and REDUCTION_MAX_CHILDREN.

00291                            {
00292     if (CkpvAccess(ReductionMgr_instance) == 0) {
00293       CkpvAccess(ReductionMgr_instance) = this;
00294     } else {
00295       DebugM(1, "ReductionMgr::ReductionMgr() - another instance exists!\n");
00296     }
00297     
00298     buildSpanTree(CkMyPe(),REDUCTION_MAX_CHILDREN,REDUCTION_MAX_CHILDREN,
00299                   &myParent,&numChildren,&children);
00300     
00301 //    CkPrintf("TREE [%d] parent %d %d children\n",
00302 //      CkMyPe(),myParent,numChildren);
00303 //    if (numChildren > 0) {
00304 //      for(int i=0; i < numChildren; i++)  {
00305 //        CkPrintf("TREE [%d] child %d %d\n",CkMyPe(),i,children[i]);
00306 //      }
00307 //    }
00308     
00309     // fill in the spanning tree fields
00310 #if 0  // Old spanning tree
00311     if (CkMyPe() == 0) {
00312       myParent = -1;
00313     } else {
00314       myParent = (CkMyPe()-1)/REDUCTION_MAX_CHILDREN;
00315     }
00316     firstChild = CkMyPe()*REDUCTION_MAX_CHILDREN + 1;
00317     if (firstChild > CkNumPes()) firstChild = CkNumPes();
00318     lastChild = firstChild + REDUCTION_MAX_CHILDREN;
00319     if (lastChild > CkNumPes()) lastChild = CkNumPes();
00320 #endif
00321 
00322     // initialize data
00323     for(int i=0; i<REDUCTION_MAX_SET_ID; i++) {
00324       reductionSets[i] = 0;
00325     }
00326 
00327     DebugM(1,"ReductionMgr() instantiated.\n");
00328 }

ReductionMgr::~ReductionMgr  ) 
 

Definition at line 331 of file ReductionMgr.C.

00331                             {
00332     if (children != 0)
00333       delete [] children;
00334     for(int i=0; i<REDUCTION_MAX_SET_ID; i++) {
00335       delete reductionSets[i];
00336     }
00337 
00338 }


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

References CmiGetFirstPeOnPhysicalNode, CmiNumPesOnPhysicalNode, CmiPeOnSamePhysicalNode, CmiPhysicalNodeID, and NAMD_die().

Referenced by ReductionMgr().

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

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

Definition at line 250 of file ReductionMgr.h.

Referenced by ComputeConsForce::ComputeConsForce(), ComputeConsTorque::ComputeConsTorque(), ComputeCylindricalBC::ComputeCylindricalBC(), ComputeEField::ComputeEField(), ComputeEwald::ComputeEwald(), ComputeExt::ComputeExt(), ComputeFullDirect::ComputeFullDirect(), ComputeGlobal::ComputeGlobal(), ComputeGridForce::ComputeGridForce(), ComputeHomeTuples< ExclElem, Exclusion, int >::ComputeHomeTuples(), ComputeNonbondedPair::ComputeNonbondedPair(), ComputeNonbondedSelf::ComputeNonbondedSelf(), ComputePme::ComputePme(), ComputeRestraints::ComputeRestraints(), ComputeSphericalBC::ComputeSphericalBC(), ComputeStir::ComputeStir(), ComputeTclBC::ComputeTclBC(), Controller::Controller(), GlobalMasterEasy::GlobalMasterEasy(), GlobalMasterTcl::GlobalMasterTcl(), OptPmeMgr::initialize(), OptPmeCompute::OptPmeCompute(), PressureProfileReduction::PressureProfileReduction(), ComputeNonbondedCUDA::requirePatch(), and Sequencer::Sequencer().

00250                                            {
00251     return CkpvAccess(ReductionMgr_instance);
00252   }

void ReductionMgr::remoteRegister ReductionRegisterMsg msg  ) 
 

Definition at line 421 of file ReductionMgr.C.

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

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

void ReductionMgr::remoteSubmit ReductionSubmitMsg msg  ) 
 

Definition at line 455 of file ReductionMgr.C.

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

00455                                                        {
00456   int setID = msg->reductionSetID;
00457   ReductionSet *set = reductionSets[setID];
00458   int seqNum = msg->sequenceNumber
00459         + set->addToRemoteSequenceNumber[childIndex(msg->sourceNode)];
00460 
00461 //iout << "seq " << seqNum << " from " << msg->sourceNode << " received on " << CkMyPe() << "\n" << endi;
00462   int size = msg->dataSize;
00463   if ( size != set->dataSize ) {
00464     NAMD_bug("ReductionMgr::remoteSubmit data sizes do not match.");
00465   }
00466 
00467   BigReal *newData = msg->data;
00468   ReductionSetData *data = set->getData(seqNum);
00469   BigReal *curData = data->data;
00470 #ifdef ARCH_POWERPC
00471 #pragma disjoint (*curData,  *newData)
00472 #pragma unroll(4)
00473 #endif
00474   for ( int i = 0; i < size; ++i ) {
00475     curData[i] += newData[i];
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 440 of file ReductionMgr.C.

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

00440                                                              {
00441 
00442   int setID = msg->reductionSetID;
00443   ReductionSet *set = reductionSets[setID];
00444   if ( set->getData(set->nextSequenceNumber)->submitsRecorded ) {
00445     NAMD_die("SubmitReduction deleted while reductions outstanding on parent!");
00446   }
00447 
00448   set->submitsRegistered--;
00449 
00450   delSet(setID);
00451   delete msg;
00452 }

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

Definition at line 527 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().

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

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

Definition at line 373 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 ComputeConsForce::ComputeConsForce(), ComputeConsTorque::ComputeConsTorque(), ComputeCylindricalBC::ComputeCylindricalBC(), ComputeEField::ComputeEField(), ComputeEwald::ComputeEwald(), ComputeExt::ComputeExt(), ComputeFullDirect::ComputeFullDirect(), ComputeGlobal::ComputeGlobal(), ComputeGridForce::ComputeGridForce(), ComputeHomeTuples< ExclElem, Exclusion, int >::ComputeHomeTuples(), ComputeNonbondedPair::ComputeNonbondedPair(), ComputeNonbondedSelf::ComputeNonbondedSelf(), ComputePme::ComputePme(), ComputeRestraints::ComputeRestraints(), ComputeSphericalBC::ComputeSphericalBC(), ComputeStir::ComputeStir(), ComputeTclBC::ComputeTclBC(), GlobalMasterEasy::GlobalMasterEasy(), GlobalMasterTcl::GlobalMasterTcl(), OptPmeMgr::initialize(), OptPmeCompute::OptPmeCompute(), ComputeNonbondedCUDA::requirePatch(), and Sequencer::Sequencer().

00373                                                              {
00374   ReductionSet *set = getSet(setID, size);
00375   ReductionSetData *data = set->getData(set->nextSequenceNumber);
00376   if ( data->submitsRecorded ) {
00377     NAMD_die("ReductionMgr::willSubmit called while reductions outstanding!");
00378   }
00379 
00380   set->submitsRegistered++;
00381 
00382   SubmitReduction *handle = new SubmitReduction;
00383   handle->reductionSetID = setID;
00384   handle->sequenceNumber = set->nextSequenceNumber;
00385   handle->master = this;
00386   handle->data = data->data;
00387 
00388   return handle;
00389 }


Friends And Related Function Documentation

friend class RequireReduction [friend]
 

Definition at line 209 of file ReductionMgr.h.

friend class SubmitReduction [friend]
 

Definition at line 208 of file ReductionMgr.h.


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 05:00:09 2009 for NAMD by  doxygen 1.3.9.1