| 68 |
|
namespace oopse { |
| 69 |
|
|
| 70 |
|
RestReader::RestReader( SimInfo* info ) : info_(info){ |
| 71 |
– |
|
| 72 |
– |
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 |
|
|
| 88 |
– |
inIdealFileName = idealName; |
| 88 |
|
#ifdef IS_MPI |
| 89 |
|
} |
| 90 |
|
strcpy( checkPointMsg, |
| 91 |
|
"File \"idealCrystal.in\" opened successfully for reading." ); |
| 92 |
< |
MPIcheckPoint(); |
| 92 |
> |
errorCheckPoint(); |
| 93 |
|
#endif |
| 94 |
+ |
|
| 95 |
|
return; |
| 96 |
|
} |
| 97 |
|
|
| 99 |
|
#ifdef IS_MPI |
| 100 |
|
if (worldRank == 0) { |
| 101 |
|
#endif |
| 102 |
< |
int error; |
| 103 |
< |
error = fclose( inIdealFile ); |
| 104 |
< |
|
| 105 |
< |
if( error ){ |
| 106 |
< |
sprintf( painCave.errMsg, |
| 107 |
< |
"Error closing %s\n", inIdealFileName.c_str()); |
| 108 |
< |
simError(); |
| 109 |
< |
} |
| 110 |
< |
|
| 111 |
< |
MemoryUtils::deletePointers(framePos); |
| 112 |
< |
|
| 102 |
> |
|
| 103 |
> |
delete inIdealFile; |
| 104 |
> |
delete inAngFile; |
| 105 |
> |
|
| 106 |
|
#ifdef IS_MPI |
| 107 |
|
} |
| 108 |
< |
strcpy( checkPointMsg, "Restraint file closed successfully." ); |
| 109 |
< |
MPIcheckPoint(); |
| 108 |
> |
strcpy( checkPointMsg, |
| 109 |
> |
"File idealCrystal.in (and .zang0 if present) closed successfully." ); |
| 110 |
> |
errorCheckPoint(); |
| 111 |
|
#endif |
| 112 |
|
|
| 113 |
|
return; |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
void RestReader :: readIdealCrystal(){ |
| 118 |
< |
|
| 125 |
< |
int i; |
| 126 |
< |
unsigned int j; |
| 127 |
< |
|
| 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 |
|
|
| 136 |
– |
char *eof_test; // ptr to see when we reach the end of the file |
| 128 |
|
char *parseErr; |
| 129 |
|
|
| 130 |
|
std::vector<StuntDouble*> integrableObjects; |
| 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 |
|
} |
| 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 |
|
} |
| 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(); |
| 212 |
|
painCave.isEventLoop = 1; |
| 213 |
|
|
| 214 |
|
int masterNode = 0; |
| 219 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 215 |
|
|
| 216 |
|
MPI_Status istatus; |
| 217 |
|
int nCurObj; |
| 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 |
|
} |
| 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 |
| 268 |
|
|
| 269 |
|
if(mol == NULL) { |
| 270 |
|
sprintf(painCave.errMsg, |
| 271 |
< |
"RestReader Error: Molecule not found on node %d!\n", |
| 272 |
< |
worldRank); |
| 271 |
> |
"RestReader Error: Molecule not found on node %d!\n", |
| 272 |
> |
worldRank); |
| 273 |
|
painCave.isFatal = 1; |
| 274 |
|
simError(); |
| 275 |
|
} |
| 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 |
|
} |
| 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 |
|
|
| 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 |
| 371 |
< |
double uX, uY, uZ; // reference unit vector place holders |
| 372 |
< |
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"); |
| 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(); |
| 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]); |
| 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(); |
| 469 |
|
void RestReader::readZangle(){ |
| 470 |
|
|
| 471 |
|
int i; |
| 471 |
– |
unsigned int j; |
| 472 |
|
int isPresent; |
| 473 |
|
|
| 474 |
|
Molecule* mol; |
| 477 |
|
Molecule::IntegrableObjectIterator ii; |
| 478 |
|
|
| 479 |
|
#ifdef IS_MPI |
| 480 |
< |
int done, which_node, which_atom; // loop counter |
| 481 |
< |
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 |
|
|
| 489 |
– |
char *eof_test; // ptr to see when we reach the end of the file |
| 490 |
– |
char *parseErr; |
| 491 |
– |
|
| 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(); |
| 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 |
| 543 |
|
} |
| 544 |
|
|
| 545 |
|
strcpy( checkPointMsg, "zAngle file opened successfully for reading." ); |
| 546 |
< |
MPIcheckPoint(); |
| 546 |
> |
errorCheckPoint(); |
| 547 |
|
#endif |
| 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); |
| 557 |
< |
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(); |
| 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 |
|
} |
| 604 |
|
painCave.isEventLoop = 1; |
| 605 |
|
|
| 606 |
|
int masterNode = 0; |
| 607 |
< |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 607 |
> |
|
| 608 |
|
int haveError; |
| 609 |
< |
int index; |
| 609 |
> |
int intObjIndex; |
| 610 |
> |
int intObjIndexTransfer; |
| 611 |
|
|
| 612 |
+ |
int j; |
| 613 |
|
int nCurObj; |
| 614 |
< |
double angleTranfer; |
| 614 |
> |
RealType angleTransfer; |
| 615 |
|
|
| 616 |
|
nTotObjs = info_->getNGlobalIntegrableObjects(); |
| 617 |
|
haveError = 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. |
| 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 |
|
// At this point, node 0 has a tempZangs vector completed, and |
| 656 |
|
// everyone else has nada |
| 639 |
– |
index = 0; |
| 657 |
|
|
| 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 (worldRank == masterNode) { |
| 662 |
> |
if (which_node == masterNode) { |
| 663 |
|
mol = info_->getMoleculeByGlobalIndex(i); |
| 664 |
< |
|
| 664 |
> |
|
| 665 |
|
if(mol == NULL) { |
| 666 |
|
strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
| 667 |
|
haveError = 1; |
| 668 |
|
simError(); |
| 669 |
|
} |
| 670 |
< |
|
| 670 |
> |
|
| 671 |
|
for (integrableObject = mol->beginIntegrableObject(ii); |
| 672 |
|
integrableObject != NULL; |
| 673 |
|
integrableObject = mol->nextIntegrableObject(ii)){ |
| 674 |
< |
|
| 675 |
< |
integrableObject->setZangle(tempZangs[index]); |
| 659 |
< |
index++; |
| 674 |
> |
intObjIndex = integrableObject->getGlobalIntegrableObjectIndex(); |
| 675 |
> |
integrableObject->setZangle(tempZangs[intObjIndex]); |
| 676 |
|
} |
| 677 |
|
|
| 678 |
|
} else { |
| 679 |
|
// I am MASTER OF THE UNIVERSE, but I don't own this molecule |
| 680 |
< |
|
| 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 |
< |
angleTransfer = tempZangs[index]; |
| 686 |
< |
MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, |
| 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); |
| 672 |
– |
index++; |
| 692 |
|
} |
| 674 |
– |
|
| 693 |
|
} |
| 694 |
|
} |
| 695 |
|
} else { |
| 696 |
|
// I am SLAVE TO THE MASTER |
| 697 |
|
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 698 |
< |
int which_node = info_->getMolToProc(i); |
| 698 |
> |
which_node = info_->getMolToProc(i); |
| 699 |
|
|
| 700 |
|
if (which_node == worldRank) { |
| 701 |
|
|
| 712 |
|
} |
| 713 |
|
|
| 714 |
|
nCurObj = mol->getNIntegrableObjects(); |
| 715 |
< |
|
| 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 |
< |
|
| 723 |
< |
MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0, |
| 722 |
> |
intObjIndexTransfer = integrableObject->getGlobalIntegrableObjectIndex(); |
| 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); |
| 737 |
|
|
| 738 |
|
void RestReader :: zeroZangle(){ |
| 739 |
|
|
| 718 |
– |
int i; |
| 719 |
– |
unsigned int j; |
| 720 |
– |
int nTotObjs; // the number of atoms |
| 721 |
– |
|
| 740 |
|
Molecule* mol; |
| 741 |
|
StuntDouble* integrableObject; |
| 742 |
|
SimInfo::MoleculeIterator mi; |
| 743 |
|
Molecule::IntegrableObjectIterator ii; |
| 744 |
< |
|
| 727 |
< |
std::vector<StuntDouble*> vecParticles; |
| 728 |
< |
|
| 744 |
> |
|
| 745 |
|
#ifndef IS_MPI |
| 746 |
|
// set all zAngles to 0.0 |
| 747 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 759 |
|
// first thing first, suspend fatalities. |
| 760 |
|
painCave.isEventLoop = 1; |
| 761 |
|
|
| 746 |
– |
int masterNode = 0; |
| 762 |
|
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 763 |
|
int haveError; |
| 764 |
|
int which_node; |
| 765 |
|
|
| 766 |
< |
MPI_Status istatus; |
| 752 |
< |
|
| 753 |
< |
int nCurObj; |
| 754 |
< |
double angleTranfer; |
| 755 |
< |
|
| 756 |
< |
nTotObjs = info_->getNGlobalIntegrableObjects(); |
| 757 |
< |
haveError = 0; |
| 758 |
< |
if (worldRank == masterNode) { |
| 766 |
> |
haveError = 0; |
| 767 |
|
|
| 768 |
< |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 769 |
< |
// Get the Node number which has this atom |
| 770 |
< |
which_node = info_->getMolToProc(i); |
| 768 |
> |
for (int i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 769 |
> |
|
| 770 |
> |
// Get the Node number which has this atom |
| 771 |
> |
which_node = info_->getMolToProc(i); |
| 772 |
|
|
| 773 |
< |
// let's let node 0 pass out constant values to all the processors |
| 774 |
< |
if (worldRank == masterNode) { |
| 775 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
| 776 |
< |
|
| 777 |
< |
if(mol == NULL) { |
| 778 |
< |
strcpy(painCave.errMsg, "Molecule not found on node 0!"); |
| 779 |
< |
haveError = 1; |
| 780 |
< |
simError(); |
| 781 |
< |
} |
| 782 |
< |
|
| 774 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 775 |
< |
integrableObject != NULL; |
| 776 |
< |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 777 |
< |
|
| 778 |
< |
integrableObject->setZangle( 0.0 ); |
| 779 |
< |
|
| 780 |
< |
} |
| 781 |
< |
|
| 782 |
< |
} else { |
| 783 |
< |
// I am MASTER OF THE UNIVERSE, but I don't own this molecule |
| 784 |
< |
|
| 785 |
< |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
| 786 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 787 |
< |
|
| 788 |
< |
for(j=0; j < nCurObj; j++){ |
| 789 |
< |
angleTransfer = 0.0; |
| 790 |
< |
MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, |
| 791 |
< |
TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); |
| 792 |
< |
|
| 793 |
< |
} |
| 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 |
|
} |
| 795 |
– |
} |
| 796 |
– |
} else { |
| 797 |
– |
// I am SLAVE TO THE MASTER |
| 798 |
– |
for (i=0 ; i < info_->getNGlobalMolecules(); i++) { |
| 799 |
– |
int which_node = info_->getMolToProc(i); |
| 784 |
|
|
| 785 |
< |
if (which_node == worldRank) { |
| 785 |
> |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 786 |
> |
integrableObject != NULL; |
| 787 |
> |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 788 |
|
|
| 789 |
< |
// BUT I OWN THIS MOLECULE!!! |
| 804 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
| 789 |
> |
integrableObject->setZangle( 0.0 ); |
| 790 |
|
|
| 791 |
< |
if(mol == NULL) { |
| 807 |
< |
sprintf(painCave.errMsg, |
| 808 |
< |
"RestReader Error: molecule not found on node %d\n", |
| 809 |
< |
worldRank); |
| 810 |
< |
painCave.isFatal = 1; |
| 811 |
< |
simError(); |
| 812 |
< |
} |
| 813 |
< |
|
| 814 |
< |
nCurObj = mol->getNIntegrableObjects(); |
| 815 |
< |
|
| 816 |
< |
MPI_Send(&nCurObj, 1, MPI_INT, 0, |
| 817 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 818 |
< |
|
| 819 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); |
| 820 |
< |
integrableObject != NULL; |
| 821 |
< |
integrableObject = mol->nextIntegrableObject(ii)){ |
| 822 |
< |
|
| 823 |
< |
MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0, |
| 824 |
< |
TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); |
| 825 |
< |
vecParticles[j]->setZangle(angleTransfer); |
| 826 |
< |
} |
| 827 |
< |
} |
| 791 |
> |
} |
| 792 |
|
} |
| 793 |
|
} |
| 794 |
+ |
|
| 795 |
|
#endif |
| 796 |
|
} |
| 797 |
|
|