--- trunk/OOPSE/libmdtools/DumpWriter.cpp 2004/01/30 21:47:22 1000 +++ trunk/OOPSE/libmdtools/DumpWriter.cpp 2004/06/07 14:26:33 1252 @@ -1,3 +1,4 @@ +#define _LARGEFILE_SOURCE64 #define _FILE_OFFSET_BITS 64 #include @@ -87,12 +88,11 @@ void DumpWriter::sortByGlobalIndex(){ */ void DumpWriter::sortByGlobalIndex(){ - Atom** atoms = entry_plug->atoms; - + Molecule* mols = entry_plug->molecules; indexArray.clear(); - for(int i = 0; i < mpiSim->getMyNlocal();i++) - indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex())); + for(int i = 0; i < entry_plug->n_mol;i++) + indexArray.push_back(make_pair(i, mols[i].getGlobalIndex())); sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); } @@ -170,7 +170,8 @@ void DumpWriter::writeFrame( vector& outFil char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; - int i, k; + int i; + unsigned int k; #ifdef IS_MPI @@ -216,25 +217,27 @@ void DumpWriter::writeFrame( vector& outFil int nProc; int j, which_node, done, which_atom, local_index, currentIndex; - double atomData6[6]; - double atomData13[13]; + double atomData[13]; int isDirectional; char* atomTypeString; char MPIatomTypeString[MINIBUFFERSIZE]; - -#else //is_mpi - int nAtoms = entry_plug->n_atoms; + int nObjects; + int msgLen; // the length of message actually recieved at master nodes #endif //is_mpi - double q[4]; - DirectionalAtom* dAtom; - Atom** atoms = entry_plug->atoms; + double q[4], ji[3]; + DirectionalAtom* dAtom; double pos[3], vel[3]; - + int nTotObjects; + StuntDouble* sd; + char* molName; + vector integrableObjects; + vector::iterator iter; + nTotObjects = entry_plug->getTotIntegrableObjects(); #ifndef IS_MPI for(k = 0; k < outFile.size(); k++){ - *outFile[k] << nAtoms << "\n"; + *outFile[k] << nTotObjects << "\n"; *outFile[k] << currentTime << ";\t" << entry_plug->Hmat[0][0] << "\t" @@ -253,44 +256,51 @@ void DumpWriter::writeFrame( vector& outFil *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl; } - for( i=0; in_mol; i++ ){ - atoms[i]->getPos(pos); - atoms[i]->getVel(vel); + integrableObjects = entry_plug->molecules[i].getIntegrableObjects(); + molName = (entry_plug->compStamps[entry_plug->molecules[i].getStampID()])->getID(); + + for( iter = integrableObjects.begin();iter != integrableObjects.end(); ++iter){ + sd = *iter; + sd->getPos(pos); + sd->getVel(vel); - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[i]->getType(), - pos[0], - pos[1], - pos[2], - vel[0], - vel[1], - vel[2]); - strcpy( writeLine, tempBuffer ); + sprintf( tempBuffer, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + sd->getType(), + pos[0], + pos[1], + pos[2], + vel[0], + vel[1], + vel[2]); + strcpy( writeLine, tempBuffer ); - if( atoms[i]->isDirectional() ){ + if( sd->isDirectional() ){ - dAtom = (DirectionalAtom *)atoms[i]; - dAtom->getQ( q ); + sd->getQ( q ); + sd->getJ( ji ); - sprintf( tempBuffer, - "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - q[0], - q[1], - q[2], - q[3], - dAtom->getJx(), - dAtom->getJy(), - dAtom->getJz()); - strcat( writeLine, tempBuffer ); + sprintf( tempBuffer, + "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + q[0], + q[1], + q[2], + q[3], + ji[0], + ji[1], + ji[2]); + strcat( writeLine, tempBuffer ); + } + else + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + + for(k = 0; k < outFile.size(); k++) + *outFile[k] << writeLine; } - else - strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - for(k = 0; k < outFile.size(); k++) - *outFile[k] << writeLine; - } +} #else // is_mpi @@ -307,7 +317,8 @@ void DumpWriter::writeFrame( vector& outFil int haveError; MPI_Status istatus; - int *AtomToProcMap = mpiSim->getAtomToProcMap(); + int nCurObj; + int *MolToProcMap = mpiSim->getMolToProcMap(); // write out header and node 0's coordinates @@ -315,7 +326,7 @@ void DumpWriter::writeFrame( vector& outFil // Node 0 needs a list of the magic potatoes for each processor; - nProc = mpiSim->getNumberProcessors(); + nProc = mpiSim->getNProcessors(); potatoes = new int[nProc]; //write out the comment lines @@ -323,7 +334,7 @@ void DumpWriter::writeFrame( vector& outFil potatoes[i] = 0; for(k = 0; k < outFile.size(); k++){ - *outFile[k] << mpiSim->getTotAtoms() << "\n"; + *outFile[k] << nTotObjects << "\n"; *outFile[k] << currentTime << ";\t" << entry_plug->Hmat[0][0] << "\t" @@ -343,144 +354,196 @@ void DumpWriter::writeFrame( vector& outFil currentIndex = 0; - for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { + for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) { // Get the Node number which has this atom; - which_node = AtomToProcMap[i]; + which_node = MolToProcMap[i]; if (which_node != 0) { - - if (potatoes[which_node] + 3 >= MAXTAG) { + + if (potatoes[which_node] + 1 >= MAXTAG) { // The potato was going to exceed the maximum value, // so wrap this processor potato back to 0: potatoes[which_node] = 0; - MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); + MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); } myPotato = potatoes[which_node]; - - MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, - myPotato, MPI_COMM_WORLD, &istatus); - - atomTypeString = MPIatomTypeString; - - myPotato++; - MPI_Recv(&isDirectional, 1, MPI_INT, which_node, + //recieve the number of integrableObject in current molecule + MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, MPI_COMM_WORLD, &istatus); - myPotato++; - - if (isDirectional) { - MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node, - myPotato, MPI_COMM_WORLD, &istatus); - } else { - MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node, - myPotato, MPI_COMM_WORLD, &istatus); - } - myPotato++; - potatoes[which_node] = myPotato; - - } else { - - haveError = 0; - which_atom = i; - - local_index = indexArray[currentIndex].first; - - if (which_atom == indexArray[currentIndex].second) { - - atomTypeString = atoms[local_index]->getType(); - - atoms[local_index]->getPos(pos); - atoms[local_index]->getVel(vel); - - atomData6[0] = pos[0]; - atomData6[1] = pos[1]; - atomData6[2] = pos[2]; + for(int l = 0; l < nCurObj; l++){ - atomData6[3] = vel[0]; - atomData6[4] = vel[1]; - atomData6[5] = vel[2]; - - isDirectional = 0; + if (potatoes[which_node] + 2 >= MAXTAG) { + // The potato was going to exceed the maximum value, + // so wrap this processor potato back to 0: - if( atoms[local_index]->isDirectional() ){ + potatoes[which_node] = 0; + MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); + + } + MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, + myPotato, MPI_COMM_WORLD, &istatus); + + atomTypeString = MPIatomTypeString; + + myPotato++; + + MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, MPI_COMM_WORLD, &istatus); + myPotato++; + + MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); + + if(msgLen == 13) isDirectional = 1; + else + isDirectional = 0; + + // If we've survived to here, format the line: - dAtom = (DirectionalAtom *)atoms[local_index]; - dAtom->getQ( q ); - - for (int j = 0; j < 6 ; j++) - atomData13[j] = atomData6[j]; + if (!isDirectional) { + + sprintf( writeLine, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + atomTypeString, + atomData[0], + atomData[1], + atomData[2], + atomData[3], + atomData[4], + atomData[5]); + + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + + } + else { + + sprintf( writeLine, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + atomTypeString, + atomData[0], + atomData[1], + atomData[2], + atomData[3], + atomData[4], + atomData[5], + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11], + atomData[12]); - atomData13[6] = q[0]; - atomData13[7] = q[1]; - atomData13[8] = q[2]; - atomData13[9] = q[3]; - - atomData13[10] = dAtom->getJx(); - atomData13[11] = dAtom->getJy(); - atomData13[12] = dAtom->getJz(); } - } else { - sprintf(painCave.errMsg, - "Atom %d not found on processor %d, currentIndex = %d, local_index = %d\n", - which_atom, worldRank, currentIndex, local_index ); - haveError= 1; - simError(); - } + for(k = 0; k < outFile.size(); k++) + *outFile[k] << writeLine; + + }// end for(int l =0) + potatoes[which_node] = myPotato; + + } + else { - if(haveError) DieDieDie(); + haveError = 0; - currentIndex++; - } - // If we've survived to here, format the line: - - if (!isDirectional) { - - sprintf( writeLine, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atomTypeString, - atomData6[0], - atomData6[1], - atomData6[2], - atomData6[3], - atomData6[4], - atomData6[5]); - - strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - - } else { - - sprintf( writeLine, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - atomTypeString, - atomData13[0], - atomData13[1], - atomData13[2], - atomData13[3], - atomData13[4], - atomData13[5], - atomData13[6], - atomData13[7], - atomData13[8], - atomData13[9], - atomData13[10], - atomData13[11], - atomData13[12]); + local_index = indexArray[currentIndex].first; + + integrableObjects = (entry_plug->molecules[local_index]).getIntegrableObjects(); + + for(iter= integrableObjects.begin(); iter != integrableObjects.end(); ++iter){ + sd = *iter; + atomTypeString = sd->getType(); + + sd->getPos(pos); + sd->getVel(vel); + + atomData[0] = pos[0]; + atomData[1] = pos[1]; + atomData[2] = pos[2]; + + atomData[3] = vel[0]; + atomData[4] = vel[1]; + atomData[5] = vel[2]; + + isDirectional = 0; + + if( sd->isDirectional() ){ + + isDirectional = 1; + + sd->getQ( q ); + sd->getJ( ji ); + + for (int j = 0; j < 6 ; j++) + atomData[j] = atomData[j]; + + atomData[6] = q[0]; + atomData[7] = q[1]; + atomData[8] = q[2]; + atomData[9] = q[3]; + + atomData[10] = ji[0]; + atomData[11] = ji[1]; + atomData[12] = ji[2]; + } + + // If we've survived to here, format the line: + + if (!isDirectional) { + + sprintf( writeLine, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + atomTypeString, + atomData[0], + atomData[1], + atomData[2], + atomData[3], + atomData[4], + atomData[5]); + + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + + } + else { + + sprintf( writeLine, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + atomTypeString, + atomData[0], + atomData[1], + atomData[2], + atomData[3], + atomData[4], + atomData[5], + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11], + atomData[12]); + + } + + for(k = 0; k < outFile.size(); k++) + *outFile[k] << writeLine; + + + }//end for(iter = integrableObject.begin()) + currentIndex++; } - - for(k = 0; k < outFile.size(); k++) - *outFile[k] << writeLine; - } + + }//end for(i = 0; i < mpiSim->getNmol()) for(k = 0; k < outFile.size(); k++) outFile[k]->flush(); @@ -501,13 +564,14 @@ void DumpWriter::writeFrame( vector& outFil myPotato = 0; currentIndex = 0; - for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { + for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) { - // Am I the node which has this atom? + // Am I the node which has this integrableObject? - if (AtomToProcMap[i] == worldRank) { + if (MolToProcMap[i] == worldRank) { - if (myPotato + 3 >= MAXTAG) { + + if (myPotato + 1 >= MAXTAG) { // The potato was going to exceed the maximum value, // so wrap this processor potato back to 0 (and block until @@ -516,91 +580,102 @@ void DumpWriter::writeFrame( vector& outFil MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); } - which_atom = i; - local_index = indexArray[currentIndex].first; - - if (which_atom == indexArray[currentIndex].second) { - - atomTypeString = atoms[local_index]->getType(); - - atoms[local_index]->getPos(pos); - atoms[local_index]->getVel(vel); - - atomData6[0] = pos[0]; - atomData6[1] = pos[1]; - atomData6[2] = pos[2]; - - atomData6[3] = vel[0]; - atomData6[4] = vel[1]; - atomData6[5] = vel[2]; + local_index = indexArray[currentIndex].first; + integrableObjects = entry_plug->molecules[local_index].getIntegrableObjects(); - isDirectional = 0; + nCurObj = integrableObjects.size(); + + MPI_Send(&nCurObj, 1, MPI_INT, 0, + myPotato, MPI_COMM_WORLD); + myPotato++; - if( atoms[local_index]->isDirectional() ){ + for( iter = integrableObjects.begin(); iter != integrableObjects.end(); iter++){ - isDirectional = 1; + if (myPotato + 2 >= MAXTAG) { + + // The potato was going to exceed the maximum value, + // so wrap this processor potato back to 0 (and block until + // node 0 says we can go: + + MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); + + } - dAtom = (DirectionalAtom *)atoms[local_index]; - dAtom->getQ( q ); + sd = *iter; - for (int j = 0; j < 6 ; j++) - atomData13[j] = atomData6[j]; + atomTypeString = sd->getType(); + + sd->getPos(pos); + sd->getVel(vel); + + atomData[0] = pos[0]; + atomData[1] = pos[1]; + atomData[2] = pos[2]; + + atomData[3] = vel[0]; + atomData[4] = vel[1]; + atomData[5] = vel[2]; + + isDirectional = 0; + + if( sd->isDirectional() ){ + + isDirectional = 1; + + sd->getQ( q ); + sd->getJ( ji ); + + + atomData[6] = q[0]; + atomData[7] = q[1]; + atomData[8] = q[2]; + atomData[9] = q[3]; + + atomData[10] = ji[0]; + atomData[11] = ji[1]; + atomData[12] = ji[2]; + } + + + strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); + + // null terminate the string before sending (just in case): + MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; + + MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, + myPotato, MPI_COMM_WORLD); - atomData13[6] = q[0]; - atomData13[7] = q[1]; - atomData13[8] = q[2]; - atomData13[9] = q[3]; - - atomData13[10] = dAtom->getJx(); - atomData13[11] = dAtom->getJy(); - atomData13[12] = dAtom->getJz(); - } + myPotato++; + + if (isDirectional) { - } else { - sprintf(painCave.errMsg, - "Atom %d not found on processor %d, currentIndex = %d, local_index = %d\n", - which_atom, worldRank, currentIndex, local_index ); - haveError= 1; - simError(); - } - - strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); + MPI_Send(atomData, 13, MPI_DOUBLE, 0, + myPotato, MPI_COMM_WORLD); + + } else { - // null terminate the string before sending (just in case): - MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; + MPI_Send(atomData, 6, MPI_DOUBLE, 0, + myPotato, MPI_COMM_WORLD); + } - MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, - myPotato, MPI_COMM_WORLD); - - myPotato++; + myPotato++; - MPI_Send(&isDirectional, 1, MPI_INT, 0, - myPotato, MPI_COMM_WORLD); - - myPotato++; - - if (isDirectional) { + } - MPI_Send(atomData13, 13, MPI_DOUBLE, 0, - myPotato, MPI_COMM_WORLD); + currentIndex++; - } else { - - MPI_Send(atomData6, 6, MPI_DOUBLE, 0, - myPotato, MPI_COMM_WORLD); } - - myPotato++; - currentIndex++; + } - } sprintf( checkPointMsg, "Sucessfully took a dump.\n"); - MPIcheckPoint(); + MPIcheckPoint(); - } + } + + #endif // is_mpi }