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 submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f);
00039 void sendDataStream(const char *);
00040
00041 CkChareID getMasterChareID() { return master; }
00042
00043 class CollectVectorInstance
00044 {
00045 public:
00046
00047 CollectVectorInstance(void) : seq(-10) { ; }
00048
00049 void free() { seq = -10; }
00050 int notfree() { return ( seq != -10 ); }
00051
00052 void reset(int s, int p) {
00053 if ( s == -10 ) NAMD_bug("seq == free in CollectionMgr");
00054 seq = s;
00055 precisions = p;
00056 remaining = PatchMap::Object()->numHomePatches();
00057 aid.resize(0);
00058 #ifdef MEM_OPT_VERSION
00059 outRank.resize(0);
00060 #endif
00061 data.resize(0);
00062 fdata.resize(0);
00063 }
00064
00065
00066 #ifdef MEM_OPT_VERSION
00067 int append(AtomIDList &a, ResizeArray<int> &oRank, ResizeArray<Vector> &d)
00068 #else
00069 int append(AtomIDList &a, ResizeArray<Vector> &d)
00070 #endif
00071 {
00072 int size = a.size();
00073 for( int i = 0; i < size; ++i )
00074 {
00075 aid.add(a[i]);
00076 #ifdef MEM_OPT_VERSION
00077 outRank.add(oRank[i]);
00078 #endif
00079 if ( precisions & 2 ) data.add(d[i]);
00080 if ( precisions & 1 ) fdata.add(d[i]);
00081 }
00082 return ( ! --remaining );
00083 }
00084
00085 int seq;
00086 AtomIDList aid;
00087 #ifdef MEM_OPT_VERSION
00088
00089 ResizeArray<int> outRank;
00090 #endif
00091 int precisions;
00092 ResizeArray<Vector> data;
00093 ResizeArray<FloatVector> fdata;
00094
00095 private:
00096 int remaining;
00097
00098 };
00099
00100 class CollectVectorSequence
00101 {
00102 public:
00103 #ifdef MEM_OPT_VERSION
00104 CollectVectorInstance* submitData(int seq, AtomIDList &i, ResizeArray<int> &oRank,
00105 ResizeArray<Vector> &d, int prec=2)
00106 #else
00107 CollectVectorInstance* submitData(int seq, AtomIDList &i,
00108 ResizeArray<Vector> &d, int prec=2)
00109 #endif
00110 {
00111 CollectVectorInstance **c = data.begin();
00112 CollectVectorInstance **c_e = data.end();
00113 for( ; c != c_e && (*c)->seq != seq; ++c );
00114 if ( c == c_e )
00115 {
00116 c = data.begin();
00117 for( ; c != c_e && (*c)->notfree(); ++c );
00118 if ( c == c_e ) {
00119 data.add(new CollectVectorInstance);
00120 c = data.end() - 1;
00121 }
00122 (*c)->reset(seq,prec);
00123 }
00124 #ifdef MEM_OPT_VERSION
00125 if ( (*c)->append(i, oRank, d) )
00126 #else
00127 if ( (*c)->append(i,d) )
00128 #endif
00129 {
00130 return *c;
00131 }
00132 else
00133 {
00134 return 0;
00135 }
00136 }
00137
00138 ResizeArray<CollectVectorInstance*> data;
00139
00140 };
00141 private:
00142
00143 CkChareID master;
00144
00145 CollectVectorSequence positions;
00146 CollectVectorSequence velocities;
00147 CollectVectorSequence forces;
00148
00149 };
00150
00151 #endif
00152