• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂9e4d7cb3f74676c6ba6269b79e91e54651221827 (tree)
時間2013-08-01 09:43:11
作者Mikiya Fujii <mikiya.fujii@gmai...>
CommiterMikiya Fujii

Log Message

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

Change Summary

差異

--- a/src/base/Molecule.cpp
+++ b/src/base/Molecule.cpp
@@ -711,6 +711,88 @@ void Molecule::SynchronizePhaseSpacePointTo(const Molecule& ref){
711711 this->CalcBasicsConfiguration();
712712 }
713713
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+
714796 }
715797
716798
--- a/src/base/Molecule.h
+++ b/src/base/Molecule.h
@@ -60,6 +60,9 @@ public:
6060 void SynchronizeConfigurationTo (const Molecule& ref);
6161 void SynchronizeMomentaTo (const Molecule& ref);
6262 void SynchronizePhaseSpacePointTo(const Molecule& ref);
63+ void BroadcastConfigurationToAllProcesses(int root) const;
64+ void BroadcastMomentaToAllProcesses(int root) const;
65+ void BroadcastPhaseSpacePointToAllProcesses(int root) const;
6366 private:
6467 std::vector<MolDS_base_atoms::Atom*>* atomVect;
6568 double* xyzCOM; // x, y, z coordinates of Center of Mass;
--- a/src/mc/MC.cpp
+++ b/src/mc/MC.cpp
@@ -137,6 +137,11 @@ void MC::DoMC(int totalSteps, int elecState, double temperature, double stepWidt
137137 else{
138138 trialMolecule.SynchronizeConfigurationTo(*this->molecule);
139139 }
140+
141+ // Broadcast to all processes
142+ int root=0;
143+ this->molecule->BroadcastConfigurationToAllProcesses(root);
144+ trialMolecule.BroadcastConfigurationToAllProcesses(root);
140145
141146 // output molecular states
142147 this->OutputMolecule(*currentES, *this->molecule, elecState);
--- a/src/md/MD.cpp
+++ b/src/md/MD.cpp
@@ -115,6 +115,10 @@ void MD::DoMD(){
115115 // update momenta
116116 this->UpdateMomenta(*this->molecule, matrixForce, dt);
117117
118+ // Broadcast to all processes
119+ int root=0;
120+ this->molecule->BroadcastPhaseSpacePointToAllProcesses(root);
121+
118122 // output results
119123 this->OutputEnergies(electronicStructure, initialEnergy);
120124 this->molecule->OutputConfiguration();
--- a/src/optimization/BFGS.cpp
+++ b/src/optimization/BFGS.cpp
@@ -188,6 +188,11 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
188188 }
189189 else{
190190 this->UpdateMolecularCoordinates(molecule, matrixStep);
191+
192+ // Broadcast to all processes
193+ int root=0;
194+ molecule.BroadcastConfigurationToAllProcesses(root);
195+
191196 this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs);
192197 lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState);
193198 }
--- a/src/optimization/Optimizer.cpp
+++ b/src/optimization/Optimizer.cpp
@@ -158,9 +158,9 @@ void Optimizer::UpdateMolecularCoordinates(Molecule& molecule, double const* con
158158 }
159159
160160 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{
164164 electronicStructure->SetCanOutputLogs(canOutputLogs);
165165 molecule.SetCanOutputLogs(canOutputLogs);
166166 electronicStructure->DoSCF(requireGuess);
@@ -170,8 +170,8 @@ void Optimizer::UpdateElectronicStructure(boost::shared_ptr<ElectronicStructure>
170170 }
171171
172172 void Optimizer::OutputMoleculeElectronicStructure(boost::shared_ptr<ElectronicStructure> electronicStructure,
173- Molecule& molecule,
174- bool canOutputLogs) const{
173+ Molecule& molecule,
174+ bool canOutputLogs) const{
175175 // output molecular configuration
176176 molecule.SetCanOutputLogs(canOutputLogs);
177177 molecule.OutputConfiguration();
@@ -196,9 +196,10 @@ void Optimizer::LineSearch(boost::shared_ptr<ElectronicStructure> electronicStru
196196 int lineSearchSteps = 0;
197197 double lineSearchOldEnergy = lineSearchCurrentEnergy;
198198
199+ bool requireGuess = false;
199200 while(lineSearchCurrentEnergy <= lineSearchOldEnergy){
200201 this->UpdateMolecularCoordinates(molecule, matrixForce, dt);
201- this->UpdateElectronicStructure(electronicStructure, molecule, false, tempCanOutputLogs);
202+ this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs);
202203 lineSearchOldEnergy = lineSearchCurrentEnergy;
203204 lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState);
204205 lineSearchSteps++;
@@ -207,7 +208,13 @@ void Optimizer::LineSearch(boost::shared_ptr<ElectronicStructure> electronicStru
207208 // final state of line search
208209 this->OutputLog(boost::format("%s%d\n\n") % this->messageLineSearchSteps.c_str() % lineSearchSteps);
209210 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);
211218 this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs());
212219
213220 lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState);
--- a/src/optimization/SteepestDescent.cpp
+++ b/src/optimization/SteepestDescent.cpp
@@ -89,6 +89,8 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect
8989
9090 // do line search
9191 this->LineSearch(electronicStructure, molecule, lineSearchCurrentEnergy, matrixForce, elecState, dt);
92+
93+ // update force
9294 matrixForce = electronicStructure->GetForce(elecState);
9395
9496 // check convergence
--- a/src/rpmd/RPMD.cpp
+++ b/src/rpmd/RPMD.cpp
@@ -129,6 +129,13 @@ void RPMD::UpdateCoordinates(const vector<boost::shared_ptr<Molecule> >& molecul
129129 }
130130 }
131131
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+
132139 void RPMD::FluctuateBeads(const vector<boost::shared_ptr<Molecule> >& molecularBeads,
133140 int elecState,
134141 double temperature,
@@ -194,6 +201,10 @@ void RPMD::DoRPMD(const Molecule& refferenceMolecule){
194201 // update momenta
195202 this->UpdateMomenta(molecularBeads, electronicStructureBeads, elecState, dt, temperature);
196203
204+ // Broadcast coordinates and momenta of beads to all processes
205+ int root=0;
206+ this->BroadcastPhaseSpacepointsToAllProcesses(molecularBeads, root);
207+
197208 // output energy
198209 this->OutputEnergies(molecularBeads,
199210 electronicStructureBeads,
--- a/src/rpmd/RPMD.h
+++ b/src/rpmd/RPMD.h
@@ -65,6 +65,7 @@ private:
6565 void UpdateCoordinates(const std::vector<boost::shared_ptr<MolDS_base::Molecule> >& molecularBeads,
6666 double dt);
6767 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;
6869 void FluctuateBeads(const std::vector<boost::shared_ptr<MolDS_base::Molecule> >& molecularBeads,
6970 int elecState,
7071 double temperature,