7 |
|
#include "utils/simError.h" |
8 |
|
|
9 |
|
|
10 |
< |
|
11 |
< |
ZConsWriter::ZConsWriter(const char* filename, std::vector<ZConsParaItem>* thePara) |
12 |
< |
{ |
10 |
> |
namespace oopse { |
11 |
> |
ZConsWriter::ZConsWriter(SimInfo* info, const std::string& filename) : info_(info) { |
12 |
|
//use master - slave mode, only master node writes to disk |
13 |
|
#ifdef IS_MPI |
14 |
< |
if(worldRank == 0){ |
14 |
> |
if(worldRank == 0){ |
15 |
|
#endif |
16 |
|
|
17 |
< |
output.open(filename); |
19 |
< |
|
20 |
< |
if(!output){ |
21 |
< |
sprintf( painCave.errMsg, |
22 |
< |
"Could not open %s for z constrain output \n", |
23 |
< |
filename); |
24 |
< |
painCave.isFatal = 1; |
25 |
< |
simError(); |
26 |
< |
} |
27 |
< |
output << "#number of z constrain molecules" << std::endl; |
28 |
< |
output << "#global Index of molecule\tzPos" << std::endl; |
29 |
< |
output << "#every frame will contain below data" <<std::endl; |
30 |
< |
output << "#time(fs)" << std::endl; |
31 |
< |
output << "#number of fixed z-constrain molecules" << std::endl; |
32 |
< |
output << "#global Index of molecule\tzconstrain force\tcurrentZPos" << std::endl; |
17 |
> |
output_.open(filename.c_str()); |
18 |
|
|
19 |
< |
parameters = thePara; |
20 |
< |
writeZPos(); |
19 |
> |
if(!output_){ |
20 |
> |
sprintf( painCave.errMsg, |
21 |
> |
"Could not open %s for z constrain output_ \n", filename.c_str()); |
22 |
> |
painCave.isFatal = 1; |
23 |
> |
simError(); |
24 |
> |
} |
25 |
|
|
26 |
+ |
output_ << "#time(fs)" << std::endl; |
27 |
+ |
output_ << "#number of fixed z-constrain molecules" << std::endl; |
28 |
+ |
output_ << "#global Index of molecule\tzconstrain force\tcurrentZPos" << std::endl; |
29 |
+ |
|
30 |
|
#ifdef IS_MPI |
31 |
< |
} |
31 |
> |
} |
32 |
|
#endif |
33 |
|
|
34 |
|
} |
39 |
|
#ifdef IS_MPI |
40 |
|
if(worldRank == 0 ){ |
41 |
|
#endif |
42 |
< |
output.close(); |
42 |
> |
output_.close(); |
43 |
|
#ifdef IS_MPI |
44 |
|
} |
45 |
|
#endif |
46 |
|
} |
47 |
|
|
48 |
< |
/** |
56 |
< |
* |
57 |
< |
*/ |
58 |
< |
void ZConsWriter::writeFZ(SimInfo* info, double time, int num, int* index, double* fz, double* curZPos, double* zpos){ |
59 |
< |
|
48 |
> |
void ZConsWriter::writeFZ(const std::list<ZconstraintMol>& fixedZmols){ |
49 |
|
#ifndef IS_MPI |
50 |
< |
output << time << std::endl; |
51 |
< |
output << num << std::endl; |
63 |
< |
|
64 |
< |
for(int i = 0; i < num; i++) |
65 |
< |
output << index[i] <<"\t" << fz[i] << "\t" << curZPos[i] << "\t" << zpos[i] <<std::endl; |
50 |
> |
output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() << std::endl; |
51 |
> |
output_ << fixedZmols.size() << std::endl; |
52 |
|
|
53 |
+ |
std::list<ZconstraintMol>::const_iterator i; |
54 |
+ |
for ( i = fixedZmols.begin(); i != fixedZmols.end(); ++i) { |
55 |
+ |
output_ << i->mol->getGlobalIndex() <<"\t" << i->fz << "\t" << i->zpos << "\t" << i->param.zTargetPos <<std::endl; |
56 |
+ |
} |
57 |
|
#else |
58 |
< |
int totalNum; |
59 |
< |
MPI_Allreduce(&num, &totalNum, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
60 |
< |
|
61 |
< |
if(worldRank == 0){ |
62 |
< |
output << time << std::endl; |
63 |
< |
output << totalNum << std::endl; |
64 |
< |
} |
75 |
< |
|
76 |
< |
int whichNode; |
77 |
< |
enum CommType { RequesPosAndForce, EndOfRequest} status; |
78 |
< |
double pos; |
79 |
< |
double force; |
80 |
< |
double zconsPos; |
81 |
< |
int localIndex; |
82 |
< |
MPI_Status ierr; |
83 |
< |
int tag = 0; |
84 |
< |
|
85 |
< |
if(worldRank == 0){ |
58 |
> |
int nproc; |
59 |
> |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
60 |
> |
const int masterNode = 0; |
61 |
> |
int myNode = worldRank; |
62 |
> |
std::vector<int> tmpNFixedZmols(nproc, 0); |
63 |
> |
std::vector<int> nFixedZmolsInProc(nproc, 0); |
64 |
> |
tmpNFixedZmols[myNode] = fixedZmols.size(); |
65 |
|
|
66 |
< |
int globalIndexOfCurMol; |
66 |
> |
//do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups |
67 |
> |
MPI_Allreduce(&tmpNFixedZmols[0], &nFixedZmolsInProc[0], nproc, MPI_INT, |
68 |
> |
MPI_SUM, MPI_COMM_WORLD); |
69 |
> |
|
70 |
> |
MPI_Status ierr; |
71 |
> |
int zmolIndex; |
72 |
> |
double data[3]; |
73 |
|
|
74 |
< |
for(int i = 0; i < (int)(parameters->size()); i++){ |
90 |
< |
|
91 |
< |
globalIndexOfCurMol = (*parameters)[i].zconsIndex; |
92 |
< |
whichNode = info->getMolToProc(globalIndexOfCurMol); |
93 |
< |
|
94 |
< |
if(whichNode == 0){ |
95 |
< |
|
96 |
< |
for(int j = 0; j < num; j++) |
97 |
< |
if(index[j] == globalIndexOfCurMol){ |
98 |
< |
localIndex = j; |
99 |
< |
break; |
100 |
< |
} |
74 |
> |
if (masterNode == 0) { |
75 |
|
|
76 |
< |
force = fz[localIndex]; |
77 |
< |
pos = curZPos[localIndex]; |
78 |
< |
|
79 |
< |
} |
80 |
< |
else{ |
81 |
< |
status = RequesPosAndForce; |
82 |
< |
MPI_Send(&status, 1, MPI_INT, whichNode, tag, MPI_COMM_WORLD); |
83 |
< |
MPI_Send(&globalIndexOfCurMol, 1, MPI_INT, whichNode, tag, MPI_COMM_WORLD); |
84 |
< |
MPI_Recv(&force, 1, MPI_DOUBLE, whichNode, tag, MPI_COMM_WORLD, &ierr); |
85 |
< |
MPI_Recv(&pos, 1, MPI_DOUBLE, whichNode, tag, MPI_COMM_WORLD, &ierr); |
86 |
< |
MPI_Recv(&zconsPos, 1, MPI_DOUBLE, whichNode, tag, MPI_COMM_WORLD, &ierr); |
87 |
< |
} |
76 |
> |
std::vector<ZconsData> zconsData; |
77 |
> |
ZconsData tmpData; |
78 |
> |
for(int i =0 ; i < nproc; ++i) { |
79 |
> |
if (i == masterNode) { |
80 |
> |
std::list<ZconstraintMol>::const_iterator j; |
81 |
> |
for ( i = fixedZmols.begin(); i != fixedZmols.end(); ++i) { |
82 |
> |
tmpData.zmolIndex = j->mol->getGlobalIndex() ; |
83 |
> |
tmpData.zforce= j->fz; |
84 |
> |
tmpData.zpos = j->zpos; |
85 |
> |
tmpData.zconsPos = j->param.zTargetPos; |
86 |
> |
zconsData.push_back(tmpData); |
87 |
> |
} |
88 |
|
|
89 |
< |
output << globalIndexOfCurMol << "\t" << force << "\t" << pos << "\t"<< zconsPos << std::endl; |
90 |
< |
|
91 |
< |
} //End of Request Loop |
92 |
< |
|
93 |
< |
//Send ending request message to slave nodes |
94 |
< |
status = EndOfRequest; |
89 |
> |
} else { |
90 |
> |
for(int k =0 ; k < nFixedZmolsInProc[i]; ++k) { |
91 |
> |
MPI_Recv(&zmolIndex, 1, MPI_INT, i, tag, MPI_COMM_WORLD,&ierr); |
92 |
> |
MPI_Recv(data, 3, MPI_DOUBLE, i, tag, MPI_COMM_WORLD,&ierr); |
93 |
> |
tmpData.zmolIndex = zmolIndex; |
94 |
> |
tmpData.zforce= data[0]; |
95 |
> |
tmpData.zpos = data[1]; |
96 |
> |
tmpData.zconsPos = data[2]; |
97 |
> |
zconsData.push_back(tmpData); |
98 |
> |
} |
99 |
> |
} |
100 |
> |
|
101 |
> |
} |
102 |
|
|
122 |
– |
int nproc; |
123 |
– |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
103 |
|
|
104 |
< |
for(int i =1; i < nproc; i++) |
105 |
< |
MPI_Send(&status, 1, MPI_INT, i, tag, MPI_COMM_WORLD); |
127 |
< |
|
128 |
< |
} |
129 |
< |
else{ |
130 |
< |
|
131 |
< |
int whichMol; |
132 |
< |
bool done = false; |
104 |
> |
output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() << std::endl; |
105 |
> |
output_ << zconsData.size() << std::endl; |
106 |
|
|
107 |
< |
while (!done){ |
108 |
< |
|
109 |
< |
MPI_Recv(&status, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &ierr); |
110 |
< |
|
111 |
< |
switch (status){ |
112 |
< |
|
140 |
< |
case RequesPosAndForce : |
141 |
< |
|
142 |
< |
MPI_Recv(&whichMol, 1, MPI_INT, 0, tag, MPI_COMM_WORLD,&ierr); |
143 |
< |
|
144 |
< |
for(int i = 0; i < num; i++) |
145 |
< |
if(index[i] == whichMol){ |
146 |
< |
localIndex = i; |
147 |
< |
break; |
148 |
< |
} |
149 |
< |
|
150 |
< |
MPI_Send(&fz[localIndex], 1, MPI_DOUBLE, 0, tag, MPI_COMM_WORLD); |
151 |
< |
MPI_Send(&curZPos[localIndex], 1, MPI_DOUBLE, 0, tag, MPI_COMM_WORLD); |
152 |
< |
MPI_Send(&zpos[localIndex], 1, MPI_DOUBLE, 0, tag, MPI_COMM_WORLD); |
153 |
< |
break; |
154 |
< |
|
155 |
< |
case EndOfRequest : |
156 |
< |
|
157 |
< |
done = true; |
158 |
< |
break; |
159 |
< |
} |
160 |
< |
|
161 |
< |
} |
162 |
< |
|
163 |
< |
} |
107 |
> |
std::vector<ZconsData>::iterator l; |
108 |
> |
for (l = zconsData.begin(); l != zconsData.end(); ++l) { |
109 |
> |
output_ << l->zmolIndex << "\t" << l->zforce << "\t" << l->zpos << "\t" << l->zconsPos << std::endl; |
110 |
> |
} |
111 |
> |
|
112 |
> |
} else { |
113 |
|
|
114 |
+ |
std::list<ZconstraintMol>::const_iterator j; |
115 |
+ |
for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) { |
116 |
+ |
zmolIndex = j->mol->getGlobalIndex(); |
117 |
+ |
data[0] = j->fz; |
118 |
+ |
data[1] = j->zpos; |
119 |
+ |
data[2] = j->param.zTargetPos; |
120 |
+ |
MPI_Send(&zmolIndex, 1, MPI_INT, masterNode, tag, MPI_COMM_WORLD); |
121 |
+ |
MPI_Send(data, 3, MPI_DOUBLE, masterNode, tag, MPI_COMM_WORLD); |
122 |
+ |
|
123 |
+ |
} |
124 |
+ |
} |
125 |
|
#endif |
166 |
– |
|
126 |
|
} |
127 |
|
|
169 |
– |
/* |
170 |
– |
* |
171 |
– |
*/ |
172 |
– |
void ZConsWriter::writeZPos(){ |
173 |
– |
|
174 |
– |
#ifdef IS_MPI |
175 |
– |
if(worldRank == 0){ |
176 |
– |
#endif |
177 |
– |
|
178 |
– |
output << parameters->size() << std::endl; |
179 |
– |
|
180 |
– |
for(int i =0 ; i < (int)(parameters->size()); i++) |
181 |
– |
output << (*parameters)[i].zconsIndex << "\t" << (*parameters)[i].zPos << std::endl; |
182 |
– |
|
183 |
– |
#ifdef IS_MPI |
184 |
– |
} |
185 |
– |
#endif |
128 |
|
} |