• R/O
  • SSH
  • HTTPS

molds: Commit


Commit MetaInfo

Revision1837 (tree)
Time2016-12-14 09:38:57
Authormikiya_fujii

Log Message

Molecule::CalcDistanceAtomsEpcs is hybrid(MPI/openMP) re-parallelized. #30947 #29965

Change Summary

Incremental Difference

--- trunk/src/base/Molecule.cpp (revision 1836)
+++ trunk/src/base/Molecule.cpp (revision 1837)
@@ -529,21 +529,54 @@
529529 }
530530
531531 void Molecule::CalcDistanceAtomsEpcs(){
532- if(this->epcVect == NULL){return;}
532+ if(this->epcVect == NULL){
533+ return;
534+ }
535+ if(this->atomVect->size()==0 || this->epcVect->size()==0){
536+ return;
537+ }
533538 if(this->distanceAtomsEpcs==NULL){
534539 MallocerFreer::GetInstance()->Malloc<double>(&this->distanceAtomsEpcs, this->atomVect->size(), this->epcVect->size());
535540 }
541+ // MPI setting of each rank
542+ int mpiRank = MolDS_mpi::MpiProcess::GetInstance()->GetRank();
543+ int mpiSize = MolDS_mpi::MpiProcess::GetInstance()->GetSize();
544+ int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank();
545+ stringstream errorStream;
546+ MolDS_mpi::AsyncCommunicator asyncCommunicator;
547+ boost::thread communicationThread( boost::bind(&MolDS_mpi::AsyncCommunicator::Run<double>, &asyncCommunicator) );
548+
536549 for(int a=0; a<this->atomVect->size(); a++){
537- const Atom& atom = *(*this->atomVect)[a];
538- for(int b=0; b<this->epcVect->size(); b++){
539- const Atom& epc = *(*this->epcVect)[b];
540- double distance=0.0;
541- distance = sqrt( pow(atom.GetXyz()[0] - epc.GetXyz()[0], 2.0)
542- +pow(atom.GetXyz()[1] - epc.GetXyz()[1], 2.0)
543- +pow(atom.GetXyz()[2] - epc.GetXyz()[2], 2.0) );
544- this->distanceAtomsEpcs[a][b] = distance;
550+ int blockIndex = a/mpiSize;
551+ int calcRank = blockIndex%2==0 ? a%mpiSize : (mpiSize-1)-(a%mpiSize);
552+ if(mpiRank == calcRank){
553+ const Atom& atom = *(*this->atomVect)[a];
554+#pragma omp parallel for schedule(dynamic, MOLDS_OMP_DYNAMIC_CHUNK_SIZE)
555+ for(int b=0; b<this->epcVect->size(); b++){
556+ const Atom& epc = *(*this->epcVect)[b];
557+ double distance=0.0;
558+ distance = sqrt( pow(atom.GetXyz()[0] - epc.GetXyz()[0], 2.0)
559+ +pow(atom.GetXyz()[1] - epc.GetXyz()[1], 2.0)
560+ +pow(atom.GetXyz()[2] - epc.GetXyz()[2], 2.0) );
561+ this->distanceAtomsEpcs[a][b] = distance;
562+ }
563+ } // end of if(mpiRank == calcRank)
564+ // communication to collect all matrix data on head-rank
565+ int tag = a;
566+ int source = calcRank;
567+ int dest = mpiHeadRank;
568+ double* buff = &this->distanceAtomsEpcs[a][0];
569+ MolDS_mpi::molds_mpi_int num = this->epcVect->size();
570+ if(mpiRank == mpiHeadRank && mpiRank != calcRank){
571+ asyncCommunicator.SetRecvedMessage(buff, num, source, tag);
545572 }
573+ if(mpiRank != mpiHeadRank && mpiRank == calcRank){
574+ asyncCommunicator.SetSentMessage(buff, num, dest, tag);
575+ }
576+ asyncCommunicator.SetBroadcastedMessage(buff, num, mpiHeadRank);
546577 }
578+ asyncCommunicator.Finalize();
579+ communicationThread.join();
547580 }
548581
549582 void Molecule::CalcBasics(){
Show on old repository browser