11 #ifndef ROOT_Minuit2_MPIProcess
12 #define ROOT_Minuit2_MPIProcess
33 if (MPI::Is_initialized() && !(MPI::Is_finalized())) {
34 std::cout <<
"Info --> MPITerminate:: End MPI on #"
35 << MPI::COMM_WORLD.Get_rank() <<
" processor"
48 MPIProcess(
unsigned int nelements,
unsigned int indexComm);
51 inline unsigned int NumElements4JobIn()
const {
return fNumElements4JobIn; }
52 inline unsigned int NumElements4JobOut()
const {
return fNumElements4JobOut; }
54 inline unsigned int NumElements4Job(
unsigned int rank)
const
55 {
return NumElements4JobIn()+((rank<NumElements4JobOut()) ? 1 : 0); }
57 inline unsigned int StartElementIndex()
const
58 {
return ((fRank<NumElements4JobOut()) ? (fRank*NumElements4Job(fRank)) :
59 (fNelements-(fSize-fRank)*NumElements4Job(fRank))); }
61 inline unsigned int EndElementIndex()
const
62 {
return StartElementIndex()+NumElements4Job(fRank); }
64 inline unsigned int GetMPISize()
const {
return fSize; }
65 inline unsigned int GetMPIRank()
const {
return fRank; }
67 bool SyncVector(ROOT::Minuit2::MnAlgebraicVector &mnvector);
68 bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix);
70 static unsigned int GetMPIGlobalRank() { StartMPI();
return fgGlobalRank; }
71 static unsigned int GetMPIGlobalSize() { StartMPI();
return fgGlobalSize; }
72 static inline void StartMPI() {
74 if (!(MPI::Is_initialized())) {
76 std::cout <<
"Info --> MPIProcess::StartMPI: Start MPI on #"
77 << MPI::COMM_WORLD.Get_rank() <<
" processor"
80 fgGlobalSize = MPI::COMM_WORLD.Get_size();
81 fgGlobalRank = MPI::COMM_WORLD.Get_rank();
85 static void TerminateMPI() {
87 if (fgCommunicators[0]!=0 && fgCommunicators[1]!=0) {
88 delete fgCommunicators[0]; fgCommunicators[0] = 0; fgIndecesComm[0] = 0;
89 delete fgCommunicators[1]; fgCommunicators[1] = 0; fgIndecesComm[1] = 0;
97 static bool SetCartDimension(
unsigned int dimX,
unsigned int dimY);
98 static bool SetDoFirstMPICall(
bool doFirstMPICall =
true);
100 inline void SumReduce(
const double& sub,
double& total) {
105 fgCommunicator->Allreduce(&sub,&total,1,MPI::DOUBLE,MPI::SUM);
113 void MPISyncVector(
double *ivector,
int svector,
double *ovector);
117 unsigned int fNelements;
121 static unsigned int fgGlobalSize;
122 static unsigned int fgGlobalRank;
124 static unsigned int fgCartSizeX;
125 static unsigned int fgCartSizeY;
126 static unsigned int fgCartDimension;
127 static bool fgNewCart;
129 unsigned int fNumElements4JobIn;
130 unsigned int fNumElements4JobOut;
133 static MPI::Intracomm *fgCommunicator;
134 static int fgIndexComm;
135 static MPI::Intracomm *fgCommunicators[2];
136 static unsigned int fgIndecesComm[2];