Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
24namespace ROOT {
25
26namespace Minuit2 {
27
29public:
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
43public:
44 MPIProcess(unsigned int nelements, unsigned int indexComm);
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
123private:
124#ifdef MPIPROC
125 void MPISyncVector(double *ivector, int svector, double *ovector);
126#endif
127
128private:
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;
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
static unsigned int total
Class describing a symmetric matrix of size n.
Definition LASymMatrix.h:45
unsigned int fNumElements4JobIn
Definition MPIProcess.h:141
bool SyncVector(ROOT::Minuit2::MnAlgebraicVector &mnvector)
static bool SetCartDimension(unsigned int dimX, unsigned int dimY)
static unsigned int fgCartSizeY
Definition MPIProcess.h:137
unsigned int fNumElements4JobOut
Definition MPIProcess.h:142
static unsigned int fgGlobalRank
Definition MPIProcess.h:134
unsigned int GetMPIRank() const
Definition MPIProcess.h:64
unsigned int NumElements4JobOut() const
Definition MPIProcess.h:48
unsigned int GetMPISize() const
Definition MPIProcess.h:63
unsigned int NumElements4Job(unsigned int rank) const
Definition MPIProcess.h:50
unsigned int StartElementIndex() const
Definition MPIProcess.h:55
static unsigned int GetMPIGlobalRank()
Definition MPIProcess.h:69
static void TerminateMPI()
Definition MPIProcess.h:92
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
void SumReduce(const double &sub, double &total)
Definition MPIProcess.h:112
static unsigned int fgGlobalSize
Definition MPIProcess.h:133
static unsigned int GetMPIGlobalSize()
Definition MPIProcess.h:74
static unsigned int fgCartDimension
Definition MPIProcess.h:138
unsigned int NumElements4JobIn() const
Definition MPIProcess.h:47
static unsigned int fgCartSizeX
Definition MPIProcess.h:136
static bool SetDoFirstMPICall(bool doFirstMPICall=true)
unsigned int EndElementIndex() const
Definition MPIProcess.h:61
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...