--- trunk/src/io/RestReader.cpp 2005/03/10 15:10:24 417 +++ trunk/src/io/RestReader.cpp 2008/04/25 15:14:47 1241 @@ -60,7 +60,6 @@ #ifdef IS_MPI #include -#include "brains/mpiSimulation.hpp" #define TAKE_THIS_TAG_CHAR 0 #define TAKE_THIS_TAG_INT 1 #define TAKE_THIS_TAG_DOUBLE 2 @@ -69,30 +68,30 @@ namespace oopse { namespace oopse { RestReader::RestReader( SimInfo* info ) : info_(info){ - - idealName = "idealCrystal.in"; - isScanned = false; - + idealName = "idealCrystal.in"; + #ifdef IS_MPI if (worldRank == 0) { #endif - - inIdealFile = fopen(idealName, "r"); - if(inIdealFile == NULL){ + + inIdealFile = new std::ifstream(idealName.c_str()); + + if(inIdealFile->fail()){ sprintf(painCave.errMsg, - "RestReader: Cannot open file: %s\n", idealName); + "RestReader: Cannot open file: %s\n", + idealName.c_str()); painCave.isFatal = 1; simError(); } - inIdealFileName = idealName; #ifdef IS_MPI } strcpy( checkPointMsg, "File \"idealCrystal.in\" opened successfully for reading." ); - MPIcheckPoint(); + errorCheckPoint(); #endif + return; } @@ -100,21 +99,15 @@ namespace oopse { #ifdef IS_MPI if (worldRank == 0) { #endif - int error; - error = fclose( inIdealFile ); - - if( error ){ - sprintf( painCave.errMsg, - "Error closing %s\n", inIdealFileName.c_str()); - simError(); - } - - MemoryUtils::deletePointers(framePos); - + + delete inIdealFile; + delete inAngFile; + #ifdef IS_MPI } - strcpy( checkPointMsg, "Restraint file closed successfully." ); - MPIcheckPoint(); + strcpy( checkPointMsg, + "File idealCrystal.in (and .zang0 if present) closed successfully." ); + errorCheckPoint(); #endif return; @@ -122,19 +115,16 @@ namespace oopse { void RestReader :: readIdealCrystal(){ - - int i; - unsigned int j; - + #ifdef IS_MPI - int done, which_node, which_atom; // loop counter + int which_node; + int i, j; #endif //is_mpi const int BUFFERSIZE = 2000; // size of the read buffer int nTotObjs; // the number of atoms char read_buffer[BUFFERSIZE]; //the line buffer for reading - char *eof_test; // ptr to see when we reach the end of the file char *parseErr; std::vector integrableObjects; @@ -146,11 +136,12 @@ namespace oopse { #ifndef IS_MPI - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); - if( eof_test == NULL ){ + inIdealFile->getline(read_buffer, sizeof(read_buffer)); + + if( inIdealFile->eof() ){ sprintf( painCave.errMsg, "RestraintReader error: error reading 1st line of \"%s\"\n", - inIdealFileName.c_str() ); + idealName.c_str() ); painCave.isFatal = 1; simError(); } @@ -161,17 +152,20 @@ namespace oopse { sprintf( painCave.errMsg, "RestraintReader error. %s nIntegrable, %d, " "does not match the meta-data file's nIntegrable, %d.\n", - inIdealFileName.c_str(), nTotObjs, + idealName.c_str(), + nTotObjs, info_->getNGlobalIntegrableObjects()); painCave.isFatal = 1; simError(); } // skip over the comment line - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); - if(eof_test == NULL){ + inIdealFile->getline(read_buffer, sizeof(read_buffer)); + + if( inIdealFile->eof() ){ sprintf( painCave.errMsg, - "error in reading commment in %s\n", inIdealFileName.c_str()); + "error in reading commment in %s\n", + idealName.c_str()); painCave.isFatal = 1; simError(); } @@ -188,14 +182,15 @@ namespace oopse { for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; integrableObject = mol->nextIntegrableObject(ii)) { - - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); - if(eof_test == NULL){ + + inIdealFile->getline(read_buffer, sizeof(read_buffer)); + + if( inIdealFile->eof() ){ sprintf(painCave.errMsg, "RestReader Error: error in reading file %s\n" "natoms = %d; index = %d\n" "error reading the line from the file.\n", - inIdealFileName.c_str(), nTotObjs, + idealName.c_str(), nTotObjs, integrableObject->getGlobalIndex() ); painCave.isFatal = 1; simError(); @@ -217,21 +212,21 @@ namespace oopse { painCave.isEventLoop = 1; int masterNode = 0; - int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone MPI_Status istatus; - int localIndex; int nCurObj; int nitems; - - nTotObjs = info_->getTotIntegrableObjects(); + int haveError; + + nTotObjs = info_->getNGlobalIntegrableObjects(); haveError = 0; - + if (worldRank == masterNode) { - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); - if( eof_test == NULL ){ + inIdealFile->getline(read_buffer, sizeof(read_buffer)); + + if( inIdealFile->eof() ){ sprintf( painCave.errMsg, - "Error reading 1st line of %s \n ",inIdealFileName.c_str()); + "Error reading 1st line of %s \n ",idealName.c_str()); painCave.isFatal = 1; simError(); } @@ -245,33 +240,36 @@ namespace oopse { sprintf( painCave.errMsg, "RestraintReader Error. %s nIntegrable, %d, " "does not match the meta-data file's nIntegrable, %d.\n", - inIdealFileName.c_str(), nTotObjs, + idealName.c_str(), nTotObjs, info_->getNGlobalIntegrableObjects()); painCave.isFatal = 1; simError(); } // skip over the comment line - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); - if(eof_test == NULL){ + inIdealFile->getline(read_buffer, sizeof(read_buffer)); + + if( inIdealFile->eof() ){ sprintf( painCave.errMsg, - "error in reading commment in %s\n", inIdealFileName.c_str()); + "error in reading commment in %s\n", idealName.c_str()); painCave.isFatal = 1; simError(); } - + + MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, MPI_COMM_WORLD); + for (i=0 ; i < info_->getNGlobalMolecules(); i++) { - int which_node = info_->getMolToProc(i); + which_node = info_->getMolToProc(i); if(which_node == masterNode){ //molecules belong to master node - localIndex = info_->getMoleculeByGlobalIndex(i); + mol = info_->getMoleculeByGlobalIndex(i); - if(localIndex == NULL) { - strcpy(painCave.errMsg, - "RestReader Error: Molecule not found on node %d!", - worldRank); + if(mol == NULL) { + sprintf(painCave.errMsg, + "RestReader Error: Molecule not found on node %d!\n", + worldRank); painCave.isFatal = 1; simError(); } @@ -280,57 +278,59 @@ namespace oopse { integrableObject != NULL; integrableObject = mol->nextIntegrableObject(ii)){ - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); + inIdealFile->getline(read_buffer, sizeof(read_buffer)); - if(eof_test == NULL){ + if( inIdealFile->eof() ){ sprintf(painCave.errMsg, "RestReader Error: error in reading file %s\n" "natoms = %d; index = %d\n" "error reading the line from the file.\n", - inIdealFileName.c_str(), nTotObjs, i ); + idealName.c_str(), nTotObjs, i ); painCave.isFatal = 1; simError(); } - - parseIdealLine(read_buffer, integrableObjects[j]); + + parseIdealLine(read_buffer, integrableObject); + } + } else { //molecule belongs to slave nodes MPI_Recv(&nCurObj, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); - for(j=0; j < nCurObj; j++){ - - eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); - if(eof_test == NULL){ + for(j = 0; j < nCurObj; j++){ + inIdealFile->getline(read_buffer, sizeof(read_buffer)); + + if( inIdealFile->eof() ){ sprintf(painCave.errMsg, "RestReader Error: error in reading file %s\n" "natoms = %d; index = %d\n" "error reading the line from the file.\n", - inIdealFileName.c_str(), nTotObjs, i ); + idealName.c_str(), nTotObjs, i ); painCave.isFatal = 1; simError(); } - if(haveError) nodeZeroError(); - - MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, + MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); } } } } else { - //actions taken at slave nodes + //actions taken at slave nodes + MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, masterNode, MPI_COMM_WORLD); + for (i=0 ; i < info_->getNGlobalMolecules(); i++) { - int which_node = info_->getMolToProc(i); - + int which_node = info_->getMolToProc(i); + if(which_node == worldRank){ //molecule with global index i belongs to this processor - localIndex = info_->getMoleculeByGlobalIndex(i); + mol = info_->getMoleculeByGlobalIndex(i); - if(localIndex == NULL) { + if(mol == NULL) { sprintf(painCave.errMsg, "RestReader Error: molecule not found on node %d\n", worldRank); @@ -338,7 +338,7 @@ namespace oopse { simError(); } - nCurObj = localIndex->getNIntegrableObjects(); + nCurObj = mol->getNIntegrableObjects(); MPI_Send(&nCurObj, 1, MPI_INT, masterNode, TAKE_THIS_TAG_INT, MPI_COMM_WORLD); @@ -365,19 +365,17 @@ namespace oopse { char* RestReader::parseIdealLine(char* readLine, StuntDouble* sd){ - char *foo; // the pointer to the current string token - - double pos[3]; // position place holders - double q[4]; // the quaternions - double RfromQ[3][3]; // the rotation matrix - double normalize; // to normalize the reference unit vector - double uX, uY, uZ; // reference unit vector place holders - double uselessToken; + RealType pos[3]; // position place holders + RealType q[4]; // the quaternions + RealType RfromQ[3][3]; // the rotation matrix + RealType normalize; // to normalize the reference unit vector + RealType uX, uY, uZ; // reference unit vector place holders + RealType uselessToken; StringTokenizer tokenizer(readLine); int nTokens; nTokens = tokenizer.countTokens(); - + if (nTokens < 14) { sprintf(painCave.errMsg, "RestReader Error: Not enough Tokens.\n"); @@ -386,13 +384,13 @@ namespace oopse { } std::string name = tokenizer.nextToken(); - + if (name != sd->getType()) { sprintf(painCave.errMsg, "RestReader Error: Atom type [%s] in %s does not " "match Atom Type [%s] in .md file.\n", - name.c_str(), inIdealFileName.c_str(), + name.c_str(), idealName.c_str(), sd->getType().c_str()); painCave.isFatal = 1; simError(); @@ -401,13 +399,13 @@ namespace oopse { pos[0] = tokenizer.nextTokenAsDouble(); pos[1] = tokenizer.nextTokenAsDouble(); pos[2] = tokenizer.nextTokenAsDouble(); - + // store the positions in the stuntdouble as generic data doubles DoubleGenericData* refPosX = new DoubleGenericData(); refPosX->setID("refPosX"); refPosX->setData(pos[0]); sd->addProperty(refPosX); - + DoubleGenericData* refPosY = new DoubleGenericData(); refPosY->setID("refPosY"); refPosY->setData(pos[1]); @@ -417,7 +415,7 @@ namespace oopse { refPosZ->setID("refPosZ"); refPosZ->setData(pos[2]); sd->addProperty(refPosZ); - + // we don't need the velocities uselessToken = tokenizer.nextTokenAsDouble(); uselessToken = tokenizer.nextTokenAsDouble(); @@ -471,7 +469,6 @@ namespace oopse { void RestReader::readZangle(){ int i; - unsigned int j; int isPresent; Molecule* mol; @@ -480,39 +477,37 @@ namespace oopse { Molecule::IntegrableObjectIterator ii; #ifdef IS_MPI - int done, which_node, which_atom; // loop counter - int nProc; + int which_node; MPI_Status istatus; #endif //is_mpi const int BUFFERSIZE = 2000; // size of the read buffer - int nTotObjs; // the number of atoms + unsigned int nTotObjs; // the number of atoms char read_buffer[BUFFERSIZE]; //the line buffer for reading - char *eof_test; // ptr to see when we reach the end of the file - char *parseErr; - std::vector vecParticles; - std::vector tempZangs; + std::vector tempZangs; - inAngFileName = info_->getRestFileName(); + angFile = info_->getRestFileName(); - inAngFileName += "0"; + angFile += "0"; // open the omega value file for reading #ifdef IS_MPI if (worldRank == 0) { #endif isPresent = 1; - inAngFile = fopen(inAngFileName.c_str(), "r"); - if(!inAngFile){ + + inAngFile = new std::ifstream(angFile.c_str()); + + if(inAngFile->fail()){ sprintf(painCave.errMsg, "Restraints Warning: %s file is not present\n" "\tAll omega values will be initialized to zero. If the\n" "\tsimulation is starting from the idealCrystal.in reference\n" "\tconfiguration, this is the desired action. If this is not\n" "\tthe case, the energy calculations will be incorrect.\n", - inAngFileName.c_str()); + angFile.c_str()); painCave.severity = OOPSE_WARNING; painCave.isFatal = 0; simError(); @@ -530,6 +525,12 @@ namespace oopse { } #ifdef IS_MPI + if (!isPresent) { + // master node zeroes out its zAngles if .zang0 isn't present + zeroZangle(); + return; + } + } // listen to node 0 to see if we should exit this function @@ -542,26 +543,31 @@ namespace oopse { } strcpy( checkPointMsg, "zAngle file opened successfully for reading." ); - MPIcheckPoint(); + errorCheckPoint(); #endif #ifndef IS_MPI - eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); - if( eof_test == NULL ){ + // read the first line and die if there is a failure + inAngFile->getline(read_buffer, sizeof(read_buffer)); + + if( inAngFile->eof() ){ sprintf( painCave.errMsg, "RestraintReader error: error reading 1st line of \"%s\"\n", - inAngFileName.c_str() ); + angFile.c_str() ); painCave.isFatal = 1; simError(); } + + // read the file and load the values into a vector + inAngFile->getline(read_buffer, sizeof(read_buffer)); - eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); - while ( eof_test != NULL ) { + while ( !inAngFile->eof() ) { // check for and ignore blank lines if ( read_buffer != NULL ) tempZangs.push_back( atof(read_buffer) ); - eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); + + inAngFile->getline(read_buffer, sizeof(read_buffer)); } nTotObjs = info_->getNGlobalIntegrableObjects(); @@ -569,8 +575,10 @@ namespace oopse { if( nTotObjs != tempZangs.size() ){ sprintf( painCave.errMsg, "RestraintReader zAngle reading error. %s nIntegrable, %d, " - "does not match the meta-data file's nIntegrable, %d.\n", - inAngFileName.c_str(), tempZangs.size(), nTotObjs ); + "does not match the meta-data file's nIntegrable, %i.\n", + angFile.c_str(), + tempZangs.size(), + nTotObjs ); painCave.isFatal = 1; simError(); } @@ -594,36 +602,42 @@ namespace oopse { // first thing first, suspend fatalities. painCave.isEventLoop = 1; - - int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone - int haveError, index; - - int *MolToProcMap = mpiSim->getMolToProcMap(); - int localIndex; + + int masterNode = 0; + + int haveError; + int intObjIndex; + int intObjIndexTransfer; + + int j; int nCurObj; - double angleTranfer; + RealType angleTransfer; - nTotObjs = info_->getTotIntegrableObjects(); + nTotObjs = info_->getNGlobalIntegrableObjects(); haveError = 0; - if (worldRank == 0) { + + if (worldRank == masterNode) { - eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); - if( eof_test == NULL ){ + inAngFile->getline(read_buffer, sizeof(read_buffer)); + + if( inAngFile->eof() ){ sprintf( painCave.errMsg, - "Error reading 1st line of %s \n ",inAngFileName.c_str()); + "Error reading 1st line of %s \n ",angFile.c_str()); haveError = 1; simError(); } - // let node 0 load the temporary angle vector - eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); - while ( eof_test != NULL ) { + // let the master node read the file and load the temporary angle vector + inAngFile->getline(read_buffer, sizeof(read_buffer)); + + while ( !inAngFile->eof() ) { // check for and ignore blank lines if ( read_buffer != NULL ) tempZangs.push_back( atof(read_buffer) ); - eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); + + inAngFile->getline(read_buffer, sizeof(read_buffer)); } - + // Check to see that the number of integrable objects in the // intial configuration file is the same as derived from the // meta-data file. @@ -631,90 +645,103 @@ namespace oopse { sprintf( painCave.errMsg, "RestraintReader zAngle reading Error. %s nIntegrable, %d, " "does not match the meta-data file's nIntegrable, %d.\n", - inAngFileName.c_str(), tempZangs.size(), nTotObjs); + angFile.c_str(), + tempZangs.size(), + nTotObjs); haveError= 1; simError(); } - } - // At this point, node 0 has a tempZangs vector completed, and - // everyone else has nada - index = 0; - - for (i=0 ; i < mpiSim->getNMolGlobal(); i++) { - // Get the Node number which has this atom - which_node = MolToProcMap[i]; + // At this point, node 0 has a tempZangs vector completed, and + // everyone else has nada - if (worldRank == 0) { - if (which_node == 0) { - localIndex = mpiSim->getGlobalToLocalMol(i); - - if(localIndex == -1) { - strcpy(painCave.errMsg, "Molecule not found on node 0!"); - haveError = 1; + for (i=0 ; i < info_->getNGlobalMolecules(); i++) { + // Get the Node number which has this atom + which_node = info_->getMolToProc(i); + + if (which_node == masterNode) { + mol = info_->getMoleculeByGlobalIndex(i); + + if(mol == NULL) { + strcpy(painCave.errMsg, "Molecule not found on node 0!"); + haveError = 1; + simError(); + } + + for (integrableObject = mol->beginIntegrableObject(ii); + integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(ii)){ + intObjIndex = integrableObject->getGlobalIntegrableObjectIndex(); + integrableObject->setZangle(tempZangs[intObjIndex]); + } + + } else { + // I am MASTER OF THE UNIVERSE, but I don't own this molecule + // listen for the number of integrableObjects in the molecule + MPI_Recv(&nCurObj, 1, MPI_INT, which_node, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + + for(j=0; j < nCurObj; j++){ + // listen for which integrableObject we need to send the value for + MPI_Recv(&intObjIndexTransfer, 1, MPI_INT, which_node, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + angleTransfer = tempZangs[intObjIndexTransfer]; + // send the value to the node so it can initialize the object + MPI_Send(&angleTransfer, 1, MPI_REALTYPE, which_node, + TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); + } + } + } + } else { + // I am SLAVE TO THE MASTER + for (i=0 ; i < info_->getNGlobalMolecules(); i++) { + which_node = info_->getMolToProc(i); + + if (which_node == worldRank) { + + // BUT I OWN THIS MOLECULE!!! + + mol = info_->getMoleculeByGlobalIndex(i); + + if(mol == NULL) { + sprintf(painCave.errMsg, + "RestReader Error: molecule not found on node %d\n", + worldRank); + painCave.isFatal = 1; simError(); } - - vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); - for(j = 0; j < vecParticles.size(); j++){ - vecParticles[j]->setZangle(tempZangs[index]); - index++; - } - - } else { - // I am MASTER OF THE UNIVERSE, but I don't own this molecule - - MPI_Recv(&nCurObj, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); - - for(j=0; j < nCurObj; j++){ - angleTransfer = tempZangs[index]; - MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, - TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); - index++; - } - - } - - } else { - // I am SLAVE TO THE MASTER - - if (which_node == worldRank) { - - // BUT I OWN THIS MOLECULE!!! - - localIndex = mpiSim->getGlobalToLocalMol(i); - vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); - nCurObj = vecParticles.size(); - - MPI_Send(&nCurObj, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - - for(j = 0; j < vecParticles.size(); j++){ - - MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0, - TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); - vecParticles[j]->setZangle(angleTransfer); - } - } + + nCurObj = mol->getNIntegrableObjects(); + // send the number of integrableObjects in the molecule + MPI_Send(&nCurObj, 1, MPI_INT, 0, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + + for (integrableObject = mol->beginIntegrableObject(ii); + integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(ii)){ + intObjIndexTransfer = integrableObject->getGlobalIntegrableObjectIndex(); + // send the global index of the integrableObject + MPI_Send(&intObjIndexTransfer, 1, MPI_INT, 0, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + // listen for the value we want to set locally + MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0, + TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); + + integrableObject->setZangle(angleTransfer); + } + } } - } + } #endif } void RestReader :: zeroZangle(){ - int i; - unsigned int j; - int nTotObjs; // the number of atoms - Molecule* mol; StuntDouble* integrableObject; SimInfo::MoleculeIterator mi; Molecule::IntegrableObjectIterator ii; - - std::vector vecParticles; - + #ifndef IS_MPI // set all zAngles to 0.0 for (mol = info_->beginMolecule(mi); mol != NULL; @@ -733,74 +760,38 @@ namespace oopse { painCave.isEventLoop = 1; int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone - int haveError, index; + int haveError; int which_node; - MPI_Status istatus; - int *MolToProcMap = mpiSim->getMolToProcMap(); - int localIndex; - int nCurObj; - double angleTranfer; - - nTotObjs = info_->getTotIntegrableObjects(); haveError = 0; - - for (i=0 ; i < mpiSim->getNMolGlobal(); i++) { + + for (int i=0 ; i < info_->getNGlobalMolecules(); i++) { + // Get the Node number which has this atom - which_node = MolToProcMap[i]; - - // let's let node 0 pass out constant values to all the processors - if (worldRank == 0) { - if (which_node == 0) { - localIndex = mpiSim->getGlobalToLocalMol(i); - - if(localIndex == -1) { - strcpy(painCave.errMsg, "Molecule not found on node 0!"); - haveError = 1; - simError(); - } - - vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); - for(j = 0; j < vecParticles.size(); j++){ - vecParticles[j]->setZangle( 0.0 ); - } - - } else { - // I am MASTER OF THE UNIVERSE, but I don't own this molecule - - MPI_Recv(&nCurObj, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); - - for(j=0; j < nCurObj; j++){ - angleTransfer = 0.0; - MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, - TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); - index++; - } - } - } else { - // I am SLAVE TO THE MASTER - - if (which_node == worldRank) { - - // BUT I OWN THIS MOLECULE!!! - - localIndex = mpiSim->getGlobalToLocalMol(i); - vecParticles = (info_->molecules[localIndex]).getIntegrableObjects(); - nCurObj = vecParticles.size(); - - MPI_Send(&nCurObj, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - - for(j = 0; j < vecParticles.size(); j++){ - - MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0, - TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); - vecParticles[j]->setZangle(angleTransfer); - } - } + which_node = info_->getMolToProc(i); + + // each processor zeroes its own integrable objects + if (which_node == worldRank) { + mol = info_->getMoleculeByGlobalIndex(i); + + if(mol == NULL) { + sprintf( painCave.errMsg, + "Molecule not found on node %i!", + which_node ); + haveError = 1; + simError(); + } + + for (integrableObject = mol->beginIntegrableObject(ii); + integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(ii)){ + + integrableObject->setZangle( 0.0 ); + + } } } + #endif }