ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimCreator.cpp
(Generate patch)

Comparing branches/development/src/brains/SimCreator.cpp (file contents):
Revision 1593 by gezelter, Fri Jul 15 21:35:14 2011 UTC vs.
Revision 1613 by gezelter, Thu Aug 18 20:18:19 2011 UTC

# Line 81 | Line 81 | namespace OpenMD {
81  
82   namespace OpenMD {
83    
84 <  Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int startOfMetaDataBlock ){
84 >  Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int mdFileVersion, int startOfMetaDataBlock ){
85      Globals* simParams = NULL;
86      try {
87  
# Line 92 | Line 92 | namespace OpenMD {
92        const int masterNode = 0;
93        int commStatus;
94        if (worldRank == masterNode) {
95 < #endif
96 <                
95 >        commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
96 > #endif                
97          SimplePreprocessor preprocessor;
98          preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream);
99                  
# Line 106 | Line 106 | namespace OpenMD {
106              
107                  
108        } else {
109 +
110 +        commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
111 +
112          //get stream size
113          commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD);  
114  
# Line 229 | Line 232 | namespace OpenMD {
232        simError();
233      }
234  
235 +    simParams->setMDfileVersion(mdFileVersion);
236      return simParams;
237    }
238    
# Line 243 | Line 247 | namespace OpenMD {
247      int metaDataBlockEnd = -1;
248      int i;
249      int mdOffset;
250 +    int mdFileVersion;
251  
252   #ifdef IS_MPI            
253      const int masterNode = 0;
# Line 276 | Line 281 | namespace OpenMD {
281          painCave.isFatal = 1;
282          simError();
283        }
284 +      
285 +      // found the correct opening string, now try to get the file
286 +      // format version number.
287 +
288 +      StringTokenizer tokenizer(line, "=<> \t\n\r");
289 +      std::string fileType = tokenizer.nextToken();
290 +      toUpper(fileType);
291 +
292 +      mdFileVersion = 0;
293  
294 +      if (fileType == "OPENMD") {
295 +        while (tokenizer.hasMoreTokens()) {
296 +          std::string token(tokenizer.nextToken());
297 +          toUpper(token);
298 +          if (token == "VERSION") {
299 +            mdFileVersion = tokenizer.nextTokenAsInt();
300 +            break;
301 +          }
302 +        }
303 +      }
304 +            
305        //scan through the input stream and find MetaData tag        
306        while(mdFile_.getline(buffer, bufferSize)) {
307          ++lineNo;
# Line 332 | Line 357 | namespace OpenMD {
357      std::stringstream rawMetaDataStream(mdRawData);
358  
359      //parse meta-data file
360 <    Globals* simParams = parseFile(rawMetaDataStream, mdFileName, metaDataBlockStart+1);
360 >    Globals* simParams = parseFile(rawMetaDataStream, mdFileName, mdFileVersion,
361 >                                   metaDataBlockStart + 1);
362      
363      //create the force field
364      ForceField * ff = ForceFieldFactory::getInstance()->createForceField(simParams->getForceField());
# Line 609 | Line 635 | namespace OpenMD {
635   #endif
636          
637          stampId = info->getMoleculeStampId(i);
638 <        Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId),
639 <                                                   stampId, i, info->getLocalIndexManager());
638 >        Molecule * mol = molCreator.createMolecule(info->getForceField(),
639 >                                                   info->getMoleculeStamp(stampId),
640 >                                                   stampId, i,
641 >                                                   info->getLocalIndexManager());
642          
643          info->addMolecule(mol);
644          
# Line 637 | Line 665 | namespace OpenMD {
665      int beginRigidBodyIndex;
666      int beginCutoffGroupIndex;
667      int nGlobalAtoms = info->getNGlobalAtoms();
640
641    /**@todo fixme */
642 #ifndef IS_MPI
668      
669      beginAtomIndex = 0;
670      beginRigidBodyIndex = 0;
671      beginCutoffGroupIndex = 0;
672 <    
673 < #else
649 <    
650 <    int nproc;
651 <    int myNode;
652 <    
653 <    myNode = worldRank;
654 <    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
655 <    
656 <    std::vector < int > tmpAtomsInProc(nproc, 0);
657 <    std::vector < int > tmpRigidBodiesInProc(nproc, 0);
658 <    std::vector < int > tmpCutoffGroupsInProc(nproc, 0);
659 <    std::vector < int > NumAtomsInProc(nproc, 0);
660 <    std::vector < int > NumRigidBodiesInProc(nproc, 0);
661 <    std::vector < int > NumCutoffGroupsInProc(nproc, 0);
662 <    
663 <    tmpAtomsInProc[myNode] = info->getNAtoms();
664 <    tmpRigidBodiesInProc[myNode] = info->getNRigidBodies();
665 <    tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups();
666 <    
667 <    //do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups
668 <    MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT,
669 <                  MPI_SUM, MPI_COMM_WORLD);
670 <    MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc,
671 <                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
672 <    MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc,
673 <                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
674 <    
675 <    beginAtomIndex = 0;
676 <    beginRigidBodyIndex = 0;
677 <    beginCutoffGroupIndex = 0;
678 <    
679 <    for(int i = 0; i < myNode; i++) {
680 <      beginAtomIndex += NumAtomsInProc[i];
681 <      beginRigidBodyIndex += NumRigidBodiesInProc[i];
682 <      beginCutoffGroupIndex += NumCutoffGroupsInProc[i];
683 <    }
684 <    
685 < #endif
686 <    
687 <    //rigidbody's index begins right after atom's
688 <    beginRigidBodyIndex += info->getNGlobalAtoms();
689 <    
690 <    for(mol = info->beginMolecule(mi); mol != NULL;
691 <        mol = info->nextMolecule(mi)) {
672 >
673 >    for(int i = 0; i < info->getNGlobalMolecules(); i++) {
674        
675 <      //local index(index in DataStorge) of atom is important
676 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
677 <        atom->setGlobalIndex(beginAtomIndex++);
675 > #ifdef IS_MPI      
676 >      if (info->getMolToProc(i) == worldRank) {
677 > #endif        
678 >        // stuff to do if I own this molecule
679 >        mol = info->getMoleculeByGlobalIndex(i);
680 >
681 >        //local index(index in DataStorge) of atom is important
682 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
683 >          atom->setGlobalIndex(beginAtomIndex++);
684 >        }
685 >        
686 >        for(rb = mol->beginRigidBody(ri); rb != NULL;
687 >            rb = mol->nextRigidBody(ri)) {
688 >          rb->setGlobalIndex(beginRigidBodyIndex++);
689 >        }
690 >        
691 >        //local index of cutoff group is trivial, it only depends on
692 >        //the order of travesing
693 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
694 >            cg = mol->nextCutoffGroup(ci)) {
695 >          cg->setGlobalIndex(beginCutoffGroupIndex++);
696 >        }        
697 >        
698 > #ifdef IS_MPI        
699 >      }  else {
700 >
701 >        // stuff to do if I don't own this molecule
702 >        
703 >        int stampId = info->getMoleculeStampId(i);
704 >        MoleculeStamp* stamp = info->getMoleculeStamp(stampId);
705 >
706 >        beginAtomIndex += stamp->getNAtoms();
707 >        beginRigidBodyIndex += stamp->getNRigidBodies();
708 >        beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms();
709        }
710 <      
711 <      for(rb = mol->beginRigidBody(ri); rb != NULL;
712 <          rb = mol->nextRigidBody(ri)) {
713 <        rb->setGlobalIndex(beginRigidBodyIndex++);
701 <      }
702 <      
703 <      //local index of cutoff group is trivial, it only depends on the order of travesing
704 <      for(cg = mol->beginCutoffGroup(ci); cg != NULL;
705 <          cg = mol->nextCutoffGroup(ci)) {
706 <        cg->setGlobalIndex(beginCutoffGroupIndex++);
707 <      }
708 <    }
709 <    
710 > #endif          
711 >
712 >    } //end for(int i=0)  
713 >
714      //fill globalGroupMembership
715 <    std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), -1);
715 >    std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0);
716      for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {        
717        for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
718          
# Line 727 | Line 731 | namespace OpenMD {
731      // docs said we could.
732      std::vector<int> tmpGroupMembership(info->getNGlobalAtoms(), 0);
733      MPI_Allreduce(&globalGroupMembership[0], &tmpGroupMembership[0], nGlobalAtoms,
734 <                  MPI_INT, MPI_MAX, MPI_COMM_WORLD);
734 >                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
735      info->setGlobalGroupMembership(tmpGroupMembership);
732
733    cerr << "ggm:\n";
734    for (int i = 0; i < tmpGroupMembership.size(); i++)
735      cerr << "i = " << i << "\t ggm(i) = " << tmpGroupMembership[i] << "\n";
736
736   #else
737      info->setGlobalGroupMembership(globalGroupMembership);
738   #endif
# Line 793 | Line 792 | namespace OpenMD {
792          globalIO++;
793        }
794      }
795 <    
795 >      
796      info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject);
797      
798    }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines