Logo ROOT  
Reference Guide
MPIProcess.h
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Author: A. Lazzaro 2009
3 /***************************************************************************
4  * Package: Minuit2 *
5  * File: $Id$ *
6  * Author: Alfio Lazzaro, alfio.lazzaro@mi.infn.it *
7  * *
8  * Copyright: (C) 2008 by Universita' and INFN, Milan *
9  ***************************************************************************/
10 
11 #ifndef ROOT_Minuit2_MPIProcess
12 #define ROOT_Minuit2_MPIProcess
13 
14 // disable MPI calls
15 //#define MPIPROC
16 
17 #include "Minuit2/MnMatrix.h"
18 
19 #ifdef MPIPROC
20 #include "mpi.h"
21 #include <iostream>
22 #endif
23 
24 namespace ROOT {
25 
26 namespace Minuit2 {
27 
28 class MPITerminate {
29 public:
31  {
32 #ifdef MPIPROC
33  if (MPI::Is_initialized() && !(MPI::Is_finalized())) {
34  std::cout << "Info --> MPITerminate:: End MPI on #" << MPI::COMM_WORLD.Get_rank() << " processor" << std::endl;
35 
36  MPI::Finalize();
37  }
38 #endif
39  }
40 };
41 
42 class MPIProcess {
43 public:
44  MPIProcess(unsigned int nelements, unsigned int indexComm);
45  ~MPIProcess();
46 
47  inline unsigned int NumElements4JobIn() const { return fNumElements4JobIn; }
48  inline unsigned int NumElements4JobOut() const { return fNumElements4JobOut; }
49 
50  inline unsigned int NumElements4Job(unsigned int rank) const
51  {
52  return NumElements4JobIn() + ((rank < NumElements4JobOut()) ? 1 : 0);
53  }
54 
55  inline unsigned int StartElementIndex() const
56  {
59  }
60 
61  inline unsigned int EndElementIndex() const { return StartElementIndex() + NumElements4Job(fRank); }
62 
63  inline unsigned int GetMPISize() const { return fSize; }
64  inline unsigned int GetMPIRank() const { return fRank; }
65 
68 
69  static unsigned int GetMPIGlobalRank()
70  {
71  StartMPI();
72  return fgGlobalRank;
73  }
74  static unsigned int GetMPIGlobalSize()
75  {
76  StartMPI();
77  return fgGlobalSize;
78  }
79  static inline void StartMPI()
80  {
81 #ifdef MPIPROC
82  if (!(MPI::Is_initialized())) {
83  MPI::Init();
84  std::cout << "Info --> MPIProcess::StartMPI: Start MPI on #" << MPI::COMM_WORLD.Get_rank() << " processor"
85  << std::endl;
86  }
87  fgGlobalSize = MPI::COMM_WORLD.Get_size();
88  fgGlobalRank = MPI::COMM_WORLD.Get_rank();
89 #endif
90  }
91 
92  static void TerminateMPI()
93  {
94 #ifdef MPIPROC
95  if (fgCommunicators[0] != 0 && fgCommunicators[1] != 0) {
96  delete fgCommunicators[0];
97  fgCommunicators[0] = 0;
98  fgIndecesComm[0] = 0;
99  delete fgCommunicators[1];
100  fgCommunicators[1] = 0;
101  fgIndecesComm[1] = 0;
102  }
103 
104  MPITerminate();
105 
106 #endif
107  }
108 
109  static bool SetCartDimension(unsigned int dimX, unsigned int dimY);
110  static bool SetDoFirstMPICall(bool doFirstMPICall = true);
111 
112  inline void SumReduce(const double &sub, double &total)
113  {
114  total = sub;
115 
116 #ifdef MPIPROC
117  if (fSize > 1) {
118  fgCommunicator->Allreduce(&sub, &total, 1, MPI::DOUBLE, MPI::SUM);
119  }
120 #endif
121  }
122 
123 private:
124 #ifdef MPIPROC
125  void MPISyncVector(double *ivector, int svector, double *ovector);
126 #endif
127 
128 private:
129  unsigned int fNelements;
130  unsigned int fSize;
131  unsigned int fRank;
132 
133  static unsigned int fgGlobalSize;
134  static unsigned int fgGlobalRank;
135 
136  static unsigned int fgCartSizeX;
137  static unsigned int fgCartSizeY;
138  static unsigned int fgCartDimension;
139  static bool fgNewCart;
140 
141  unsigned int fNumElements4JobIn;
142  unsigned int fNumElements4JobOut;
143 
144 #ifdef MPIPROC
145  static MPI::Intracomm *fgCommunicator;
146  static int fgIndexComm; // maximum 2 communicators, so index can be 0 and 1
147  static MPI::Intracomm *fgCommunicators[2]; // maximum 2 communicators
148  static unsigned int fgIndecesComm[2];
149 #endif
150 };
151 
152 } // namespace Minuit2
153 } // namespace ROOT
154 
155 #endif
ROOT::Minuit2::MPIProcess::fRank
unsigned int fRank
Definition: MPIProcess.h:131
ROOT::Minuit2::MPIProcess::TerminateMPI
static void TerminateMPI()
Definition: MPIProcess.h:92
ROOT::Minuit2::MPIProcess::fgGlobalRank
static unsigned int fgGlobalRank
Definition: MPIProcess.h:134
ROOT::Minuit2::MPIProcess
Definition: MPIProcess.h:42
ROOT::Minuit2::LAVector
Definition: LAVector.h:32
ROOT::Minuit2::MPIProcess::StartElementIndex
unsigned int StartElementIndex() const
Definition: MPIProcess.h:55
ROOT::Minuit2::MPIProcess::fNumElements4JobOut
unsigned int fNumElements4JobOut
Definition: MPIProcess.h:142
ROOT::Minuit2::LASymMatrix
Class describing a symmetric matrix of size n.
Definition: LASymMatrix.h:45
ROOT::Minuit2::MPIProcess::GetMPIGlobalRank
static unsigned int GetMPIGlobalRank()
Definition: MPIProcess.h:69
ROOT::Minuit2::MPIProcess::GetMPISize
unsigned int GetMPISize() const
Definition: MPIProcess.h:63
ROOT::Minuit2::MPITerminate
Definition: MPIProcess.h:28
MnMatrix.h
ROOT::Minuit2::MPIProcess::StartMPI
static void StartMPI()
Definition: MPIProcess.h:79
ROOT::Minuit2::MPIProcess::NumElements4JobOut
unsigned int NumElements4JobOut() const
Definition: MPIProcess.h:48
total
static unsigned int total
Definition: TGWin32ProxyDefs.h:40
ROOT::Minuit2::MPIProcess::fNelements
unsigned int fNelements
Definition: MPIProcess.h:129
ROOT::Minuit2::MPIProcess::SetDoFirstMPICall
static bool SetDoFirstMPICall(bool doFirstMPICall=true)
ROOT::Minuit2::MPIProcess::SyncVector
bool SyncVector(ROOT::Minuit2::MnAlgebraicVector &mnvector)
Definition: MPIProcess.cxx:153
ROOT::Minuit2::MPIProcess::fgCartDimension
static unsigned int fgCartDimension
Definition: MPIProcess.h:138
ROOT::Minuit2::MPIProcess::SyncSymMatrixOffDiagonal
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
Definition: MPIProcess.cxx:193
ROOT::Minuit2::MPITerminate::~MPITerminate
~MPITerminate()
Definition: MPIProcess.h:30
ROOT::Minuit2::MPIProcess::fgCartSizeX
static unsigned int fgCartSizeX
Definition: MPIProcess.h:136
ROOT::Minuit2::MPIProcess::fgNewCart
static bool fgNewCart
Definition: MPIProcess.h:139
ROOT::Minuit2::MPIProcess::~MPIProcess
~MPIProcess()
Definition: MPIProcess.cxx:141
ROOT::Minuit2::MPIProcess::MPIProcess
MPIProcess(unsigned int nelements, unsigned int indexComm)
Definition: MPIProcess.cxx:35
ROOT::Minuit2::MPIProcess::GetMPIRank
unsigned int GetMPIRank() const
Definition: MPIProcess.h:64
TClassEdit::Init
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:154
ROOT::Minuit2::MPIProcess::fNumElements4JobIn
unsigned int fNumElements4JobIn
Definition: MPIProcess.h:141
ROOT::Minuit2::MPIProcess::EndElementIndex
unsigned int EndElementIndex() const
Definition: MPIProcess.h:61
ROOT::Minuit2::MPIProcess::SumReduce
void SumReduce(const double &sub, double &total)
Definition: MPIProcess.h:112
ROOT::Minuit2::MPIProcess::NumElements4JobIn
unsigned int NumElements4JobIn() const
Definition: MPIProcess.h:47
ROOT::Minuit2::MPIProcess::fgGlobalSize
static unsigned int fgGlobalSize
Definition: MPIProcess.h:133
ROOT::Minuit2::MPIProcess::SetCartDimension
static bool SetCartDimension(unsigned int dimX, unsigned int dimY)
ROOT::Minuit2::MPIProcess::fgCartSizeY
static unsigned int fgCartSizeY
Definition: MPIProcess.h:137
ROOT::Minuit2::MPIProcess::fSize
unsigned int fSize
Definition: MPIProcess.h:130
ROOT::Minuit2::MPIProcess::GetMPIGlobalSize
static unsigned int GetMPIGlobalSize()
Definition: MPIProcess.h:74
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MPIProcess::NumElements4Job
unsigned int NumElements4Job(unsigned int rank) const
Definition: MPIProcess.h:50