修訂 | 9e4d7cb3f74676c6ba6269b79e91e54651221827 (tree) |
---|---|
時間 | 2013-08-01 09:43:11 |
作者 | Mikiya Fujii <mikiya.fujii@gmai...> |
Commiter | Mikiya Fujii |
Synchronize phase space point between all MPI-processes in MC, MD, RPMD, and opt is added. #31814
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1450 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -711,6 +711,88 @@ void Molecule::SynchronizePhaseSpacePointTo(const Molecule& ref){ | ||
711 | 711 | this->CalcBasicsConfiguration(); |
712 | 712 | } |
713 | 713 | |
714 | +void Molecule::BroadcastConfigurationToAllProcesses(int root) const{ | |
715 | + int numTransported = this->GetNumberAtoms()*CartesianType_end; | |
716 | + double* tmp=NULL; | |
717 | + try{ | |
718 | + MolDS_base::MallocerFreer::GetInstance()->Malloc<double>(&tmp, numTransported); | |
719 | + for(int a=0; a<this->GetNumberAtoms(); a++){ | |
720 | + Atom& atom = *this->GetAtom(a); | |
721 | + for(int i=0; i<CartesianType_end; i++){ | |
722 | + tmp[a*CartesianType_end+i] = atom.GetXyz()[i]; | |
723 | + } | |
724 | + } | |
725 | + MolDS_mpi::MpiProcess::GetInstance()->Broadcast(tmp, numTransported, root); | |
726 | + for(int a=0; a<this->GetNumberAtoms(); a++){ | |
727 | + Atom& atom = *this->GetAtom(a); | |
728 | + for(int i=0; i<CartesianType_end; i++){ | |
729 | + atom.GetXyz()[i] = tmp[a*CartesianType_end+i]; | |
730 | + } | |
731 | + } | |
732 | + } | |
733 | + catch(MolDS_base::MolDSException ex){ | |
734 | + MolDS_base::MallocerFreer::GetInstance()->Free<double>(&tmp, numTransported); | |
735 | + throw ex; | |
736 | + } | |
737 | + MolDS_base::MallocerFreer::GetInstance()->Free<double>(&tmp, numTransported); | |
738 | +} | |
739 | + | |
740 | +void Molecule::BroadcastMomentaToAllProcesses(int root) const{ | |
741 | + int numTransported = this->GetNumberAtoms()*CartesianType_end; | |
742 | + double* tmp=NULL; | |
743 | + try{ | |
744 | + MolDS_base::MallocerFreer::GetInstance()->Malloc<double>(&tmp, numTransported); | |
745 | + for(int a=0; a<this->GetNumberAtoms(); a++){ | |
746 | + Atom& atom = *this->GetAtom(a); | |
747 | + for(int i=0; i<CartesianType_end; i++){ | |
748 | + tmp[a*CartesianType_end+i] = atom.GetPxyz()[i]; | |
749 | + } | |
750 | + } | |
751 | + MolDS_mpi::MpiProcess::GetInstance()->Broadcast(tmp, numTransported, root); | |
752 | + for(int a=0; a<this->GetNumberAtoms(); a++){ | |
753 | + Atom& atom = *this->GetAtom(a); | |
754 | + for(int i=0; i<CartesianType_end; i++){ | |
755 | + atom.GetPxyz()[i] = tmp[a*CartesianType_end+i]; | |
756 | + } | |
757 | + } | |
758 | + } | |
759 | + catch(MolDS_base::MolDSException ex){ | |
760 | + MolDS_base::MallocerFreer::GetInstance()->Free<double>(&tmp, numTransported); | |
761 | + throw ex; | |
762 | + } | |
763 | + MolDS_base::MallocerFreer::GetInstance()->Free<double>(&tmp, numTransported); | |
764 | +} | |
765 | + | |
766 | +void Molecule::BroadcastPhaseSpacePointToAllProcesses(int root) const{ | |
767 | + int numTransported = 2*this->GetNumberAtoms()*CartesianType_end; | |
768 | + double* tmp=NULL; | |
769 | + try{ | |
770 | + MolDS_base::MallocerFreer::GetInstance()->Malloc<double>(&tmp, numTransported); | |
771 | + for(int a=0; a<this->GetNumberAtoms(); a++){ | |
772 | + Atom& atom = *this->GetAtom(a); | |
773 | + for(int i=0; i<CartesianType_end; i++){ | |
774 | + int k = a*CartesianType_end+i; | |
775 | + tmp[2*k ] = atom.GetXyz() [i]; | |
776 | + tmp[2*k+1] = atom.GetPxyz()[i]; | |
777 | + } | |
778 | + } | |
779 | + MolDS_mpi::MpiProcess::GetInstance()->Broadcast(tmp, numTransported, root); | |
780 | + for(int a=0; a<this->GetNumberAtoms(); a++){ | |
781 | + Atom& atom = *this->GetAtom(a); | |
782 | + for(int i=0; i<CartesianType_end; i++){ | |
783 | + int k = a*CartesianType_end+i; | |
784 | + atom.GetXyz() [i] = tmp[2*k ]; | |
785 | + atom.GetPxyz()[i] = tmp[2*k+1]; | |
786 | + } | |
787 | + } | |
788 | + } | |
789 | + catch(MolDS_base::MolDSException ex){ | |
790 | + MolDS_base::MallocerFreer::GetInstance()->Free<double>(&tmp, numTransported); | |
791 | + throw ex; | |
792 | + } | |
793 | + MolDS_base::MallocerFreer::GetInstance()->Free<double>(&tmp, numTransported); | |
794 | +} | |
795 | + | |
714 | 796 | } |
715 | 797 | |
716 | 798 |
@@ -60,6 +60,9 @@ public: | ||
60 | 60 | void SynchronizeConfigurationTo (const Molecule& ref); |
61 | 61 | void SynchronizeMomentaTo (const Molecule& ref); |
62 | 62 | void SynchronizePhaseSpacePointTo(const Molecule& ref); |
63 | + void BroadcastConfigurationToAllProcesses(int root) const; | |
64 | + void BroadcastMomentaToAllProcesses(int root) const; | |
65 | + void BroadcastPhaseSpacePointToAllProcesses(int root) const; | |
63 | 66 | private: |
64 | 67 | std::vector<MolDS_base_atoms::Atom*>* atomVect; |
65 | 68 | double* xyzCOM; // x, y, z coordinates of Center of Mass; |
@@ -137,6 +137,11 @@ void MC::DoMC(int totalSteps, int elecState, double temperature, double stepWidt | ||
137 | 137 | else{ |
138 | 138 | trialMolecule.SynchronizeConfigurationTo(*this->molecule); |
139 | 139 | } |
140 | + | |
141 | + // Broadcast to all processes | |
142 | + int root=0; | |
143 | + this->molecule->BroadcastConfigurationToAllProcesses(root); | |
144 | + trialMolecule.BroadcastConfigurationToAllProcesses(root); | |
140 | 145 | |
141 | 146 | // output molecular states |
142 | 147 | this->OutputMolecule(*currentES, *this->molecule, elecState); |
@@ -115,6 +115,10 @@ void MD::DoMD(){ | ||
115 | 115 | // update momenta |
116 | 116 | this->UpdateMomenta(*this->molecule, matrixForce, dt); |
117 | 117 | |
118 | + // Broadcast to all processes | |
119 | + int root=0; | |
120 | + this->molecule->BroadcastPhaseSpacePointToAllProcesses(root); | |
121 | + | |
118 | 122 | // output results |
119 | 123 | this->OutputEnergies(electronicStructure, initialEnergy); |
120 | 124 | this->molecule->OutputConfiguration(); |
@@ -188,6 +188,11 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
188 | 188 | } |
189 | 189 | else{ |
190 | 190 | this->UpdateMolecularCoordinates(molecule, matrixStep); |
191 | + | |
192 | + // Broadcast to all processes | |
193 | + int root=0; | |
194 | + molecule.BroadcastConfigurationToAllProcesses(root); | |
195 | + | |
191 | 196 | this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs); |
192 | 197 | lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState); |
193 | 198 | } |
@@ -158,9 +158,9 @@ void Optimizer::UpdateMolecularCoordinates(Molecule& molecule, double const* con | ||
158 | 158 | } |
159 | 159 | |
160 | 160 | void Optimizer::UpdateElectronicStructure(boost::shared_ptr<ElectronicStructure> electronicStructure, |
161 | - Molecule& molecule, | |
162 | - bool requireGuess, | |
163 | - bool canOutputLogs) const{ | |
161 | + Molecule& molecule, | |
162 | + bool requireGuess, | |
163 | + bool canOutputLogs) const{ | |
164 | 164 | electronicStructure->SetCanOutputLogs(canOutputLogs); |
165 | 165 | molecule.SetCanOutputLogs(canOutputLogs); |
166 | 166 | electronicStructure->DoSCF(requireGuess); |
@@ -170,8 +170,8 @@ void Optimizer::UpdateElectronicStructure(boost::shared_ptr<ElectronicStructure> | ||
170 | 170 | } |
171 | 171 | |
172 | 172 | void Optimizer::OutputMoleculeElectronicStructure(boost::shared_ptr<ElectronicStructure> electronicStructure, |
173 | - Molecule& molecule, | |
174 | - bool canOutputLogs) const{ | |
173 | + Molecule& molecule, | |
174 | + bool canOutputLogs) const{ | |
175 | 175 | // output molecular configuration |
176 | 176 | molecule.SetCanOutputLogs(canOutputLogs); |
177 | 177 | molecule.OutputConfiguration(); |
@@ -196,9 +196,10 @@ void Optimizer::LineSearch(boost::shared_ptr<ElectronicStructure> electronicStru | ||
196 | 196 | int lineSearchSteps = 0; |
197 | 197 | double lineSearchOldEnergy = lineSearchCurrentEnergy; |
198 | 198 | |
199 | + bool requireGuess = false; | |
199 | 200 | while(lineSearchCurrentEnergy <= lineSearchOldEnergy){ |
200 | 201 | this->UpdateMolecularCoordinates(molecule, matrixForce, dt); |
201 | - this->UpdateElectronicStructure(electronicStructure, molecule, false, tempCanOutputLogs); | |
202 | + this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs); | |
202 | 203 | lineSearchOldEnergy = lineSearchCurrentEnergy; |
203 | 204 | lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState); |
204 | 205 | lineSearchSteps++; |
@@ -207,7 +208,13 @@ void Optimizer::LineSearch(boost::shared_ptr<ElectronicStructure> electronicStru | ||
207 | 208 | // final state of line search |
208 | 209 | this->OutputLog(boost::format("%s%d\n\n") % this->messageLineSearchSteps.c_str() % lineSearchSteps); |
209 | 210 | this->UpdateMolecularCoordinates(molecule, matrixForce, -0.5*dt); |
210 | - this->UpdateElectronicStructure(electronicStructure, molecule, false, tempCanOutputLogs); | |
211 | + | |
212 | + // Broadcast to all processes | |
213 | + int root=0; | |
214 | + molecule.BroadcastConfigurationToAllProcesses(root); | |
215 | + | |
216 | + // update and output electronic structure | |
217 | + this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs); | |
211 | 218 | this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs()); |
212 | 219 | |
213 | 220 | lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState); |
@@ -89,6 +89,8 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect | ||
89 | 89 | |
90 | 90 | // do line search |
91 | 91 | this->LineSearch(electronicStructure, molecule, lineSearchCurrentEnergy, matrixForce, elecState, dt); |
92 | + | |
93 | + // update force | |
92 | 94 | matrixForce = electronicStructure->GetForce(elecState); |
93 | 95 | |
94 | 96 | // check convergence |
@@ -129,6 +129,13 @@ void RPMD::UpdateCoordinates(const vector<boost::shared_ptr<Molecule> >& molecul | ||
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | +void RPMD::BroadcastPhaseSpacepointsToAllProcesses(std::vector<boost::shared_ptr<MolDS_base::Molecule> >& molecularBeads, int root) const{ | |
133 | + int numBeads = molecularBeads.size(); | |
134 | + for(int b=0; b<numBeads; b++){ | |
135 | + molecularBeads[b]->BroadcastPhaseSpacePointToAllProcesses(root); | |
136 | + } | |
137 | +} | |
138 | + | |
132 | 139 | void RPMD::FluctuateBeads(const vector<boost::shared_ptr<Molecule> >& molecularBeads, |
133 | 140 | int elecState, |
134 | 141 | double temperature, |
@@ -194,6 +201,10 @@ void RPMD::DoRPMD(const Molecule& refferenceMolecule){ | ||
194 | 201 | // update momenta |
195 | 202 | this->UpdateMomenta(molecularBeads, electronicStructureBeads, elecState, dt, temperature); |
196 | 203 | |
204 | + // Broadcast coordinates and momenta of beads to all processes | |
205 | + int root=0; | |
206 | + this->BroadcastPhaseSpacepointsToAllProcesses(molecularBeads, root); | |
207 | + | |
197 | 208 | // output energy |
198 | 209 | this->OutputEnergies(molecularBeads, |
199 | 210 | electronicStructureBeads, |
@@ -65,6 +65,7 @@ private: | ||
65 | 65 | void UpdateCoordinates(const std::vector<boost::shared_ptr<MolDS_base::Molecule> >& molecularBeads, |
66 | 66 | double dt); |
67 | 67 | void UpdateElectronicStructure(const std::vector<boost::shared_ptr<MolDS_base::ElectronicStructure> >& electronicStructureBeads); |
68 | + void BroadcastPhaseSpacepointsToAllProcesses(std::vector<boost::shared_ptr<MolDS_base::Molecule> >& molecularBeads, int root) const; | |
68 | 69 | void FluctuateBeads(const std::vector<boost::shared_ptr<MolDS_base::Molecule> >& molecularBeads, |
69 | 70 | int elecState, |
70 | 71 | double temperature, |