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
25namespace ROOT {
26
27namespace Minuit2 {
28
30 public:
32#ifdef MPIPROC
33 if (MPI::Is_initialized() && !(MPI::Is_finalized())) {
34 std::cout << "Info --> MPITerminate:: End MPI on #"
35 << MPI::COMM_WORLD.Get_rank() << " processor"
36 << std::endl;
37
38 MPI::Finalize();
39 }
40#endif
41 }
42
43 };
44
45
46 class MPIProcess {
47 public:
48 MPIProcess(unsigned int nelements, unsigned int indexComm);
50
51 inline unsigned int NumElements4JobIn() const { return fNumElements4JobIn; }
52 inline unsigned int NumElements4JobOut() const { return fNumElements4JobOut; }
53
54 inline unsigned int NumElements4Job(unsigned int rank) const
55 { return NumElements4JobIn()+((rank<NumElements4JobOut()) ? 1 : 0); }
56
57 inline unsigned int StartElementIndex() const
60
61 inline unsigned int EndElementIndex() const
63
64 inline unsigned int GetMPISize() const { return fSize; }
65 inline unsigned int GetMPIRank() const { return fRank; }
66
69
70 static unsigned int GetMPIGlobalRank() { StartMPI(); return fgGlobalRank; }
71 static unsigned int GetMPIGlobalSize() { StartMPI(); return fgGlobalSize; }
72 static inline void StartMPI() {
73#ifdef MPIPROC
74 if (!(MPI::Is_initialized())) {
75 MPI::Init();
76 std::cout << "Info --> MPIProcess::StartMPI: Start MPI on #"
77 << MPI::COMM_WORLD.Get_rank() << " processor"
78 << std::endl;
79 }
80 fgGlobalSize = MPI::COMM_WORLD.Get_size();
81 fgGlobalRank = MPI::COMM_WORLD.Get_rank();
82#endif
83 }
84
85 static void TerminateMPI() {
86#ifdef MPIPROC
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;
90 }
91
93
94#endif
95 }
96
97 static bool SetCartDimension(unsigned int dimX, unsigned int dimY);
98 static bool SetDoFirstMPICall(bool doFirstMPICall = true);
99
100 inline void SumReduce(const double& sub, double& total) {
101 total = sub;
102
103#ifdef MPIPROC
104 if (fSize>1) {
105 fgCommunicator->Allreduce(&sub,&total,1,MPI::DOUBLE,MPI::SUM);
106 }
107#endif
108 }
109
110 private:
111
112#ifdef MPIPROC
113 void MPISyncVector(double *ivector, int svector, double *ovector);
114#endif
115
116 private:
117 unsigned int fNelements;
118 unsigned int fSize;
119 unsigned int fRank;
120
121 static unsigned int fgGlobalSize;
122 static unsigned int fgGlobalRank;
123
124 static unsigned int fgCartSizeX;
125 static unsigned int fgCartSizeY;
126 static unsigned int fgCartDimension;
127 static bool fgNewCart;
128
129 unsigned int fNumElements4JobIn;
131
132#ifdef MPIPROC
133 static MPI::Intracomm *fgCommunicator;
134 static int fgIndexComm; // maximum 2 communicators, so index can be 0 and 1
135 static MPI::Intracomm *fgCommunicators[2]; // maximum 2 communicators
136 static unsigned int fgIndecesComm[2];
137#endif
138
139 };
140
141} // namespace Minuit2
142} // namespace ROOT
143
144#endif
145
146
static unsigned int total
Class describing a symmetric matrix of size n.
Definition: LASymMatrix.h:51
unsigned int fNumElements4JobIn
Definition: MPIProcess.h:129
bool SyncVector(ROOT::Minuit2::MnAlgebraicVector &mnvector)
Definition: MPIProcess.cxx:160
static bool SetCartDimension(unsigned int dimX, unsigned int dimY)
static void StartMPI()
Definition: MPIProcess.h:72
MPIProcess(unsigned int nelements, unsigned int indexComm)
Definition: MPIProcess.cxx:35
static unsigned int fgCartSizeY
Definition: MPIProcess.h:125
unsigned int fNumElements4JobOut
Definition: MPIProcess.h:130
static unsigned int fgGlobalRank
Definition: MPIProcess.h:122
unsigned int GetMPIRank() const
Definition: MPIProcess.h:65
unsigned int NumElements4JobOut() const
Definition: MPIProcess.h:52
unsigned int GetMPISize() const
Definition: MPIProcess.h:64
unsigned int NumElements4Job(unsigned int rank) const
Definition: MPIProcess.h:54
unsigned int StartElementIndex() const
Definition: MPIProcess.h:57
static unsigned int GetMPIGlobalRank()
Definition: MPIProcess.h:70
static void TerminateMPI()
Definition: MPIProcess.h:85
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
Definition: MPIProcess.cxx:201
void SumReduce(const double &sub, double &total)
Definition: MPIProcess.h:100
static unsigned int fgGlobalSize
Definition: MPIProcess.h:121
static unsigned int GetMPIGlobalSize()
Definition: MPIProcess.h:71
static unsigned int fgCartDimension
Definition: MPIProcess.h:126
unsigned int NumElements4JobIn() const
Definition: MPIProcess.h:51
static unsigned int fgCartSizeX
Definition: MPIProcess.h:124
static bool SetDoFirstMPICall(bool doFirstMPICall=true)
unsigned int EndElementIndex() const
Definition: MPIProcess.h:61
VSD Structures.
Definition: StringConv.hxx:21
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:155