• 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

修訂3a1f18414278129978ce26051ad754e6cb01fb3c (tree)
時間2013-06-18 20:39:10
作者Mikiya Fujii <mikiya.fujii@gmai...>
CommiterMikiya Fujii

Log Message

Mndo::CalcCISMatrix is MPI-parallelized. #31588

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/mpi-cis@1367 1136aad2-a195-0410-b898-f5ea1d11b9d8

Change Summary

差異

--- a/src/mndo/Mndo.cpp
+++ b/src/mndo/Mndo.cpp
@@ -731,21 +731,23 @@ double Mndo::GetMolecularIntegralElement(int moI, int moJ, int moK, int moL,
731731 void Mndo::CalcCISMatrix(double** matrixCIS) const{
732732 this->OutputLog(this->messageStartCalcCISMatrix);
733733 double ompStartTime = omp_get_wtime();
734+ boost::mpi::communicator* world = MolDS_mpi::MpiProcess::GetInstance()->GetCommunicator();
734735
735- stringstream ompErrors;
736-#pragma omp parallel for schedule(auto)
737736 for(int k=0; k<this->matrixCISdimension; k++){
738- try{
739- // single excitation from I-th (occupied)MO to A-th (virtual)MO
740- int moI = this->GetActiveOccIndex(*this->molecule, k);
741- int moA = this->GetActiveVirIndex(*this->molecule, k);
737+ // single excitation from I-th (occupied)MO to A-th (virtual)MO
738+ int moI = this->GetActiveOccIndex(*this->molecule, k);
739+ int moA = this->GetActiveVirIndex(*this->molecule, k);
740+ if(k%world->size() != world->rank()){continue;}
742741
743- for(int l=k; l<this->matrixCISdimension; l++){
742+ stringstream ompErrors;
743+#pragma omp parallel for schedule(auto)
744+ for(int l=k; l<this->matrixCISdimension; l++){
745+ try{
744746 // single excitation from J-th (occupied)MO to B-th (virtual)MO
745747 int moJ = this->GetActiveOccIndex(*this->molecule, l);
746748 int moB = this->GetActiveVirIndex(*this->molecule, l);
747749 double value=0.0;
748-
750+
749751 // Fast algorith, but this is not easy to read.
750752 // Slow algorithm is alos written below.
751753 for(int A=0; A<molecule->GetNumberAtoms(); A++){
@@ -865,13 +867,13 @@ void Mndo::CalcCISMatrix(double** matrixCIS) const{
865867 }
866868 }
867869 // End of the fast algorith.
868-
870+
869871 /*
870872 // Slow algorith, but this is easy to read. Fast altorithm is also written above.
871873 value = 2.0*this->GetMolecularIntegralElement(moA, moI, moJ, moB,
872- this->molecule, this->fockMatrix, NULL)
874+ *this->molecule, this->fockMatrix, NULL)
873875 -this->GetMolecularIntegralElement(moA, moB, moI, moJ,
874- this->molecule, this->fockMatrix, NULL);
876+ *this->molecule, this->fockMatrix, NULL);
875877 // End of the slow algorith.
876878 */
877879 // Diagonal term
@@ -879,17 +881,38 @@ void Mndo::CalcCISMatrix(double** matrixCIS) const{
879881 value += this->energiesMO[moA] - this->energiesMO[moI];
880882 }
881883 matrixCIS[k][l] = value;
884+ }
885+ catch(MolDSException ex){
886+#pragma omp critical
887+ ompErrors << ex.what() << endl ;
882888 }
889+ }// end of l-loop
890+ // Exception throwing for omp-region
891+ if(!ompErrors.str().empty()){
892+ throw MolDSException(ompErrors.str());
883893 }
884- catch(MolDSException ex){
885-#pragma omp critical
886- ompErrors << ex.what() << endl ;
894+ } // end of k-loop
895+
896+ // communication to collect all matrix data on rank 0
897+ if(world->rank() == 0){
898+ // receive the matrix data from other ranks
899+ for(int k=0; k<this->matrixCISdimension; k++){
900+ if(k%world->size() == 0){continue;}
901+ int source = k%world->size();
902+ int tag = k;
903+ world->recv(source, tag, matrixCIS[k], this->matrixCISdimension);
887904 }
888905 }
889- // Exception throwing for omp-region
890- if(!ompErrors.str().empty()){
891- throw MolDSException(ompErrors.str());
906+ else{
907+ // send the matrix data to rank-0
908+ for(int k=0; k<this->matrixCISdimension; k++){
909+ if(k%world->size() != world->rank()){continue;}
910+ int dest = 0;
911+ int tag = k;
912+ world->send(dest, tag, matrixCIS[k], this->matrixCISdimension);
913+ }
892914 }
915+
893916 double ompEndTime = omp_get_wtime();
894917 this->OutputLog(boost::format("%s%lf%s\n%s") % this->messageOmpElapsedTimeCalcCISMarix.c_str()
895918 % (ompEndTime - ompStartTime)