• R/O
  • SSH
  • HTTPS

molds: Commit


Commit MetaInfo

Revision1834 (tree)
Time2016-12-14 09:14:32
Authormikiya_fujii

Log Message

Molecule::CalcDistanceAtoms is hybrid(MPI/openMP) parallelized. Molecule::CalcDistanceEpcs and Molecule::CalcDistanceAtomsEpcs are OMP-parallelized. #30947 #29965

Change Summary

Incremental Difference

--- trunk/src/base/Molecule.cpp (revision 1833)
+++ trunk/src/base/Molecule.cpp (revision 1834)
@@ -27,14 +27,20 @@
2727 #include<algorithm>
2828 #include<omp.h>
2929 #include<boost/format.hpp>
30+#include"../config.h"
3031 #include"Enums.h"
3132 #include"Uncopyable.h"
3233 #include"PrintController.h"
3334 #include"MolDSException.h"
3435 #include"MallocerFreer.h"
36+#include"containers/ThreadSafeQueue.h"
3537 #include"../mpi/MpiInt.h"
3638 #include"../mpi/MpiProcess.h"
39+#include"../mpi/AsyncCommunicator.h"
3740 #include"../wrappers/Lapack.h"
41+#include"../mpi/MpiInt.h"
42+#include"../mpi/MpiProcess.h"
43+#include"../wrappers/Lapack.h"
3844 #include"MathUtilities.h"
3945 #include"EularAngle.h"
4046 #include"Parameters.h"
@@ -423,16 +429,54 @@
423429 if(this->distanceAtoms==NULL){
424430 MallocerFreer::GetInstance()->Malloc<double>(&this->distanceAtoms, this->atomVect->size(), this->atomVect->size());
425431 }
432+ // MPI setting of each rank
433+ int mpiRank = MolDS_mpi::MpiProcess::GetInstance()->GetRank();
434+ int mpiSize = MolDS_mpi::MpiProcess::GetInstance()->GetSize();
435+ int mpiHeadRank = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank();
436+ stringstream errorStream;
437+ MolDS_mpi::AsyncCommunicator asyncCommunicator;
438+ boost::thread communicationThread( boost::bind(&MolDS_mpi::AsyncCommunicator::Run<double>, &asyncCommunicator) );
439+
426440 for(int a=0; a<this->atomVect->size(); a++){
427- const Atom& atomA = *(*this->atomVect)[a];
441+ int blockIndex = a/mpiSize;
442+ int calcRank = blockIndex%2==0 ? a%mpiSize : (mpiSize-1)-(a%mpiSize);
443+ if(mpiRank == calcRank){
444+ const Atom& atomA = *(*this->atomVect)[a];
445+#pragma omp parallel for schedule(dynamic, MOLDS_OMP_DYNAMIC_CHUNK_SIZE)
446+ for(int b=a; b<this->atomVect->size(); b++){
447+ const Atom& atomB = *(*this->atomVect)[b];
448+ double distance=0.0;
449+ distance = sqrt( pow(atomA.GetXyz()[0] - atomB.GetXyz()[0], 2.0)
450+ +pow(atomA.GetXyz()[1] - atomB.GetXyz()[1], 2.0)
451+ +pow(atomA.GetXyz()[2] - atomB.GetXyz()[2], 2.0) );
452+ this->distanceAtoms[a][b] = distance;
453+ }
454+ } // end of if(mpiRank == calcRank)
455+ // communication to collect all matrix data on head-rank
456+ int tag = a;
457+ int source = calcRank;
458+ int dest = mpiHeadRank;
459+ double* buff = &this->distanceAtoms[a][a];
460+ MolDS_mpi::molds_mpi_int num = this->atomVect->size()-a;
461+ if(mpiRank == mpiHeadRank && mpiRank != calcRank){
462+ asyncCommunicator.SetRecvedMessage(buff, num, source, tag);
463+ }
464+ if(mpiRank != mpiHeadRank && mpiRank == calcRank){
465+ asyncCommunicator.SetSentMessage(buff, num, dest, tag);
466+ }
467+ //asyncCommunicator.SetBroadcastedMessage(buff, num, mpiHeadRank);
468+ }
469+ asyncCommunicator.Finalize();
470+ communicationThread.join();
471+ for(int a=0; a<this->atomVect->size(); a++){
472+ int num = this->atomVect->size() - a;
473+ double* buff = &this->distanceAtoms[a][a];
474+ MolDS_mpi::MpiProcess::GetInstance()->Broadcast(buff, num, mpiHeadRank);
475+ }
476+#pragma omp parallel for schedule(dynamic, MOLDS_OMP_DYNAMIC_CHUNK_SIZE)
477+ for(int a=0; a<this->atomVect->size(); a++){
428478 for(int b=a; b<this->atomVect->size(); b++){
429- const Atom& atomB = *(*this->atomVect)[b];
430- double distance=0.0;
431- distance = sqrt( pow(atomA.GetXyz()[0] - atomB.GetXyz()[0], 2.0)
432- +pow(atomA.GetXyz()[1] - atomB.GetXyz()[1], 2.0)
433- +pow(atomA.GetXyz()[2] - atomB.GetXyz()[2], 2.0) );
434- this->distanceAtoms[a][b] = distance;
435- this->distanceAtoms[b][a] = distance;
479+ this->distanceAtoms[b][a] = this->distanceAtoms[a][b];
436480 }
437481 }
438482 }
Show on old repository browser