• R/O
  • SSH
  • HTTPS

molds: Commit


Commit MetaInfo

Revision1836 (tree)
Time2016-12-14 09:22:56
Authormikiya_fujii

Log Message

Molecule::CalcDistanceEpcs is hybrid(MPI/openMP) parallelized. #30947 #29965

Change Summary

Incremental Difference

--- trunk/src/base/Molecule.cpp (revision 1835)
+++ trunk/src/base/Molecule.cpp (revision 1836)
@@ -481,16 +481,49 @@
481481 if(this->distanceEpcs==NULL){
482482 MallocerFreer::GetInstance()->Malloc<double>(&this->distanceEpcs, this->epcVect->size(), this->epcVect->size());
483483 }
484+ // MPI setting of each rank
485+ int mpiRank = MolDS_mpi::MpiProcess::GetInstance()->GetRank();
486+ int mpiSize = MolDS_mpi::MpiProcess::GetInstance()->GetSize();
487+ int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank();
488+ stringstream errorStream;
489+ MolDS_mpi::AsyncCommunicator asyncCommunicator;
490+ boost::thread communicationThread( boost::bind(&MolDS_mpi::AsyncCommunicator::Run<double>, &asyncCommunicator) );
491+
484492 for(int a=0; a<this->epcVect->size(); a++){
485- const Atom& epcA = *(*this->epcVect)[a];
493+ int blockIndex = a/mpiSize;
494+ int calcRank = blockIndex%2==0 ? a%mpiSize : (mpiSize-1)-(a%mpiSize);
495+ if(mpiRank == calcRank){
496+ const Atom& epcA = *(*this->epcVect)[a];
497+#pragma omp parallel for schedule(dynamic, MOLDS_OMP_DYNAMIC_CHUNK_SIZE)
498+ for(int b=a; b<this->epcVect->size(); b++){
499+ const Atom& epcB = *(*this->epcVect)[b];
500+ double distance=0.0;
501+ distance = sqrt( pow(epcA.GetXyz()[0] - epcB.GetXyz()[0], 2.0)
502+ +pow(epcA.GetXyz()[1] - epcB.GetXyz()[1], 2.0)
503+ +pow(epcA.GetXyz()[2] - epcB.GetXyz()[2], 2.0) );
504+ this->distanceEpcs[a][b] = distance;
505+ }
506+ } // end of if(mpiRank == calcRank)
507+ // communication to collect all matrix data on head-rank
508+ int tag = a;
509+ int source = calcRank;
510+ int dest = mpiHeadRank;
511+ double* buff = &this->distanceEpcs[a][a];
512+ MolDS_mpi::molds_mpi_int num = this->epcVect->size()-a;
513+ if(mpiRank == mpiHeadRank && mpiRank != calcRank){
514+ asyncCommunicator.SetRecvedMessage(buff, num, source, tag);
515+ }
516+ if(mpiRank != mpiHeadRank && mpiRank == calcRank){
517+ asyncCommunicator.SetSentMessage(buff, num, dest, tag);
518+ }
519+ asyncCommunicator.SetBroadcastedMessage(buff, num, mpiHeadRank);
520+ }
521+ asyncCommunicator.Finalize();
522+ communicationThread.join();
523+#pragma omp parallel for schedule(dynamic, MOLDS_OMP_DYNAMIC_CHUNK_SIZE)
524+ for(int a=0; a<this->epcVect->size(); a++){
486525 for(int b=a; b<this->epcVect->size(); b++){
487- const Atom& epcB = *(*this->epcVect)[b];
488- double distance=0.0;
489- distance = sqrt( pow(epcA.GetXyz()[0] - epcB.GetXyz()[0], 2.0)
490- +pow(epcA.GetXyz()[1] - epcB.GetXyz()[1], 2.0)
491- +pow(epcA.GetXyz()[2] - epcB.GetXyz()[2], 2.0) );
492- this->distanceEpcs[a][b] = distance;
493- this->distanceEpcs[b][a] = distance;
526+ this->distanceEpcs[b][a] = this->distanceEpcs[a][b];
494527 }
495528 }
496529 }
Show on old repository browser