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  void submitPositions(int seq, FullAtomList &a, Lattice l, int prec);
37  void submitVelocities(int seq, int zero, FullAtomList &a);
38  void submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f);
39  void sendDataStream(const char *);
40 
41  CkChareID getMasterChareID() { return master; }
42 
44  {
45  public:
46 
47  CollectVectorInstance(void) : seq(-10) { ; }
48 
49  void free() { seq = -10; }
50  int notfree() { return ( seq != -10 ); }
51 
52  void reset(int s, int p) {
53  if ( s == -10 ) NAMD_bug("seq == free in CollectionMgr");
54  seq = s;
55  precisions = p;
56  remaining = PatchMap::Object()->numHomePatches();
57  aid.resize(0);
58 #ifdef MEM_OPT_VERSION
59  outRank.resize(0);
60 #endif
61  data.resize(0);
62  fdata.resize(0);
63  }
64 
65  // true -> send it and delete it!
66 #ifdef MEM_OPT_VERSION
68 #else
70 #endif
71  {
72  int size = a.size();
73  for( int i = 0; i < size; ++i )
74  {
75  aid.add(a[i]);
76 #ifdef MEM_OPT_VERSION
77  outRank.add(oRank[i]);
78 #endif
79  if ( precisions & 2 ) data.add(d[i]);
80  if ( precisions & 1 ) fdata.add(d[i]);
81  }
82  return ( ! --remaining );
83  }
84 
85  int seq;
87 #ifdef MEM_OPT_VERSION
88  //record the dest output proc rank the atom goes to
89  ResizeArray<int> outRank;
90 #endif
94 
95  private:
96  int remaining;
97 
98  };
99 
101  {
102  public:
103 #ifdef MEM_OPT_VERSION
105  ResizeArray<Vector> &d, int prec=2)
106 #else
108  ResizeArray<Vector> &d, int prec=2)
109 #endif
110  {
111  CollectVectorInstance **c = data.begin();
112  CollectVectorInstance **c_e = data.end();
113  for( ; c != c_e && (*c)->seq != seq; ++c );
114  if ( c == c_e )
115  {
116  c = data.begin();
117  for( ; c != c_e && (*c)->notfree(); ++c );
118  if ( c == c_e ) {
119  data.add(new CollectVectorInstance);
120  c = data.end() - 1;
121  }
122  (*c)->reset(seq,prec);
123  }
124 #ifdef MEM_OPT_VERSION
125  if ( (*c)->append(i, oRank, d) )
126 #else
127  if ( (*c)->append(i,d) )
128 #endif
129  {
130  return *c;
131  }
132  else
133  {
134  return 0;
135  }
136  }
137 
139 
140  };
141 private:
142 
143  CkChareID master;
144 
145  CollectVectorSequence positions;
146  CollectVectorSequence velocities;
147  CollectVectorSequence forces;
148 
149 };
150 
151 #endif
152 
static CollectionMgr * Object()
Definition: CollectionMgr.h:30
CkChareID master
Definition: CollectionMgr.h:23
static PatchMap * Object()
Definition: PatchMap.h:27
void submitVelocities(int seq, int zero, FullAtomList &a)
CollectVectorInstance * submitData(int seq, AtomIDList &i, ResizeArray< Vector > &d, int prec=2)
int append(AtomIDList &a, ResizeArray< Vector > &d)
Definition: CollectionMgr.h:69
CkChareID getMasterChareID()
Definition: CollectionMgr.h:41
void NAMD_bug(const char *err_msg)
Definition: common.C:129
ResizeArray< CollectVectorInstance * > data
void submitPositions(int seq, FullAtomList &a, Lattice l, int prec)
~CollectionMgr(void)
Definition: CollectionMgr.C:31
void submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f)
int add(const Elem &elem)
Definition: ResizeArray.h:97
void resize(int i)
Definition: ResizeArray.h:84
int numHomePatches(void)
Definition: PatchMap.C:432
ResizeArray< FloatVector > fdata
Definition: CollectionMgr.h:93
CollectionMgr(SlaveInitMsg *msg)
Definition: CollectionMgr.C:20
int size(void) const
Definition: ResizeArray.h:127
void sendDataStream(const char *)