-
Notifications
You must be signed in to change notification settings - Fork 1
/
CollectionMgr.C
317 lines (298 loc) · 9.77 KB
/
CollectionMgr.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/**
*** Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
*** The Board of Trustees of the University of Illinois.
*** All rights reserved.
**/
#include "CollectionMgr.decl.h"
#include "CollectionMgr.h"
#include "CollectionMaster.decl.h"
#include "CollectionMaster.h"
#include "Node.h"
#include "SimParameters.h"
#include "ParallelIOMgr.decl.h"
#include "ParallelIOMgr.h"
//#define DEBUGM
#include "Debug.h"
CollectionMgr::CollectionMgr(SlaveInitMsg *msg) : master(msg->master)
{
delete msg;
if (CkpvAccess(CollectionMgr_instance) == 0) {
CkpvAccess(CollectionMgr_instance) = this;
} else {
DebugM(1, "CollectionMgr::CollectionMgr() - another instance of CollectionMgr exists!\n");
}
}
CollectionMgr::~CollectionMgr(void)
{
}
#ifdef MEM_OPT_VERSION
//1. record the dest output rank of each atom
//2. distribute the atoms to the corresponding output procs
//1 and 2 are both needed for positions and velocities
void CollectionMgr::submitPositions(int seq, FullAtomList &a,
Lattice l, int prec)
{
int numAtoms = a.size();
AtomIDList aid(numAtoms);
ResizeArray<int> oRank(numAtoms);
PositionList d(numAtoms);
for ( int i=0; i<numAtoms; ++i ) {
aid[i] = a[i].id;
oRank[i] = a[i].outputRank;
d[i] = l.reverse_transform(a[i].position,a[i].transform);
}
CollectVectorInstance *c;
if ( ( c = positions.submitData(seq,aid,oRank,d,prec) ) )
{
CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
ParallelIOMgr *ioMgr = io.ckLocalBranch();
//construct per output proc atoms list
AtomIDList *perOList = new AtomIDList[ioMgr->numOutputProcs];
for(int i=0; i<c->aid.size(); i++){
perOList[c->outRank[i]].add(i);
}
CollectVectorVarMsg::DataStatus vstatus;
if(c->data.size()==0){
vstatus = CollectVectorVarMsg::FloatVectorValid;
}else if(c->fdata.size()==0){
vstatus = CollectVectorVarMsg::VectorValid;
}else{
vstatus = CollectVectorVarMsg::BothValid;
}
//send msg to output proc if there's one
for(int i=0; i<ioMgr->numOutputProcs; i++){
int numAtoms = perOList[i].size();
if(!numAtoms) continue;
CollectVectorVarMsg *msg;
if( vstatus == CollectVectorVarMsg::VectorValid){
msg = new(numAtoms, numAtoms, 0, 0)CollectVectorVarMsg;
for(int j=0; j<numAtoms; j++){
int lIdx = perOList[i][j];
msg->aid[j] = c->aid[lIdx];
msg->data[j] = c->data[lIdx];
}
}else if(vstatus == CollectVectorVarMsg::FloatVectorValid){
msg = new(numAtoms, 0, numAtoms, 0)CollectVectorVarMsg;
for(int j=0; j<numAtoms; j++){
int lIdx = perOList[i][j];
msg->aid[j] = c->aid[lIdx];
msg->fdata[j] = c->fdata[lIdx];
}
}else{
msg = new(numAtoms, numAtoms, numAtoms, 0)CollectVectorVarMsg;
for(int j=0; j<numAtoms; j++){
int lIdx = perOList[i][j];
msg->aid[j] = c->aid[lIdx];
msg->data[j] = c->data[lIdx];
msg->fdata[j] = c->fdata[lIdx];
}
}
msg->seq = c->seq;
msg->size = numAtoms;
msg->status = vstatus;
io[ioMgr->outputProcArray[i]].receivePositions(msg);
}
c->free();
delete [] perOList;
}
}
void CollectionMgr::submitVelocities(int seq, int zero, FullAtomList &a)
{
int numAtoms = a.size();
AtomIDList aid(numAtoms);
ResizeArray<int> oRank(numAtoms);
PositionList d(numAtoms);
for ( int i=0; i<numAtoms; ++i ) {
aid[i] = a[i].id;
oRank[i] = a[i].outputRank;
if ( zero ) d[i] = 0.;
else d[i] = a[i].velocity;
}
CollectVectorInstance *c;
if ( ( c = velocities.submitData(seq,aid,oRank,d) ) )
{
CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
ParallelIOMgr *ioMgr = io.ckLocalBranch();
//construct per output proc atoms list
AtomIDList *perOList = new AtomIDList[ioMgr->numOutputProcs];
for(int i=0; i<c->aid.size(); i++){
perOList[c->outRank[i]].add(i);
}
CollectVectorVarMsg::DataStatus vstatus = CollectVectorVarMsg::VectorValid;
//send msg to output proc if there's one
for(int i=0; i<ioMgr->numOutputProcs; i++){
int numAtoms = perOList[i].size();
if(!numAtoms) continue;
CollectVectorVarMsg *msg;
msg = new(numAtoms, numAtoms, 0, 0)CollectVectorVarMsg;
msg->seq = c->seq;
msg->size = numAtoms;
msg->status = vstatus;
for(int j=0; j<numAtoms; j++){
int lIdx = perOList[i][j];
msg->aid[j] = c->aid[lIdx];
msg->data[j] = c->data[lIdx];
}
io[ioMgr->outputProcArray[i]].receiveVelocities(msg);
}
c->free();
delete [] perOList;
}
}
void CollectionMgr::submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f)
{
int numAtoms = a.size();
AtomIDList aid(numAtoms);
ResizeArray<int> oRank(numAtoms);
ForceList d(numAtoms);
for ( int i=0; i<numAtoms; ++i ) {
aid[i] = a[i].id;
oRank[i] = a[i].outputRank;
d[i] = 0.;
}
for ( int j=0; j<=maxForceUsed; ++j ) {
Force *fptr = f[j].begin();
for ( int i=0; i<numAtoms; ++i ) {
d[i] += fptr[i];
}
}
if ( Node::Object()->simParameters->fixedAtomsOn ) {
for ( int i=0; i<numAtoms; ++i ) {
if ( a[i].atomFixed ) d[i] = 0.;
}
}
CollectVectorInstance *c;
if ( ( c = forces.submitData(seq,aid,oRank,d) ) )
{
CProxy_ParallelIOMgr io(CkpvAccess(BOCclass_group).ioMgr);
ParallelIOMgr *ioMgr = io.ckLocalBranch();
//construct per output proc atoms list
AtomIDList *perOList = new AtomIDList[ioMgr->numOutputProcs];
for(int i=0; i<c->aid.size(); i++){
perOList[c->outRank[i]].add(i);
}
CollectVectorVarMsg::DataStatus vstatus = CollectVectorVarMsg::VectorValid;
//send msg to output proc if there's one
for(int i=0; i<ioMgr->numOutputProcs; i++){
int numAtoms = perOList[i].size();
if(!numAtoms) continue;
CollectVectorVarMsg *msg;
msg = new(numAtoms, numAtoms, 0, 0)CollectVectorVarMsg;
msg->seq = c->seq;
msg->size = numAtoms;
msg->status = vstatus;
for(int j=0; j<numAtoms; j++){
int lIdx = perOList[i][j];
msg->aid[j] = c->aid[lIdx];
msg->data[j] = c->data[lIdx];
}
io[ioMgr->outputProcArray[i]].receiveForces(msg);
}
c->free();
delete [] perOList;
}
}
#else
void CollectionMgr::submitPositions(int seq, FullAtomList &a,
Lattice l, int prec)
{
int numAtoms = a.size();
AtomIDList aid(numAtoms);
PositionList d(numAtoms);
for ( int i=0; i<numAtoms; ++i ) {
aid[i] = a[i].id;
d[i] = l.reverse_transform(a[i].position,a[i].transform);
}
CollectVectorInstance *c;
if ( ( c = positions.submitData(seq,aid,d,prec) ) )
{
int aid_size = c->aid.size();
int data_size = c->data.size();
int fdata_size = c->fdata.size();
CollectVectorMsg *msg
= new (aid_size, data_size, fdata_size,0) CollectVectorMsg;
msg->seq = c->seq;
msg->aid_size = aid_size;
msg->data_size = data_size;
msg->fdata_size = fdata_size;
memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
memcpy(msg->fdata,c->fdata.begin(),fdata_size*sizeof(FloatVector));
CProxy_CollectionMaster cm(master);
cm.receivePositions(msg);
c->free();
}
}
void CollectionMgr::submitVelocities(int seq, int zero, FullAtomList &a)
{
int numAtoms = a.size();
AtomIDList aid(numAtoms);
PositionList d(numAtoms);
for ( int i=0; i<numAtoms; ++i ) {
aid[i] = a[i].id;
if ( zero ) d[i] = 0.;
else d[i] = a[i].velocity;
}
CollectVectorInstance *c;
if ( ( c = velocities.submitData(seq,aid,d) ) )
{
int aid_size = c->aid.size();
int data_size = c->data.size();
CollectVectorMsg *msg = new (aid_size, data_size, 0, 0) CollectVectorMsg;
msg->seq = c->seq;
msg->aid_size = aid_size;
msg->data_size = data_size;
msg->fdata_size = 0;
memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
CProxy_CollectionMaster cm(master);
cm.receiveVelocities(msg);
c->free();
}
}
void CollectionMgr::submitForces(int seq, FullAtomList &a, int maxForceUsed, ForceList *f)
{
int numAtoms = a.size();
AtomIDList aid(numAtoms);
ForceList d(numAtoms);
for ( int i=0; i<numAtoms; ++i ) {
aid[i] = a[i].id;
d[i] = 0.;
}
for ( int j=0; j<=maxForceUsed; ++j ) {
Force *fptr = f[j].begin();
for ( int i=0; i<numAtoms; ++i ) {
d[i] += fptr[i];
}
}
if ( Node::Object()->simParameters->fixedAtomsOn ) {
for ( int i=0; i<numAtoms; ++i ) {
if ( a[i].atomFixed ) d[i] = 0.;
}
}
CollectVectorInstance *c;
if ( ( c = forces.submitData(seq,aid,d) ) )
{
int aid_size = c->aid.size();
int data_size = c->data.size();
CollectVectorMsg *msg = new (aid_size, data_size, 0, 0) CollectVectorMsg;
msg->seq = c->seq;
msg->aid_size = aid_size;
msg->data_size = data_size;
msg->fdata_size = 0;
memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
CProxy_CollectionMaster cm(master);
cm.receiveForces(msg);
c->free();
}
}
#endif
void CollectionMgr::sendDataStream(const char *data) {
DataStreamMsg *msg = new DataStreamMsg;
msg->data.resize(strlen(data)+1);
strcpy(msg->data.begin(),data);
CProxy_CollectionMaster cm(master);
cm.receiveDataStream(msg);
}
#include "CollectionMgr.def.h"