Loading...
Searching...
No Matches
G4MPImanager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25/// @file G4MPImanager.hh
26/// @brief MPI manager class
27
28#ifndef G4MPI_MANAGER_H
29#define G4MPI_MANAGER_H
30
31#include "mpi.h"
32#include <fstream>
33#include <pthread.h>
34#include "globals.hh"
35
36#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
37 TypeName(const TypeName&); \
38 void operator=(const TypeName&)
39
40class G4MPImessenger;
41class G4MPIsession;
42class G4MPIstatus;
45
46class G4MPImanager {
47public:
48 // MPI master rank
49 enum { kRANK_MASTER = 0 };
50
51 enum { // MPI tag
55 kTAG_DATA = 1000,
56 kTAG_HISTO = 1001,
57 kTAG_RUN = 1002,
59 kTAG_NTUPLE = 1004
60 };
61
62 G4MPImanager(int nof_extra_workers = 0);
63 G4MPImanager(int argc, char** argv, int nof_extra_workers = 0);
65
66 static G4MPImanager* GetManager();
67
68 // set/get methods
70
71 G4int GetVerbose() const;
72 void SetVerbose(G4int iverbose);
73
74 G4int GetTotalSize() const; // get size of all ranks
75 G4int GetActiveSize() const; // get size of ranks wher RunBeamOn is called
76 G4int GetRank() const;
77
78 G4bool IsMaster() const;
79 G4bool IsSlave() const;
80 G4bool IsExtraWorker() const;
81
82 G4bool IsInitMacro() const;
83 const G4String& GetInitFileName() const;
84
85 G4bool IsBatchMode() const;
86 const G4String& GetMacroFileName() const;
87
88 void SetMasterWeight(G4double aweight);
89 G4double GetMasterWeight() const;
90
91 void SetExtraWorker(G4VMPIextraWorker* extraWorker);
93
95
96 // MPI methods
97 G4String BcastCommand(const G4String& command);
98 void ShowStatus();
99 void ShowSeeds();
100 void SetSeed(G4int inode, G4long seed);
101 void WaitBeamOn();
102
103 // methods for MPI environment
104 void DistributeSeeds();
105 void ExecuteMacroFile(const G4String& fname, G4bool qbatch=false);
106 G4bool CheckThreadStatus();
107 void ExecuteThreadCommand(const G4String& command);
108 void ExecuteBeamOnThread(const G4String& command);
109 void JoinBeamOnThread();
110
111 void BeamOn(G4int nevent, G4bool qdivide=true);
112 void Print(const G4String& message);
113 G4int GetEventsInMaster() const {return fevents_in_master;}
114 G4int GetEventsInSlave() const {return fevents_in_slave;}
115
116 // misc
117 void ShowHelp() const;
118
119 const MPI::Intracomm* GetComm() const { return &COMM_G4COMMAND_; }
120 const MPI_Comm* GetProcessingComm() const { return &processing_comm_; }
121 const MPI_Comm* GetCollectingComm() const { return &collecting_comm_; }
122 const MPI_Comm* GetAllComm() const { return &all_comm_; }
123private:
125
126 // internal use
127 void Initialize();
128 void ParseArguments(G4int argc, char** argv);
129 void UpdateStatus();
130
135
136 // seed generator
138
139 G4MPIstatus* status_; // status for each node
140
141 G4int verbose_;
142
143 // MPI rank
145 G4bool is_slave_;
147 G4int rank_;
148 G4int size_; // processing comm size
149 G4int world_size_; // world comm size
150
151 // MPI communicator (when no extra ranks)
152 MPI::Intracomm COMM_G4COMMAND_;
153 // MPI communicator (processing ranks - if ntuple merging)
155 // MPI communicator (collecting ranks - if ntuple merging)
157 // MPI communicator (all ranks - if ntuple mergins)
158 MPI_Comm all_comm_;
159 // Interim data - need to be freed
160 MPI_Group world_group_;
163 MPI_Group all_group_;
164
165 // cout/cerr control
166 G4bool qfcout_;
167 std::ofstream fscout_;
168
169 // init/macro file
174
175 // for beamOn
176 pthread_t thread_id_;
179
180 // parallel parameters
183};
184
185// ====================================================================
187{
188 return session_;
189}
190
191inline G4int G4MPImanager::GetVerbose() const
192{
193 return verbose_;
194}
195
196inline void G4MPImanager::SetVerbose(G4int iverbose)
197{
198 G4int lv = iverbose;
199 if( iverbose > 1 ) lv = 1;
200 if( iverbose < 0 ) lv = 0;
201
202 verbose_ = lv;
203 return;
204}
205
206inline G4int G4MPImanager::GetRank() const
207{
208 return rank_;
209}
210
211inline G4int G4MPImanager::GetTotalSize() const
212{
213 return world_size_;
214}
215
216inline G4int G4MPImanager::GetActiveSize() const
217{
218 return size_;
219}
220
221inline G4bool G4MPImanager::IsMaster() const
222{
223 return is_master_;
224}
225
226inline G4bool G4MPImanager::IsSlave() const
227{
228 return is_slave_;
229}
230
231inline G4bool G4MPImanager::IsExtraWorker() const
232{
233 return is_extra_worker_;
234}
235
236inline G4bool G4MPImanager::IsInitMacro() const
237{
238 return qinitmacro_;
239
240}
241
243{
244 return init_file_name_;
245
246}
247
248inline G4bool G4MPImanager::IsBatchMode() const
249{
250 return qbatchmode_;
251}
252
254{
255 return macro_file_name_;
256}
257
258inline void G4MPImanager::SetMasterWeight(G4double aweight)
259{
260 master_weight_ = aweight;
261
262 if( aweight < 0. ) master_weight_ = 0.;
263 if( aweight > 1. ) master_weight_ = 1.;
264}
265
266inline G4double G4MPImanager::GetMasterWeight() const
267{
268 return master_weight_;
269}
270
275
280
281#endif
void ExecuteThreadCommand(const G4String &command)
G4MPImessenger * messenger_
MPI_Group world_group_
G4String macro_file_name_
G4bool IsExtraWorker() const
G4bool CheckThreadStatus()
void ExecuteBeamOnThread(const G4String &command)
void ExecuteMacroFile(const G4String &fname, G4bool qbatch=false)
MPI_Group collecting_group_
MPI_Group processing_group_
G4MPIsession * session_
DISALLOW_COPY_AND_ASSIGN(G4MPImanager)
static G4MPImanager * GetManager()
void ShowHelp() const
const MPI_Comm * GetCollectingComm() const
G4VMPIseedGenerator * GetSeedGenerator() const
const G4String & GetMacroFileName() const
MPI::Intracomm COMM_G4COMMAND_
MPI_Group all_group_
G4int fevents_in_master
static G4MPImanager * g4mpi_
void ParseArguments(G4int argc, char **argv)
G4int fevents_in_slave
void SetMasterWeight(G4double aweight)
const MPI_Comm * GetProcessingComm() const
void SetSeed(G4int inode, G4long seed)
void SetVerbose(G4int iverbose)
G4VMPIseedGenerator * seed_generator_
G4bool IsInitMacro() const
void UpdateStatus()
G4String init_file_name_
void DistributeSeeds()
G4int GetActiveSize() const
void Print(const G4String &message)
G4bool IsBatchMode() const
G4VMPIextraWorker * extra_worker_
void BeamOn(G4int nevent, G4bool qdivide=true)
G4int GetEventsInSlave() const
G4double master_weight_
G4String BcastCommand(const G4String &command)
G4bool is_extra_worker_
const MPI::Intracomm * GetComm() const
MPI_Comm all_comm_
MPI_Comm collecting_comm_
MPI_Comm processing_comm_
G4int GetTotalSize() const
pthread_t thread_id_
G4int GetRank() const
const MPI_Comm * GetAllComm() const
G4MPIstatus * status_
void SetExtraWorker(G4VMPIextraWorker *extraWorker)
const G4String & GetInitFileName() const
G4MPIsession * GetMPIsession() const
G4double GetMasterWeight() const
G4int GetEventsInMaster() const
G4VMPIextraWorker * GetExtraWorker() const
G4bool IsMaster() const
void JoinBeamOnThread()
std::ofstream fscout_
G4bool IsSlave() const
G4int nof_extra_workers_
G4int GetVerbose() const
void message(G4RunManager *runmanager)
ts_scorers example shows how to use global scorers.
Definition ts_scorers.cc:71

Applications | User Support | Publications | Collaboration