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