NAMD
CollectionMgr.h
Go to the documentation of this file.
1 
7 #ifndef COLLECTIONMGR_H
8 #define COLLECTIONMGR_H
9 
10 #include "charm++.h"
11 
12 #include "main.h"
13 #include "NamdTypes.h"
14 #include "BOCgroup.h"
15 #include "PatchMap.h"
16 #include "ProcessorPrivate.h"
17 #include "CollectionMgr.decl.h"
18 
19 
20 class SlaveInitMsg : public CMessage_SlaveInitMsg
21 {
22 public:
23  CkChareID master;
24 };
25 
26 class CollectionMgr : public CBase_CollectionMgr
27 {
28 public:
29 
30  static CollectionMgr *Object() {
31  return CkpvAccess(CollectionMgr_instance);
32  }
34  ~CollectionMgr(void);
35 
36 
37 #ifndef MEM_OPT_VERSION
38  void submitPositions(int seq, FullAtomList &a, Lattice l, int prec,
39  int dcdSelectionIndex);
40 #else
41  void submitPositions(int seq, FullAtomList &a, Lattice l, int prec);
42 #endif
43  void submitVelocities(int seq, int zero, FullAtomList &a);
44  void submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f);
45  void sendDataStream(const char *);
46 
47  CkChareID getMasterChareID() { return master; }
48 
50  {
51  public:
52 
53  CollectVectorInstance(void) : seq(-10) { ; }
54 
55  void free() { seq = -10; }
56  int notfree() { return ( seq != -10 ); }
57 
58  void reset(int s, int p) {
59  if ( s == -10 ) NAMD_bug("seq == free in CollectionMgr");
60  seq = s;
61  precisions = p;
62  remaining = PatchMap::Object()->numHomePatches();
63  aid.resize(0);
64 #ifdef MEM_OPT_VERSION
65  outRank.resize(0);
66 #endif
67  data.resize(0);
68  fdata.resize(0);
69  }
70 
71  // true -> send it and delete it!
72 #ifdef MEM_OPT_VERSION
74 #else
76 #endif
77  {
78  int size = a.size();
79  for( int i = 0; i < size; ++i )
80  {
81  aid.add(a[i]);
82 #ifdef MEM_OPT_VERSION
83  outRank.add(oRank[i]);
84 #endif
85  if ( precisions & 2 ) data.add(d[i]);
86  if ( precisions & 1 || precisions & 4) fdata.add(d[i]);
87  }
88  return ( ! --remaining );
89  }
90 
91  int seq;
93 #ifdef MEM_OPT_VERSION
94  //record the dest output proc rank the atom goes to
95  ResizeArray<int> outRank;
96 #endif
100 
101  private:
102  int remaining;
103 
104  };
105 
107  {
108  public:
109 #ifdef MEM_OPT_VERSION
111  ResizeArray<Vector> &d, int prec=2)
112 #else
114  ResizeArray<Vector> &d, int prec=2)
115 #endif
116  {
117  CollectVectorInstance **c = data.begin();
118  CollectVectorInstance **c_e = data.end();
119  for( ; c != c_e && (*c)->seq != seq; ++c );
120  if ( c == c_e )
121  {
122  c = data.begin();
123  for( ; c != c_e && (*c)->notfree(); ++c );
124  if ( c == c_e ) {
125  data.add(new CollectVectorInstance);
126  c = data.end() - 1;
127  }
128  (*c)->reset(seq,prec);
129  }
130 #ifdef MEM_OPT_VERSION
131  if ( (*c)->append(i, oRank, d) )
132 #else
133  if ( (*c)->append(i,d) )
134 #endif
135  {
136  return *c;
137  }
138  else
139  {
140  return 0;
141  }
142  }
144 
145  };
146 private:
147 
148  CkChareID master;
149 
150  CollectVectorSequence positions;
151  CollectVectorSequence velocities;
152  CollectVectorSequence forces;
153 
154 };
155 
156 #endif
157 
static CollectionMgr * Object()
Definition: CollectionMgr.h:30
CkChareID master
Definition: CollectionMgr.h:23
int size(void) const
Definition: ResizeArray.h:131
static PatchMap * Object()
Definition: PatchMap.h:27
void submitVelocities(int seq, int zero, FullAtomList &a)
int add(const Elem &elem)
Definition: ResizeArray.h:101
CollectVectorInstance * submitData(int seq, AtomIDList &i, ResizeArray< Vector > &d, int prec=2)
void resize(int i)
Definition: ResizeArray.h:84
int append(AtomIDList &a, ResizeArray< Vector > &d)
Definition: CollectionMgr.h:75
CkChareID getMasterChareID()
Definition: CollectionMgr.h:47
void NAMD_bug(const char *err_msg)
Definition: common.C:195
ResizeArray< CollectVectorInstance * > data
~CollectionMgr(void)
Definition: CollectionMgr.C:33
void submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f)
int numHomePatches(void)
Definition: PatchMap.C:432
void submitPositions(int seq, FullAtomList &a, Lattice l, int prec, int dcdSelectionIndex)
ResizeArray< FloatVector > fdata
Definition: CollectionMgr.h:99
CollectionMgr(SlaveInitMsg *msg)
Definition: CollectionMgr.C:22
void sendDataStream(const char *)