--- trunk/src/io/RestReader.cpp 2005/03/10 15:10:24 417 +++ trunk/src/io/RestReader.cpp 2006/06/19 01:36:06 990 @@ -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,7 +68,7 @@ namespace oopse { namespace oopse { RestReader::RestReader( SimInfo* info ) : info_(info){ - + idealName = "idealCrystal.in"; isScanned = false; @@ -93,6 +92,7 @@ namespace oopse { "File \"idealCrystal.in\" opened successfully for reading." ); MPIcheckPoint(); #endif + return; } @@ -122,10 +122,10 @@ namespace oopse { void RestReader :: readIdealCrystal(){ - + int i; unsigned int j; - + #ifdef IS_MPI int done, which_node, which_atom; // loop counter #endif //is_mpi @@ -220,13 +220,13 @@ namespace oopse { 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 ){ @@ -259,19 +259,21 @@ namespace oopse { 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); 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(); } @@ -291,16 +293,18 @@ namespace oopse { 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++){ + for(j = 0; j < nCurObj; j++){ eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile); if(eof_test == NULL){ @@ -313,24 +317,24 @@ namespace oopse { 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 +342,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 +369,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,7 +388,7 @@ namespace oopse { } std::string name = tokenizer.nextToken(); - + if (name != sd->getType()) { sprintf(painCave.errMsg, @@ -401,13 +403,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 +419,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(); @@ -493,7 +495,7 @@ namespace oopse { char *parseErr; std::vector vecParticles; - std::vector tempZangs; + std::vector tempZangs; inAngFileName = info_->getRestFileName(); @@ -594,18 +596,20 @@ namespace oopse { // first thing first, suspend fatalities. painCave.isEventLoop = 1; - + + int masterNode = 0; int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone - int haveError, index; - - int *MolToProcMap = mpiSim->getMolToProcMap(); - int localIndex; + int haveError; + int intObjIndex; + int intObjIndexTransfer; + int nCurObj; - double angleTranfer; + RealType angleTranfer; - 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 ){ @@ -623,7 +627,7 @@ namespace oopse { tempZangs.push_back( atof(read_buffer) ); eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile); } - + // Check to see that the number of integrable objects in the // intial configuration file is the same as derived from the // meta-data file. @@ -636,69 +640,86 @@ namespace oopse { 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->getGlobalIndex(); + 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++) { + int 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->getGlobalIndex(); + // 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 } @@ -732,69 +753,84 @@ namespace oopse { // first thing first, suspend fatalities. painCave.isEventLoop = 1; + int masterNode = 0; 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; + RealType angleTranfer; - nTotObjs = info_->getTotIntegrableObjects(); + nTotObjs = info_->getNGlobalIntegrableObjects(); haveError = 0; - - for (i=0 ; i < mpiSim->getNMolGlobal(); 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, + if (worldRank == masterNode) { + + for (i=0 ; i < info_->getNGlobalMolecules(); i++) { + // Get the Node number which has this atom + which_node = info_->getMolToProc(i); + + // let's let node 0 pass out constant values to all the processors + if (worldRank == 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)){ + + integrableObject->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_REALTYPE, which_node, + TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD); + + } + } + } + } else { + // I am SLAVE TO THE MASTER + for (i=0 ; i < info_->getNGlobalMolecules(); i++) { + int 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(); + } + + nCurObj = mol->getNIntegrableObjects(); + + 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)){ + + MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0, TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus); vecParticles[j]->setZangle(angleTransfer); }