CollectionMgr.C

Go to the documentation of this file.
00001 
00007 #include "CollectionMgr.decl.h"
00008 #include "CollectionMgr.h"
00009 #include "CollectionMaster.decl.h"
00010 #include "CollectionMaster.h"
00011 #include "Node.h"
00012 #include "SimParameters.h"
00013 
00014 #include "ParallelIOMgr.decl.h"
00015 #include "ParallelIOMgr.h"
00016 
00017 //#define DEBUGM
00018 #include "Debug.h"
00019 
00020 CollectionMgr::CollectionMgr(SlaveInitMsg *msg) : master(msg->master)
00021 {
00022   delete msg;
00023   if (CkpvAccess(CollectionMgr_instance) == 0) {
00024     CkpvAccess(CollectionMgr_instance) = this;
00025   } else {
00026     DebugM(1, "CollectionMgr::CollectionMgr() - another instance of CollectionMgr exists!\n");
00027   }
00028 }
00029 
00030 
00031 CollectionMgr::~CollectionMgr(void)
00032 {
00033 }
00034 
00035 #ifdef MEM_OPT_VERSION
00036 //1. record the dest output rank of each atom
00037 //2. distribute the atoms to the corresponding output procs
00038 //1 and 2 are both needed for positions and velocities
00039 
00040 void CollectionMgr::submitPositions(int seq, FullAtomList &a,
00041                                 Lattice l, int prec)
00042 {
00043   int numAtoms = a.size();
00044   AtomIDList aid(numAtoms);
00045   ResizeArray<int> oRank(numAtoms);
00046   PositionList d(numAtoms);
00047   for ( int i=0; i<numAtoms; ++i ) {
00048     aid[i] = a[i].id;
00049     oRank[i] = a[i].outputRank;
00050     d[i] = l.reverse_transform(a[i].position,a[i].transform);
00051   }
00052   CollectVectorInstance *c;
00053   if ( ( c = positions.submitData(seq,aid,oRank,d,prec) ) )
00054   {    
00055     CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
00056     ParallelIOMgr *ioMgr = io.ckLocalBranch();
00057 
00058     //construct per output proc atoms list
00059     AtomIDList *perOList = new AtomIDList[ioMgr->numOutputProcs];
00060     for(int i=0; i<c->aid.size(); i++){
00061         perOList[c->outRank[i]].add(i);
00062     }    
00063     CollectVectorVarMsg::DataStatus vstatus;
00064     if(c->data.size()==0){
00065         vstatus = CollectVectorVarMsg::FloatVectorValid;
00066     }else if(c->fdata.size()==0){
00067         vstatus = CollectVectorVarMsg::VectorValid;
00068     }else{
00069         vstatus = CollectVectorVarMsg::BothValid;
00070     }
00071     //send msg to output proc if there's one    
00072     for(int i=0; i<ioMgr->numOutputProcs; i++){
00073         int numAtoms = perOList[i].size();
00074         if(!numAtoms) continue;
00075         CollectVectorVarMsg *msg;
00076         if( vstatus == CollectVectorVarMsg::VectorValid){
00077             msg = new(numAtoms, numAtoms, 0, 0)CollectVectorVarMsg;
00078             for(int j=0; j<numAtoms; j++){
00079                 int lIdx = perOList[i][j];
00080                 msg->aid[j] = c->aid[lIdx];
00081                 msg->data[j] = c->data[lIdx];
00082             }
00083         }else if(vstatus == CollectVectorVarMsg::FloatVectorValid){
00084             msg = new(numAtoms, 0, numAtoms, 0)CollectVectorVarMsg;
00085             for(int j=0; j<numAtoms; j++){
00086                 int lIdx = perOList[i][j];
00087                 msg->aid[j] = c->aid[lIdx];
00088                 msg->fdata[j] = c->fdata[lIdx];
00089             }
00090         }else{
00091             msg = new(numAtoms, numAtoms, numAtoms, 0)CollectVectorVarMsg;
00092             for(int j=0; j<numAtoms; j++){
00093                 int lIdx = perOList[i][j];
00094                 msg->aid[j] = c->aid[lIdx];
00095                 msg->data[j] = c->data[lIdx];
00096                 msg->fdata[j] = c->fdata[lIdx];
00097             }
00098         }
00099         msg->seq = c->seq;
00100         msg->size = numAtoms;
00101         msg->status = vstatus;
00102         io[ioMgr->outputProcArray[i]].receivePositions(msg);
00103     }
00104     c->free();
00105     delete [] perOList;
00106   }
00107 }
00108 
00109 void CollectionMgr::submitVelocities(int seq, int zero, FullAtomList &a)
00110 {
00111   int numAtoms = a.size();
00112   AtomIDList aid(numAtoms);
00113   ResizeArray<int> oRank(numAtoms);
00114   PositionList d(numAtoms);
00115   for ( int i=0; i<numAtoms; ++i ) {
00116     aid[i] = a[i].id;
00117     oRank[i] = a[i].outputRank;
00118     if ( zero ) d[i] = 0.;
00119     else d[i] = a[i].velocity;
00120   }
00121   CollectVectorInstance *c;
00122   if ( ( c = velocities.submitData(seq,aid,oRank,d) ) )
00123   {
00124       CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
00125       ParallelIOMgr *ioMgr = io.ckLocalBranch();
00126 
00127       //construct per output proc atoms list
00128       AtomIDList *perOList = new AtomIDList[ioMgr->numOutputProcs];
00129       for(int i=0; i<c->aid.size(); i++){
00130           perOList[c->outRank[i]].add(i);
00131       }    
00132       CollectVectorVarMsg::DataStatus vstatus = CollectVectorVarMsg::VectorValid;
00133       //send msg to output proc if there's one    
00134         for(int i=0; i<ioMgr->numOutputProcs; i++){
00135             int numAtoms = perOList[i].size();
00136             if(!numAtoms) continue;
00137             CollectVectorVarMsg *msg;            
00138             msg = new(numAtoms, numAtoms, 0, 0)CollectVectorVarMsg;
00139             msg->seq = c->seq;
00140             msg->size = numAtoms;
00141             msg->status = vstatus;
00142             for(int j=0; j<numAtoms; j++){
00143                 int lIdx = perOList[i][j];
00144                 msg->aid[j] = c->aid[lIdx];
00145                 msg->data[j] = c->data[lIdx];
00146             }
00147             io[ioMgr->outputProcArray[i]].receiveVelocities(msg);            
00148         }
00149         c->free();
00150         delete [] perOList;         
00151   }
00152 }
00153 
00154 void CollectionMgr::submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f)
00155 {
00156   int numAtoms = a.size();
00157   AtomIDList aid(numAtoms);
00158   ResizeArray<int> oRank(numAtoms);
00159   ForceList d(numAtoms);
00160   for ( int i=0; i<numAtoms; ++i ) {
00161     aid[i] = a[i].id;
00162     oRank[i] = a[i].outputRank;
00163     d[i] = 0.;
00164   }
00165   for ( int j=0; j<=maxForceUsed; ++j ) {
00166     Force *fptr = f[j].begin();
00167     for ( int i=0; i<numAtoms; ++i ) {
00168       d[i] += fptr[i];
00169     }
00170   }
00171   if ( Node::Object()->simParameters->fixedAtomsOn && !Node::Object()->simParameters->fixedAtomsForceOutput) {
00172     for ( int i=0; i<numAtoms; ++i ) {
00173       if ( a[i].atomFixed ) d[i] = 0.;
00174     }
00175   }
00176   CollectVectorInstance *c;
00177   if ( ( c = forces.submitData(seq,aid,oRank,d) ) )
00178   {
00179       CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
00180       ParallelIOMgr *ioMgr = io.ckLocalBranch();
00181 
00182       //construct per output proc atoms list
00183       AtomIDList *perOList = new AtomIDList[ioMgr->numOutputProcs];
00184       for(int i=0; i<c->aid.size(); i++){
00185           perOList[c->outRank[i]].add(i);
00186       }    
00187       CollectVectorVarMsg::DataStatus vstatus = CollectVectorVarMsg::VectorValid;
00188       //send msg to output proc if there's one    
00189         for(int i=0; i<ioMgr->numOutputProcs; i++){
00190             int numAtoms = perOList[i].size();
00191             if(!numAtoms) continue;
00192             CollectVectorVarMsg *msg;            
00193             msg = new(numAtoms, numAtoms, 0, 0)CollectVectorVarMsg;
00194             msg->seq = c->seq;
00195             msg->size = numAtoms;
00196             msg->status = vstatus;
00197             for(int j=0; j<numAtoms; j++){
00198                 int lIdx = perOList[i][j];
00199                 msg->aid[j] = c->aid[lIdx];
00200                 msg->data[j] = c->data[lIdx];
00201             }
00202             io[ioMgr->outputProcArray[i]].receiveForces(msg);            
00203         }
00204         c->free();
00205         delete [] perOList;         
00206   }
00207 }
00208 
00209 #else
00210 void CollectionMgr::submitPositions(int seq, FullAtomList &a,
00211                                 Lattice l, int prec)
00212 {  
00213   int numAtoms = a.size();
00214   AtomIDList aid(numAtoms);
00215   PositionList d(numAtoms);
00216   for ( int i=0; i<numAtoms; ++i ) {
00217     aid[i] = a[i].id;
00218     d[i] = l.reverse_transform(a[i].position,a[i].transform);
00219   }
00220   CollectVectorInstance *c;
00221   if ( ( c = positions.submitData(seq,aid,d,prec) ) )
00222   {
00223     int aid_size = c->aid.size();
00224     int data_size = c->data.size();
00225     int fdata_size = c->fdata.size();
00226     CollectVectorMsg *msg
00227       = new (aid_size, data_size, fdata_size,0) CollectVectorMsg;
00228     msg->seq = c->seq;
00229     msg->aid_size = aid_size;
00230     msg->data_size = data_size;
00231     msg->fdata_size = fdata_size;
00232     memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
00233     memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
00234     memcpy(msg->fdata,c->fdata.begin(),fdata_size*sizeof(FloatVector));
00235     CProxy_CollectionMaster cm(master);
00236     cm.receivePositions(msg);
00237     c->free();
00238   }
00239 }
00240 
00241 void CollectionMgr::submitVelocities(int seq, int zero, FullAtomList &a)
00242 {
00243   int numAtoms = a.size();
00244   AtomIDList aid(numAtoms);
00245   PositionList d(numAtoms);
00246   for ( int i=0; i<numAtoms; ++i ) {
00247     aid[i] = a[i].id;
00248     if ( zero ) d[i] = 0.;
00249     else d[i] = a[i].velocity;
00250   }
00251   CollectVectorInstance *c;
00252   if ( ( c = velocities.submitData(seq,aid,d) ) )
00253   {
00254     int aid_size = c->aid.size();
00255     int data_size = c->data.size();
00256     CollectVectorMsg *msg = new (aid_size, data_size, 0, 0) CollectVectorMsg;
00257     msg->seq = c->seq;
00258     msg->aid_size = aid_size;
00259     msg->data_size = data_size;
00260     msg->fdata_size = 0;
00261     memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
00262     memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
00263     CProxy_CollectionMaster cm(master);
00264     cm.receiveVelocities(msg);
00265     c->free();
00266   }
00267 }
00268  
00269 void CollectionMgr::submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f)
00270 {
00271   int numAtoms = a.size();
00272   AtomIDList aid(numAtoms);
00273   ForceList d(numAtoms);
00274   for ( int i=0; i<numAtoms; ++i ) {
00275     aid[i] = a[i].id;
00276     d[i] = 0.;
00277   }
00278   for ( int j=0; j<=maxForceUsed; ++j ) {
00279     Force *fptr = f[j].begin();
00280     for ( int i=0; i<numAtoms; ++i ) {
00281       d[i] += fptr[i];
00282     }
00283   }
00284   if ( Node::Object()->simParameters->fixedAtomsOn && !Node::Object()->simParameters->fixedAtomsForceOutput) {
00285     for ( int i=0; i<numAtoms; ++i ) {
00286       if ( a[i].atomFixed ) d[i] = 0.;
00287     }
00288   }
00289   CollectVectorInstance *c;
00290   if ( ( c = forces.submitData(seq,aid,d) ) )
00291   {
00292     int aid_size = c->aid.size();
00293     int data_size = c->data.size();
00294     CollectVectorMsg *msg = new (aid_size, data_size, 0, 0) CollectVectorMsg;
00295     msg->seq = c->seq;
00296     msg->aid_size = aid_size;
00297     msg->data_size = data_size;
00298     msg->fdata_size = 0;
00299     memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
00300     memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
00301     CProxy_CollectionMaster cm(master);
00302     cm.receiveForces(msg);
00303     c->free();
00304   }
00305 }
00306 #endif
00307 
00308 void CollectionMgr::sendDataStream(const char *data) {
00309   DataStreamMsg *msg = new DataStreamMsg;
00310   msg->data.resize(strlen(data)+1);
00311   strcpy(msg->data.begin(),data);
00312   CProxy_CollectionMaster cm(master);
00313   cm.receiveDataStream(msg);
00314 }
00315 
00316 #include "CollectionMgr.def.h"
00317 

Generated on Mon Nov 20 01:17:10 2017 for NAMD by  doxygen 1.4.7