# | Line 60 | Line 60 | |
---|---|---|
60 | ||
61 | #ifdef IS_MPI | |
62 | #include <mpi.h> | |
63 | – | #include "brains/mpiSimulation.hpp" |
63 | #define TAKE_THIS_TAG_CHAR 0 | |
64 | #define TAKE_THIS_TAG_INT 1 | |
65 | #define TAKE_THIS_TAG_DOUBLE 2 | |
# | Line 69 | Line 68 | namespace oopse { | |
68 | namespace oopse { | |
69 | ||
70 | RestReader::RestReader( SimInfo* info ) : info_(info){ | |
72 | – | |
73 | – | idealName = "idealCrystal.in"; |
71 | ||
72 | < | isScanned = false; |
73 | < | |
72 | > | idealName = "idealCrystal.in"; |
73 | > | |
74 | #ifdef IS_MPI | |
75 | if (worldRank == 0) { | |
76 | #endif | |
77 | < | |
78 | < | inIdealFile = fopen(idealName, "r"); |
79 | < | if(inIdealFile == NULL){ |
77 | > | |
78 | > | inIdealFile = new std::ifstream(idealName.c_str()); |
79 | > | |
80 | > | if(inIdealFile->fail()){ |
81 | sprintf(painCave.errMsg, | |
82 | < | "RestReader: Cannot open file: %s\n", idealName); |
82 | > | "RestReader: Cannot open file: %s\n", |
83 | > | idealName.c_str()); |
84 | painCave.isFatal = 1; | |
85 | simError(); | |
86 | } | |
87 | ||
89 | – | inIdealFileName = idealName; |
88 | #ifdef IS_MPI | |
89 | } | |
90 | strcpy( checkPointMsg, | |
91 | "File \"idealCrystal.in\" opened successfully for reading." ); | |
92 | MPIcheckPoint(); | |
93 | #endif | |
94 | + | |
95 | return; | |
96 | } | |
97 | ||
# | Line 100 | Line 99 | namespace oopse { | |
99 | #ifdef IS_MPI | |
100 | if (worldRank == 0) { | |
101 | #endif | |
102 | < | int error; |
103 | < | error = fclose( inIdealFile ); |
104 | < | |
105 | < | if( error ){ |
107 | < | sprintf( painCave.errMsg, |
108 | < | "Error closing %s\n", inIdealFileName.c_str()); |
109 | < | simError(); |
110 | < | } |
111 | < | |
112 | < | MemoryUtils::deletePointers(framePos); |
113 | < | |
102 | > | |
103 | > | delete inIdealFile; |
104 | > | delete inAngFile; |
105 | > | |
106 | #ifdef IS_MPI | |
107 | } | |
108 | < | strcpy( checkPointMsg, "Restraint file closed successfully." ); |
108 | > | strcpy( checkPointMsg, |
109 | > | "File idealCrystal.in (and .zang0 if present) closed successfully." ); |
110 | MPIcheckPoint(); | |
111 | #endif | |
112 | ||
# | Line 122 | Line 115 | namespace oopse { | |
115 | ||
116 | ||
117 | void RestReader :: readIdealCrystal(){ | |
118 | < | |
126 | < | int i; |
127 | < | unsigned int j; |
128 | < | |
118 | > | |
119 | #ifdef IS_MPI | |
120 | < | int done, which_node, which_atom; // loop counter |
120 | > | int which_node; |
121 | > | int i, j; |
122 | #endif //is_mpi | |
123 | ||
124 | const int BUFFERSIZE = 2000; // size of the read buffer | |
125 | int nTotObjs; // the number of atoms | |
126 | char read_buffer[BUFFERSIZE]; //the line buffer for reading | |
127 | ||
137 | – | char *eof_test; // ptr to see when we reach the end of the file |
128 | char *parseErr; | |
129 | ||
130 | std::vector<StuntDouble*> integrableObjects; | |
# | Line 146 | Line 136 | namespace oopse { | |
136 | ||
137 | #ifndef IS_MPI | |
138 | ||
139 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
140 | < | if( eof_test == NULL ){ |
139 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
140 | > | |
141 | > | if( inIdealFile->eof() ){ |
142 | sprintf( painCave.errMsg, | |
143 | "RestraintReader error: error reading 1st line of \"%s\"\n", | |
144 | < | inIdealFileName.c_str() ); |
144 | > | idealName.c_str() ); |
145 | painCave.isFatal = 1; | |
146 | simError(); | |
147 | } | |
# | Line 161 | Line 152 | namespace oopse { | |
152 | sprintf( painCave.errMsg, | |
153 | "RestraintReader error. %s nIntegrable, %d, " | |
154 | "does not match the meta-data file's nIntegrable, %d.\n", | |
155 | < | inIdealFileName.c_str(), nTotObjs, |
155 | > | idealName.c_str(), |
156 | > | nTotObjs, |
157 | info_->getNGlobalIntegrableObjects()); | |
158 | painCave.isFatal = 1; | |
159 | simError(); | |
160 | } | |
161 | ||
162 | // skip over the comment line | |
163 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
164 | < | if(eof_test == NULL){ |
163 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
164 | > | |
165 | > | if( inIdealFile->eof() ){ |
166 | sprintf( painCave.errMsg, | |
167 | < | "error in reading commment in %s\n", inIdealFileName.c_str()); |
167 | > | "error in reading commment in %s\n", |
168 | > | idealName.c_str()); |
169 | painCave.isFatal = 1; | |
170 | simError(); | |
171 | } | |
# | Line 188 | Line 182 | namespace oopse { | |
182 | for (integrableObject = mol->beginIntegrableObject(ii); | |
183 | integrableObject != NULL; | |
184 | integrableObject = mol->nextIntegrableObject(ii)) { | |
185 | < | |
186 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
187 | < | if(eof_test == NULL){ |
185 | > | |
186 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
187 | > | |
188 | > | if( inIdealFile->eof() ){ |
189 | sprintf(painCave.errMsg, | |
190 | "RestReader Error: error in reading file %s\n" | |
191 | "natoms = %d; index = %d\n" | |
192 | "error reading the line from the file.\n", | |
193 | < | inIdealFileName.c_str(), nTotObjs, |
193 | > | idealName.c_str(), nTotObjs, |
194 | integrableObject->getGlobalIndex() ); | |
195 | painCave.isFatal = 1; | |
196 | simError(); | |
# | Line 217 | Line 212 | namespace oopse { | |
212 | painCave.isEventLoop = 1; | |
213 | ||
214 | int masterNode = 0; | |
220 | – | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
215 | ||
216 | MPI_Status istatus; | |
223 | – | int localIndex; |
217 | int nCurObj; | |
218 | int nitems; | |
219 | < | |
220 | < | nTotObjs = info_->getTotIntegrableObjects(); |
219 | > | int haveError; |
220 | > | |
221 | > | nTotObjs = info_->getNGlobalIntegrableObjects(); |
222 | haveError = 0; | |
223 | < | |
223 | > | |
224 | if (worldRank == masterNode) { | |
225 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
226 | < | if( eof_test == NULL ){ |
225 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
226 | > | |
227 | > | if( inIdealFile->eof() ){ |
228 | sprintf( painCave.errMsg, | |
229 | < | "Error reading 1st line of %s \n ",inIdealFileName.c_str()); |
229 | > | "Error reading 1st line of %s \n ",idealName.c_str()); |
230 | painCave.isFatal = 1; | |
231 | simError(); | |
232 | } | |
# | Line 245 | Line 240 | namespace oopse { | |
240 | sprintf( painCave.errMsg, | |
241 | "RestraintReader Error. %s nIntegrable, %d, " | |
242 | "does not match the meta-data file's nIntegrable, %d.\n", | |
243 | < | inIdealFileName.c_str(), nTotObjs, |
243 | > | idealName.c_str(), nTotObjs, |
244 | info_->getNGlobalIntegrableObjects()); | |
245 | painCave.isFatal = 1; | |
246 | simError(); | |
247 | } | |
248 | ||
249 | // skip over the comment line | |
250 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
251 | < | if(eof_test == NULL){ |
250 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
251 | > | |
252 | > | if( inIdealFile->eof() ){ |
253 | sprintf( painCave.errMsg, | |
254 | < | "error in reading commment in %s\n", inIdealFileName.c_str()); |
254 | > | "error in reading commment in %s\n", idealName.c_str()); |
255 | painCave.isFatal = 1; | |
256 | simError(); | |
257 | } | |
258 | < | |
258 | > | |
259 | > | MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
260 | > | |
261 | for (i=0 ; i < info_->getNGlobalMolecules(); i++) { | |
262 | < | int which_node = info_->getMolToProc(i); |
262 | > | which_node = info_->getMolToProc(i); |
263 | ||
264 | if(which_node == masterNode){ | |
265 | //molecules belong to master node | |
266 | ||
267 | < | localIndex = info_->getMoleculeByGlobalIndex(i); |
267 | > | mol = info_->getMoleculeByGlobalIndex(i); |
268 | ||
269 | < | if(localIndex == NULL) { |
270 | < | strcpy(painCave.errMsg, |
271 | < | "RestReader Error: Molecule not found on node %d!", |
272 | < | worldRank); |
269 | > | if(mol == NULL) { |
270 | > | sprintf(painCave.errMsg, |
271 | > | "RestReader Error: Molecule not found on node %d!\n", |
272 | > | worldRank); |
273 | painCave.isFatal = 1; | |
274 | simError(); | |
275 | } | |
# | Line 280 | Line 278 | namespace oopse { | |
278 | integrableObject != NULL; | |
279 | integrableObject = mol->nextIntegrableObject(ii)){ | |
280 | ||
281 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
281 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
282 | ||
283 | < | if(eof_test == NULL){ |
283 | > | if( inIdealFile->eof() ){ |
284 | sprintf(painCave.errMsg, | |
285 | "RestReader Error: error in reading file %s\n" | |
286 | "natoms = %d; index = %d\n" | |
287 | "error reading the line from the file.\n", | |
288 | < | inIdealFileName.c_str(), nTotObjs, i ); |
288 | > | idealName.c_str(), nTotObjs, i ); |
289 | painCave.isFatal = 1; | |
290 | simError(); | |
291 | } | |
292 | < | |
293 | < | parseIdealLine(read_buffer, integrableObjects[j]); |
292 | > | |
293 | > | parseIdealLine(read_buffer, integrableObject); |
294 | > | |
295 | } | |
296 | + | |
297 | } else { | |
298 | //molecule belongs to slave nodes | |
299 | ||
300 | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, | |
301 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); | |
302 | ||
303 | < | for(j=0; j < nCurObj; j++){ |
304 | < | |
305 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); |
306 | < | if(eof_test == NULL){ |
303 | > | for(j = 0; j < nCurObj; j++){ |
304 | > | inIdealFile->getline(read_buffer, sizeof(read_buffer)); |
305 | > | |
306 | > | if( inIdealFile->eof() ){ |
307 | sprintf(painCave.errMsg, | |
308 | "RestReader Error: error in reading file %s\n" | |
309 | "natoms = %d; index = %d\n" | |
310 | "error reading the line from the file.\n", | |
311 | < | inIdealFileName.c_str(), nTotObjs, i ); |
311 | > | idealName.c_str(), nTotObjs, i ); |
312 | painCave.isFatal = 1; | |
313 | simError(); | |
314 | } | |
315 | ||
316 | < | if(haveError) nodeZeroError(); |
317 | < | |
318 | < | MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
316 | > | MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
317 | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); | |
318 | } | |
319 | } | |
320 | } | |
321 | } else { | |
322 | < | //actions taken at slave nodes |
322 | > | //actions taken at slave nodes |
323 | > | MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
324 | > | |
325 | for (i=0 ; i < info_->getNGlobalMolecules(); i++) { | |
326 | < | int which_node = info_->getMolToProc(i); |
327 | < | |
326 | > | int which_node = info_->getMolToProc(i); |
327 | > | |
328 | if(which_node == worldRank){ | |
329 | //molecule with global index i belongs to this processor | |
330 | ||
331 | < | localIndex = info_->getMoleculeByGlobalIndex(i); |
331 | > | mol = info_->getMoleculeByGlobalIndex(i); |
332 | ||
333 | < | if(localIndex == NULL) { |
333 | > | if(mol == NULL) { |
334 | sprintf(painCave.errMsg, | |
335 | "RestReader Error: molecule not found on node %d\n", | |
336 | worldRank); | |
# | Line 338 | Line 338 | namespace oopse { | |
338 | simError(); | |
339 | } | |
340 | ||
341 | < | nCurObj = localIndex->getNIntegrableObjects(); |
341 | > | nCurObj = mol->getNIntegrableObjects(); |
342 | ||
343 | MPI_Send(&nCurObj, 1, MPI_INT, masterNode, | |
344 | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); | |
# | Line 365 | Line 365 | namespace oopse { | |
365 | ||
366 | char* RestReader::parseIdealLine(char* readLine, StuntDouble* sd){ | |
367 | ||
368 | < | char *foo; // the pointer to the current string token |
369 | < | |
370 | < | double pos[3]; // position place holders |
371 | < | double q[4]; // the quaternions |
372 | < | double RfromQ[3][3]; // the rotation matrix |
373 | < | double normalize; // to normalize the reference unit vector |
374 | < | double uX, uY, uZ; // reference unit vector place holders |
375 | < | double uselessToken; |
368 | > | RealType pos[3]; // position place holders |
369 | > | RealType q[4]; // the quaternions |
370 | > | RealType RfromQ[3][3]; // the rotation matrix |
371 | > | RealType normalize; // to normalize the reference unit vector |
372 | > | RealType uX, uY, uZ; // reference unit vector place holders |
373 | > | RealType uselessToken; |
374 | StringTokenizer tokenizer(readLine); | |
375 | int nTokens; | |
376 | ||
377 | nTokens = tokenizer.countTokens(); | |
378 | < | |
378 | > | |
379 | if (nTokens < 14) { | |
380 | sprintf(painCave.errMsg, | |
381 | "RestReader Error: Not enough Tokens.\n"); | |
# | Line 386 | Line 384 | namespace oopse { | |
384 | } | |
385 | ||
386 | std::string name = tokenizer.nextToken(); | |
387 | < | |
387 | > | |
388 | if (name != sd->getType()) { | |
389 | ||
390 | sprintf(painCave.errMsg, | |
391 | "RestReader Error: Atom type [%s] in %s does not " | |
392 | "match Atom Type [%s] in .md file.\n", | |
393 | < | name.c_str(), inIdealFileName.c_str(), |
393 | > | name.c_str(), idealName.c_str(), |
394 | sd->getType().c_str()); | |
395 | painCave.isFatal = 1; | |
396 | simError(); | |
# | Line 401 | Line 399 | namespace oopse { | |
399 | pos[0] = tokenizer.nextTokenAsDouble(); | |
400 | pos[1] = tokenizer.nextTokenAsDouble(); | |
401 | pos[2] = tokenizer.nextTokenAsDouble(); | |
402 | < | |
402 | > | |
403 | // store the positions in the stuntdouble as generic data doubles | |
404 | DoubleGenericData* refPosX = new DoubleGenericData(); | |
405 | refPosX->setID("refPosX"); | |
406 | refPosX->setData(pos[0]); | |
407 | sd->addProperty(refPosX); | |
408 | < | |
408 | > | |
409 | DoubleGenericData* refPosY = new DoubleGenericData(); | |
410 | refPosY->setID("refPosY"); | |
411 | refPosY->setData(pos[1]); | |
# | Line 417 | Line 415 | namespace oopse { | |
415 | refPosZ->setID("refPosZ"); | |
416 | refPosZ->setData(pos[2]); | |
417 | sd->addProperty(refPosZ); | |
418 | < | |
418 | > | |
419 | // we don't need the velocities | |
420 | uselessToken = tokenizer.nextTokenAsDouble(); | |
421 | uselessToken = tokenizer.nextTokenAsDouble(); | |
# | Line 471 | Line 469 | namespace oopse { | |
469 | void RestReader::readZangle(){ | |
470 | ||
471 | int i; | |
474 | – | unsigned int j; |
472 | int isPresent; | |
473 | ||
474 | Molecule* mol; | |
# | Line 480 | Line 477 | namespace oopse { | |
477 | Molecule::IntegrableObjectIterator ii; | |
478 | ||
479 | #ifdef IS_MPI | |
480 | < | int done, which_node, which_atom; // loop counter |
484 | < | int nProc; |
480 | > | int which_node; |
481 | MPI_Status istatus; | |
482 | #endif //is_mpi | |
483 | ||
484 | const int BUFFERSIZE = 2000; // size of the read buffer | |
485 | < | int nTotObjs; // the number of atoms |
485 | > | unsigned int nTotObjs; // the number of atoms |
486 | char read_buffer[BUFFERSIZE]; //the line buffer for reading | |
487 | ||
492 | – | char *eof_test; // ptr to see when we reach the end of the file |
493 | – | char *parseErr; |
494 | – | |
488 | std::vector<StuntDouble*> vecParticles; | |
489 | < | std::vector<double> tempZangs; |
489 | > | std::vector<RealType> tempZangs; |
490 | ||
491 | < | inAngFileName = info_->getRestFileName(); |
491 | > | angFile = info_->getRestFileName(); |
492 | ||
493 | < | inAngFileName += "0"; |
493 | > | angFile += "0"; |
494 | ||
495 | // open the omega value file for reading | |
496 | #ifdef IS_MPI | |
497 | if (worldRank == 0) { | |
498 | #endif | |
499 | isPresent = 1; | |
500 | < | inAngFile = fopen(inAngFileName.c_str(), "r"); |
501 | < | if(!inAngFile){ |
500 | > | |
501 | > | inAngFile = new std::ifstream(angFile.c_str()); |
502 | > | |
503 | > | if(inAngFile->fail()){ |
504 | sprintf(painCave.errMsg, | |
505 | "Restraints Warning: %s file is not present\n" | |
506 | "\tAll omega values will be initialized to zero. If the\n" | |
507 | "\tsimulation is starting from the idealCrystal.in reference\n" | |
508 | "\tconfiguration, this is the desired action. If this is not\n" | |
509 | "\tthe case, the energy calculations will be incorrect.\n", | |
510 | < | inAngFileName.c_str()); |
510 | > | angFile.c_str()); |
511 | painCave.severity = OOPSE_WARNING; | |
512 | painCave.isFatal = 0; | |
513 | simError(); | |
# | Line 530 | Line 525 | namespace oopse { | |
525 | } | |
526 | ||
527 | #ifdef IS_MPI | |
528 | + | if (!isPresent) { |
529 | + | // master node zeroes out its zAngles if .zang0 isn't present |
530 | + | zeroZangle(); |
531 | + | return; |
532 | + | } |
533 | + | |
534 | } | |
535 | ||
536 | // listen to node 0 to see if we should exit this function | |
# | Line 547 | Line 548 | namespace oopse { | |
548 | ||
549 | #ifndef IS_MPI | |
550 | ||
551 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
552 | < | if( eof_test == NULL ){ |
551 | > | // read the first line and die if there is a failure |
552 | > | inAngFile->getline(read_buffer, sizeof(read_buffer)); |
553 | > | |
554 | > | if( inAngFile->eof() ){ |
555 | sprintf( painCave.errMsg, | |
556 | "RestraintReader error: error reading 1st line of \"%s\"\n", | |
557 | < | inAngFileName.c_str() ); |
557 | > | angFile.c_str() ); |
558 | painCave.isFatal = 1; | |
559 | simError(); | |
560 | } | |
561 | + | |
562 | + | // read the file and load the values into a vector |
563 | + | inAngFile->getline(read_buffer, sizeof(read_buffer)); |
564 | ||
565 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
560 | < | while ( eof_test != NULL ) { |
565 | > | while ( !inAngFile->eof() ) { |
566 | // check for and ignore blank lines | |
567 | if ( read_buffer != NULL ) | |
568 | tempZangs.push_back( atof(read_buffer) ); | |
569 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
569 | > | |
570 | > | inAngFile->getline(read_buffer, sizeof(read_buffer)); |
571 | } | |
572 | ||
573 | nTotObjs = info_->getNGlobalIntegrableObjects(); | |
# | Line 569 | Line 575 | namespace oopse { | |
575 | if( nTotObjs != tempZangs.size() ){ | |
576 | sprintf( painCave.errMsg, | |
577 | "RestraintReader zAngle reading error. %s nIntegrable, %d, " | |
578 | < | "does not match the meta-data file's nIntegrable, %d.\n", |
579 | < | inAngFileName.c_str(), tempZangs.size(), nTotObjs ); |
578 | > | "does not match the meta-data file's nIntegrable, %i.\n", |
579 | > | angFile.c_str(), |
580 | > | tempZangs.size(), |
581 | > | nTotObjs ); |
582 | painCave.isFatal = 1; | |
583 | simError(); | |
584 | } | |
# | Line 594 | Line 602 | namespace oopse { | |
602 | ||
603 | // first thing first, suspend fatalities. | |
604 | painCave.isEventLoop = 1; | |
605 | < | |
606 | < | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
607 | < | int haveError, index; |
608 | < | |
609 | < | int *MolToProcMap = mpiSim->getMolToProcMap(); |
610 | < | int localIndex; |
605 | > | |
606 | > | int masterNode = 0; |
607 | > | |
608 | > | int haveError; |
609 | > | int intObjIndex; |
610 | > | int intObjIndexTransfer; |
611 | > | |
612 | > | int j; |
613 | int nCurObj; | |
614 | < | double angleTranfer; |
614 | > | RealType angleTransfer; |
615 | ||
616 | < | nTotObjs = info_->getTotIntegrableObjects(); |
616 | > | nTotObjs = info_->getNGlobalIntegrableObjects(); |
617 | haveError = 0; | |
618 | < | if (worldRank == 0) { |
618 | > | |
619 | > | if (worldRank == masterNode) { |
620 | ||
621 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
622 | < | if( eof_test == NULL ){ |
621 | > | inAngFile->getline(read_buffer, sizeof(read_buffer)); |
622 | > | |
623 | > | if( inAngFile->eof() ){ |
624 | sprintf( painCave.errMsg, | |
625 | < | "Error reading 1st line of %s \n ",inAngFileName.c_str()); |
625 | > | "Error reading 1st line of %s \n ",angFile.c_str()); |
626 | haveError = 1; | |
627 | simError(); | |
628 | } | |
629 | ||
630 | < | // let node 0 load the temporary angle vector |
631 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
632 | < | while ( eof_test != NULL ) { |
630 | > | // let the master node read the file and load the temporary angle vector |
631 | > | inAngFile->getline(read_buffer, sizeof(read_buffer)); |
632 | > | |
633 | > | while ( !inAngFile->eof() ) { |
634 | // check for and ignore blank lines | |
635 | if ( read_buffer != NULL ) | |
636 | tempZangs.push_back( atof(read_buffer) ); | |
637 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); |
637 | > | |
638 | > | inAngFile->getline(read_buffer, sizeof(read_buffer)); |
639 | } | |
640 | < | |
640 | > | |
641 | // Check to see that the number of integrable objects in the | |
642 | // intial configuration file is the same as derived from the | |
643 | // meta-data file. | |
# | Line 631 | Line 645 | namespace oopse { | |
645 | sprintf( painCave.errMsg, | |
646 | "RestraintReader zAngle reading Error. %s nIntegrable, %d, " | |
647 | "does not match the meta-data file's nIntegrable, %d.\n", | |
648 | < | inAngFileName.c_str(), tempZangs.size(), nTotObjs); |
648 | > | angFile.c_str(), |
649 | > | tempZangs.size(), |
650 | > | nTotObjs); |
651 | haveError= 1; | |
652 | simError(); | |
653 | } | |
654 | ||
655 | < | } |
656 | < | // At this point, node 0 has a tempZangs vector completed, and |
641 | < | // everyone else has nada |
642 | < | index = 0; |
643 | < | |
644 | < | for (i=0 ; i < mpiSim->getNMolGlobal(); i++) { |
645 | < | // Get the Node number which has this atom |
646 | < | which_node = MolToProcMap[i]; |
655 | > | // At this point, node 0 has a tempZangs vector completed, and |
656 | > | // everyone else has nada |
657 | ||
658 | < | if (worldRank == 0) { |
659 | < | if (which_node == 0) { |
660 | < | localIndex = mpiSim->getGlobalToLocalMol(i); |
661 | < | |
662 | < | if(localIndex == -1) { |
663 | < | strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
664 | < | haveError = 1; |
658 | > | for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
659 | > | // Get the Node number which has this atom |
660 | > | which_node = info_->getMolToProc(i); |
661 | > | |
662 | > | if (which_node == masterNode) { |
663 | > | mol = info_->getMoleculeByGlobalIndex(i); |
664 | > | |
665 | > | if(mol == NULL) { |
666 | > | strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
667 | > | haveError = 1; |
668 | > | simError(); |
669 | > | } |
670 | > | |
671 | > | for (integrableObject = mol->beginIntegrableObject(ii); |
672 | > | integrableObject != NULL; |
673 | > | integrableObject = mol->nextIntegrableObject(ii)){ |
674 | > | intObjIndex = integrableObject->getGlobalIndex(); |
675 | > | integrableObject->setZangle(tempZangs[intObjIndex]); |
676 | > | } |
677 | > | |
678 | > | } else { |
679 | > | // I am MASTER OF THE UNIVERSE, but I don't own this molecule |
680 | > | // listen for the number of integrableObjects in the molecule |
681 | > | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
682 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
683 | > | |
684 | > | for(j=0; j < nCurObj; j++){ |
685 | > | // listen for which integrableObject we need to send the value for |
686 | > | MPI_Recv(&intObjIndexTransfer, 1, MPI_INT, which_node, |
687 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
688 | > | angleTransfer = tempZangs[intObjIndexTransfer]; |
689 | > | // send the value to the node so it can initialize the object |
690 | > | MPI_Send(&angleTransfer, 1, MPI_REALTYPE, which_node, |
691 | > | TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); |
692 | > | } |
693 | > | } |
694 | > | } |
695 | > | } else { |
696 | > | // I am SLAVE TO THE MASTER |
697 | > | for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
698 | > | which_node = info_->getMolToProc(i); |
699 | > | |
700 | > | if (which_node == worldRank) { |
701 | > | |
702 | > | // BUT I OWN THIS MOLECULE!!! |
703 | > | |
704 | > | mol = info_->getMoleculeByGlobalIndex(i); |
705 | > | |
706 | > | if(mol == NULL) { |
707 | > | sprintf(painCave.errMsg, |
708 | > | "RestReader Error: molecule not found on node %d\n", |
709 | > | worldRank); |
710 | > | painCave.isFatal = 1; |
711 | simError(); | |
712 | } | |
713 | < | |
714 | < | vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); |
715 | < | for(j = 0; j < vecParticles.size(); j++){ |
716 | < | vecParticles[j]->setZangle(tempZangs[index]); |
717 | < | index++; |
718 | < | } |
719 | < | |
720 | < | } else { |
721 | < | // I am MASTER OF THE UNIVERSE, but I don't own this molecule |
722 | < | |
723 | < | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
724 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
725 | < | |
726 | < | for(j=0; j < nCurObj; j++){ |
727 | < | angleTransfer = tempZangs[index]; |
728 | < | MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, |
729 | < | TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); |
730 | < | index++; |
731 | < | } |
732 | < | |
677 | < | } |
678 | < | |
679 | < | } else { |
680 | < | // I am SLAVE TO THE MASTER |
681 | < | |
682 | < | if (which_node == worldRank) { |
683 | < | |
684 | < | // BUT I OWN THIS MOLECULE!!! |
685 | < | |
686 | < | localIndex = mpiSim->getGlobalToLocalMol(i); |
687 | < | vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); |
688 | < | nCurObj = vecParticles.size(); |
689 | < | |
690 | < | MPI_Send(&nCurObj, 1, MPI_INT, 0, |
691 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
692 | < | |
693 | < | for(j = 0; j < vecParticles.size(); j++){ |
694 | < | |
695 | < | MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0, |
696 | < | TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); |
697 | < | vecParticles[j]->setZangle(angleTransfer); |
698 | < | } |
699 | < | } |
713 | > | |
714 | > | nCurObj = mol->getNIntegrableObjects(); |
715 | > | // send the number of integrableObjects in the molecule |
716 | > | MPI_Send(&nCurObj, 1, MPI_INT, 0, |
717 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
718 | > | |
719 | > | for (integrableObject = mol->beginIntegrableObject(ii); |
720 | > | integrableObject != NULL; |
721 | > | integrableObject = mol->nextIntegrableObject(ii)){ |
722 | > | intObjIndexTransfer = integrableObject->getGlobalIndex(); |
723 | > | // send the global index of the integrableObject |
724 | > | MPI_Send(&intObjIndexTransfer, 1, MPI_INT, 0, |
725 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
726 | > | // listen for the value we want to set locally |
727 | > | MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0, |
728 | > | TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); |
729 | > | |
730 | > | integrableObject->setZangle(angleTransfer); |
731 | > | } |
732 | > | } |
733 | } | |
734 | < | } |
734 | > | } |
735 | #endif | |
736 | } | |
737 | ||
738 | void RestReader :: zeroZangle(){ | |
739 | ||
707 | – | int i; |
708 | – | unsigned int j; |
709 | – | int nTotObjs; // the number of atoms |
710 | – | |
740 | Molecule* mol; | |
741 | StuntDouble* integrableObject; | |
742 | SimInfo::MoleculeIterator mi; | |
743 | Molecule::IntegrableObjectIterator ii; | |
744 | < | |
716 | < | std::vector<StuntDouble*> vecParticles; |
717 | < | |
744 | > | |
745 | #ifndef IS_MPI | |
746 | // set all zAngles to 0.0 | |
747 | for (mol = info_->beginMolecule(mi); mol != NULL; | |
# | Line 733 | Line 760 | namespace oopse { | |
760 | painCave.isEventLoop = 1; | |
761 | ||
762 | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone | |
763 | < | int haveError, index; |
763 | > | int haveError; |
764 | int which_node; | |
765 | ||
739 | – | MPI_Status istatus; |
740 | – | int *MolToProcMap = mpiSim->getMolToProcMap(); |
741 | – | int localIndex; |
742 | – | int nCurObj; |
743 | – | double angleTranfer; |
744 | – | |
745 | – | nTotObjs = info_->getTotIntegrableObjects(); |
766 | haveError = 0; | |
767 | < | |
768 | < | for (i=0 ; i < mpiSim->getNMolGlobal(); i++) { |
767 | > | |
768 | > | for (int i=0 ; i < info_->getNGlobalMolecules(); i++) { |
769 | > | |
770 | // Get the Node number which has this atom | |
771 | < | which_node = MolToProcMap[i]; |
772 | < | |
773 | < | // let's let node 0 pass out constant values to all the processors |
774 | < | if (worldRank == 0) { |
775 | < | if (which_node == 0) { |
776 | < | localIndex = mpiSim->getGlobalToLocalMol(i); |
777 | < | |
778 | < | if(localIndex == -1) { |
779 | < | strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
780 | < | haveError = 1; |
781 | < | simError(); |
782 | < | } |
783 | < | |
784 | < | vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); |
785 | < | for(j = 0; j < vecParticles.size(); j++){ |
786 | < | vecParticles[j]->setZangle( 0.0 ); |
787 | < | } |
788 | < | |
789 | < | } else { |
790 | < | // I am MASTER OF THE UNIVERSE, but I don't own this molecule |
791 | < | |
771 | < | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
772 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
773 | < | |
774 | < | for(j=0; j < nCurObj; j++){ |
775 | < | angleTransfer = 0.0; |
776 | < | MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, |
777 | < | TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); |
778 | < | index++; |
779 | < | } |
780 | < | } |
781 | < | } else { |
782 | < | // I am SLAVE TO THE MASTER |
783 | < | |
784 | < | if (which_node == worldRank) { |
785 | < | |
786 | < | // BUT I OWN THIS MOLECULE!!! |
787 | < | |
788 | < | localIndex = mpiSim->getGlobalToLocalMol(i); |
789 | < | vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); |
790 | < | nCurObj = vecParticles.size(); |
791 | < | |
792 | < | MPI_Send(&nCurObj, 1, MPI_INT, 0, |
793 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
794 | < | |
795 | < | for(j = 0; j < vecParticles.size(); j++){ |
796 | < | |
797 | < | MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0, |
798 | < | TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); |
799 | < | vecParticles[j]->setZangle(angleTransfer); |
800 | < | } |
801 | < | } |
771 | > | which_node = info_->getMolToProc(i); |
772 | > | |
773 | > | // each processor zeroes its own integrable objects |
774 | > | if (which_node == worldRank) { |
775 | > | mol = info_->getMoleculeByGlobalIndex(i); |
776 | > | |
777 | > | if(mol == NULL) { |
778 | > | sprintf( painCave.errMsg, |
779 | > | "Molecule not found on node %i!", |
780 | > | which_node ); |
781 | > | haveError = 1; |
782 | > | simError(); |
783 | > | } |
784 | > | |
785 | > | for (integrableObject = mol->beginIntegrableObject(ii); |
786 | > | integrableObject != NULL; |
787 | > | integrableObject = mol->nextIntegrableObject(ii)){ |
788 | > | |
789 | > | integrableObject->setZangle( 0.0 ); |
790 | > | |
791 | > | } |
792 | } | |
793 | } | |
794 | + | |
795 | #endif | |
796 | } | |
797 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |