修訂 | 70d59b6c069f93f404b1f0fe3034cd72b8ad0929 (tree) |
---|---|
時間 | 2013-08-05 03:52:28 |
作者 | Mikiya Fujii <mikiya.fujii@gmai...> |
Commiter | Mikiya Fujii |
MpiProcess::GetHeadRank() is added. #31814
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1453 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -41,8 +41,9 @@ PrintController::~PrintController(){ | ||
41 | 41 | |
42 | 42 | void PrintController::OutputLog(string log) const{ |
43 | 43 | if(this->canOutputLogs){ |
44 | + int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
44 | 45 | #ifndef MOLDS_DBG |
45 | - if(MolDS_mpi::MpiProcess::GetInstance()->GetRank()!=0){return;} | |
46 | + if(MolDS_mpi::MpiProcess::GetInstance()->GetRank()!=mpiHeadRank){return;} | |
46 | 47 | #endif |
47 | 48 | bool endl = false; |
48 | 49 | string::reverse_iterator iter; |
@@ -139,7 +139,7 @@ void MC::DoMC(int totalSteps, int elecState, double temperature, double stepWidt | ||
139 | 139 | } |
140 | 140 | |
141 | 141 | // Broadcast to all processes |
142 | - int root=0; | |
142 | + int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
143 | 143 | this->molecule->BroadcastConfigurationToAllProcesses(root); |
144 | 144 | trialMolecule.BroadcastConfigurationToAllProcesses(root); |
145 | 145 |
@@ -116,7 +116,7 @@ void MD::DoMD(){ | ||
116 | 116 | this->UpdateMomenta(*this->molecule, matrixForce, dt); |
117 | 117 | |
118 | 118 | // Broadcast to all processes |
119 | - int root=0; | |
119 | + int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
120 | 120 | this->molecule->BroadcastPhaseSpacePointToAllProcesses(root); |
121 | 121 | |
122 | 122 | // output results |
@@ -894,10 +894,11 @@ void Mndo::CalcCISMatrix(double** matrixCIS) const{ | ||
894 | 894 | } // end of k-loop |
895 | 895 | |
896 | 896 | // communication to collect all matrix data on rank 0 |
897 | - if(mpiRank == 0){ | |
897 | + int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
898 | + if(mpiRank == mpiHeadRank){ | |
898 | 899 | // receive the matrix data from other ranks |
899 | 900 | for(int k=0; k<this->matrixCISdimension; k++){ |
900 | - if(k%mpiSize == 0){continue;} | |
901 | + if(k%mpiSize == mpiHeadRank){continue;} | |
901 | 902 | int source = k%mpiSize; |
902 | 903 | int tag = k; |
903 | 904 | MolDS_mpi::MpiProcess::GetInstance()->Recv(source, tag, matrixCIS[k], this->matrixCISdimension); |
@@ -907,13 +908,13 @@ void Mndo::CalcCISMatrix(double** matrixCIS) const{ | ||
907 | 908 | // send the matrix data to rank-0 |
908 | 909 | for(int k=0; k<this->matrixCISdimension; k++){ |
909 | 910 | if(k%mpiSize != mpiRank){continue;} |
910 | - int dest = 0; | |
911 | + int dest = mpiHeadRank; | |
911 | 912 | int tag = k; |
912 | 913 | MolDS_mpi::MpiProcess::GetInstance()->Send(dest, tag, matrixCIS[k], this->matrixCISdimension); |
913 | 914 | } |
914 | 915 | } |
915 | 916 | // broadcast all matrix data to all rank |
916 | - int root=0; | |
917 | + int root=mpiHeadRank; | |
917 | 918 | MolDS_mpi::MpiProcess::GetInstance()->Broadcast(&matrixCIS[0][0], this->matrixCISdimension*this->matrixCISdimension, root); |
918 | 919 | |
919 | 920 |
@@ -27,6 +27,7 @@ public: | ||
27 | 27 | static void CreateInstance(int argc, char *argv[]); |
28 | 28 | static void DeleteInstance(); |
29 | 29 | static MpiProcess* GetInstance(); |
30 | + int GetHeadRank() const{return 0;} | |
30 | 31 | int GetRank() const{return this->communicator->rank();} |
31 | 32 | int GetSize() const{return this->communicator->size();} |
32 | 33 | template<typename T> void Send(int dest, int tag, const T* values, intptr_t num) const{ |
@@ -190,7 +190,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
190 | 190 | this->UpdateMolecularCoordinates(molecule, matrixStep); |
191 | 191 | |
192 | 192 | // Broadcast to all processes |
193 | - int root=0; | |
193 | + int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
194 | 194 | molecule.BroadcastConfigurationToAllProcesses(root); |
195 | 195 | |
196 | 196 | this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs); |
@@ -210,7 +210,7 @@ void Optimizer::LineSearch(boost::shared_ptr<ElectronicStructure> electronicStru | ||
210 | 210 | this->UpdateMolecularCoordinates(molecule, matrixForce, -0.5*dt); |
211 | 211 | |
212 | 212 | // Broadcast to all processes |
213 | - int root=0; | |
213 | + int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
214 | 214 | molecule.BroadcastConfigurationToAllProcesses(root); |
215 | 215 | |
216 | 216 | // update and output electronic structure |
@@ -202,7 +202,7 @@ void RPMD::DoRPMD(const Molecule& refferenceMolecule){ | ||
202 | 202 | this->UpdateMomenta(molecularBeads, electronicStructureBeads, elecState, dt, temperature); |
203 | 203 | |
204 | 204 | // Broadcast coordinates and momenta of beads to all processes |
205 | - int root=0; | |
205 | + int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
206 | 206 | this->BroadcastPhaseSpacepointsToAllProcesses(molecularBeads, root); |
207 | 207 | |
208 | 208 | // output energy |
@@ -1241,29 +1241,30 @@ void ZindoS::CalcCISProperties(){ | ||
1241 | 1241 | MallocerFreer::GetInstance()->Free<double>(&dipoleMOs, CartesianType_end, totalNumberAOs, totalNumberAOs); |
1242 | 1242 | MallocerFreer::GetInstance()->Free<double>(&overlapMOs, totalNumberAOs, totalNumberAOs); |
1243 | 1243 | |
1244 | - // communication to collect all matrix data on rank 0 | |
1244 | + // communication to collect all matrix data on head-rank | |
1245 | + int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
1245 | 1246 | int numTransported = (Parameters::GetInstance()->GetNumberExcitedStatesCIS()+1)*CartesianType_end; |
1246 | - if(mpiRank == 0){ | |
1247 | + if(mpiRank == mpiHeadRank){ | |
1247 | 1248 | // receive the matrix data from other ranks |
1248 | 1249 | for(int k=0; k<Parameters::GetInstance()->GetNumberExcitedStatesCIS()+1; k++){ |
1249 | - if(k%mpiSize == 0){continue;} | |
1250 | + if(k%mpiSize == mpiHeadRank){continue;} | |
1250 | 1251 | int source = k%mpiSize; |
1251 | 1252 | int tag = k; |
1252 | 1253 | MolDS_mpi::MpiProcess::GetInstance()->Recv(source, tag, &this->electronicTransitionDipoleMoments[k][0][0], numTransported); |
1253 | 1254 | } |
1254 | 1255 | } |
1255 | 1256 | else{ |
1256 | - // send the matrix data to rank-0 | |
1257 | + // send the matrix data to head-rank | |
1257 | 1258 | for(int k=0; k<Parameters::GetInstance()->GetNumberExcitedStatesCIS()+1; k++){ |
1258 | 1259 | if(k%mpiSize != mpiRank){continue;} |
1259 | - int dest = 0; | |
1260 | + int dest = mpiHeadRank; | |
1260 | 1261 | int tag = k; |
1261 | 1262 | MolDS_mpi::MpiProcess::GetInstance()->Send(dest, tag, &this->electronicTransitionDipoleMoments[k][0][0], numTransported); |
1262 | 1263 | } |
1263 | 1264 | } |
1264 | 1265 | |
1265 | 1266 | // right upper part of the matrix is copied from left lower part. |
1266 | - if(mpiRank == 0 && Parameters::GetInstance()->RequiresAllTransitionDipoleMomentsCIS()){ | |
1267 | + if(mpiRank == mpiHeadRank && Parameters::GetInstance()->RequiresAllTransitionDipoleMomentsCIS()){ | |
1267 | 1268 | for(int k=0; k<Parameters::GetInstance()->GetNumberExcitedStatesCIS()+1; k++){ |
1268 | 1269 | for(int l=k+1; l<Parameters::GetInstance()->GetNumberExcitedStatesCIS()+1; l++){ |
1269 | 1270 | for(int axis=0; axis<CartesianType_end; axis++){ |
@@ -1276,7 +1277,7 @@ void ZindoS::CalcCISProperties(){ | ||
1276 | 1277 | |
1277 | 1278 | // broadcast all matrix data to all ranks |
1278 | 1279 | numTransported *= (Parameters::GetInstance()->GetNumberExcitedStatesCIS()+1); |
1279 | - int root=0; | |
1280 | + int root=mpiHeadRank; | |
1280 | 1281 | MolDS_mpi::MpiProcess::GetInstance()->Broadcast(&this->electronicTransitionDipoleMoments[0][0][0], numTransported, root); |
1281 | 1282 | |
1282 | 1283 |
@@ -2393,28 +2394,29 @@ void ZindoS::CalcCISMatrix(double** matrixCIS) const{ | ||
2393 | 2394 | } // end of k-loop |
2394 | 2395 | |
2395 | 2396 | |
2396 | - // communication to collect all matrix data on rank 0 | |
2397 | - if(mpiRank == 0){ | |
2397 | + // communication to collect all matrix data on head-rank | |
2398 | + int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank(); | |
2399 | + if(mpiRank == mpiHeadRank){ | |
2398 | 2400 | // receive the matrix data from other ranks |
2399 | 2401 | for(int k=0; k<this->matrixCISdimension; k++){ |
2400 | - if(k%mpiSize == 0){continue;} | |
2402 | + if(k%mpiSize == mpiHeadRank){continue;} | |
2401 | 2403 | int source = k%mpiSize; |
2402 | 2404 | int tag = k; |
2403 | 2405 | MolDS_mpi::MpiProcess::GetInstance()->Recv(source, tag, matrixCIS[k], this->matrixCISdimension); |
2404 | 2406 | } |
2405 | 2407 | } |
2406 | 2408 | else{ |
2407 | - // send the matrix data to rank-0 | |
2409 | + // send the matrix data to head-rank | |
2408 | 2410 | for(int k=0; k<this->matrixCISdimension; k++){ |
2409 | 2411 | if(k%mpiSize != mpiRank){continue;} |
2410 | - int dest = 0; | |
2412 | + int dest = mpiHeadRank; | |
2411 | 2413 | int tag = k; |
2412 | 2414 | MolDS_mpi::MpiProcess::GetInstance()->Send(dest, tag, matrixCIS[k], this->matrixCISdimension); |
2413 | 2415 | } |
2414 | 2416 | } |
2415 | 2417 | |
2416 | 2418 | // broadcast all matrix data to all rank |
2417 | - int root=0; | |
2419 | + int root=mpiHeadRank; | |
2418 | 2420 | MolDS_mpi::MpiProcess::GetInstance()->Broadcast(&matrixCIS[0][0], this->matrixCISdimension*this->matrixCISdimension, root); |
2419 | 2421 | |
2420 | 2422 | double ompEndTime = omp_get_wtime(); |