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

CollectionMgr.h

Go to the documentation of this file.
00001 
00007 #ifndef COLLECTIONMGR_H
00008 #define COLLECTIONMGR_H
00009 
00010 #include "charm++.h"
00011 
00012 #include "main.h"
00013 #include "NamdTypes.h"
00014 #include "BOCgroup.h"
00015 #include "PatchMap.h"
00016 #include "ProcessorPrivate.h"
00017 #include "CollectionMgr.decl.h"
00018 
00019 
00020 class SlaveInitMsg : public CMessage_SlaveInitMsg
00021 {
00022 public:
00023   CkChareID master;
00024 };
00025 
00026 class CollectionMgr : public BOCclass
00027 {
00028 public:
00029 
00030   static CollectionMgr *Object() { 
00031     return CkpvAccess(CollectionMgr_instance); 
00032   }
00033   CollectionMgr(SlaveInitMsg *msg);
00034   ~CollectionMgr(void);
00035 
00036   void submitPositions(int seq, FullAtomList &a, Lattice l, int prec);
00037   void submitVelocities(int seq, int zero, FullAtomList &a);
00038   void sendDataStream(const char *);
00039 
00040   class CollectVectorInstance
00041   {
00042   public:
00043 
00044     CollectVectorInstance(void) : seq(-10) { ; }
00045 
00046     void free() { seq = -10; }
00047     int notfree() { return ( seq != -10 ); }
00048 
00049     void reset(int s, int p) {
00050       if ( s == -10 ) NAMD_bug("seq == free in CollectionMgr");
00051       seq = s;
00052       precisions = p;
00053       remaining = PatchMap::Object()->numHomePatches();
00054       aid.resize(0);
00055       data.resize(0);
00056       fdata.resize(0);
00057     }
00058 
00059     // true -> send it and delete it!
00060     int append(AtomIDList &a, ResizeArray<Vector> &d)
00061     {
00062       int size = a.size();
00063       for( int i = 0; i < size; ++i )
00064       {
00065         aid.add(a[i]);
00066         if ( precisions & 2 ) data.add(d[i]);
00067         if ( precisions & 1 ) fdata.add(d[i]);
00068       }
00069       return ( ! --remaining );
00070     }
00071 
00072     int seq;
00073     AtomIDList aid;
00074     int precisions;
00075     ResizeArray<Vector> data;
00076     ResizeArray<FloatVector> fdata;
00077 
00078   private:
00079     int remaining;
00080 
00081   };
00082 
00083   class CollectVectorSequence
00084   {
00085   public:
00086 
00087     CollectVectorInstance* submitData(
00088         int seq, AtomIDList &i, ResizeArray<Vector> &d, int prec=2)
00089     {
00090       CollectVectorInstance **c = data.begin();
00091       CollectVectorInstance **c_e = data.end();
00092       for( ; c != c_e && (*c)->seq != seq; ++c );
00093       if ( c == c_e )
00094       {
00095        c = data.begin();
00096        for( ; c != c_e && (*c)->notfree(); ++c );
00097        if ( c == c_e ) {
00098         data.add(new CollectVectorInstance);
00099         c = data.end() - 1;
00100        }
00101        (*c)->reset(seq,prec);
00102       }
00103       if ( (*c)->append(i,d) )
00104       {
00105         return *c;
00106       }
00107       else
00108       {
00109         return 0;
00110       }
00111     }
00112 
00113     ResizeArray<CollectVectorInstance*> data;
00114 
00115   };
00116 private:
00117 
00118   CkChareID master;
00119 
00120 
00121   CollectVectorSequence positions;
00122   CollectVectorSequence velocities;
00123 
00124 public:
00125   void setCollectionMaster(SlaveInitMsg *msg){ 
00126     master = msg->master; 
00127     delete msg;
00128   }
00129 };
00130 
00131 #endif
00132 

Generated on Sun Nov 8 04:07:15 2009 for NAMD by  doxygen 1.3.9.1