Geant4  10.00.p02
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 // ********************************************************************
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 
40 class G4MPImessenger;
41 class G4MPIsession;
42 class G4MPIstatus;
44 
45 class G4MPImanager {
46 public:
47  // MPI master rank
48  enum { kRANK_MASTER = 0 };
49 
50  enum { // MPI tag
53  kTAG_G4SEED = 300,
54  kTAG_DATA = 1000
55  };
56 
57  G4MPImanager();
58  G4MPImanager(int argc, char** argv);
59  ~G4MPImanager();
60 
61  static G4MPImanager* GetManager();
62 
63  // set/get methods
64  G4MPIsession* GetMPIsession() const;
65 
66  G4int GetVerbose() const;
67  void SetVerbose(G4int iverbose);
68 
69  G4int GetSize() const;
70  G4int GetRank() const;
71 
72  G4bool IsMaster() const;
73  G4bool IsSlave() const;
74 
75  G4bool IsInitMacro() const;
76  const G4String& GetInitFileName() const;
77 
78  G4bool IsBatchMode() const;
79  const G4String& GetMacroFileName() const;
80 
81  void SetMasterWeight(G4double aweight);
82  G4double GetMasterWeight() const;
83 
85 
86  // MPI methods
87  G4String BcastCommand(const G4String& command);
88  void ShowStatus();
89  void ShowSeeds();
90  void SetSeed(G4int inode, G4long seed);
91  void WaitBeamOn();
92 
93  // methods for MPI environment
94  void DistributeSeeds();
95  void ExecuteMacroFile(const G4String& fname, G4bool qbatch=false);
97  void ExecuteThreadCommand(const G4String& command);
98  void ExecuteBeamOnThread(const G4String& command);
99  void JoinBeamOnThread();
100 
101  void BeamOn(G4int nevent, G4bool qdivide=true);
102  void Print(const G4String& message);
103 
104  // misc
105  void ShowHelp() const;
106 
107 private:
109 
110  // internal use
111  void Initialize();
112  void ParseArguments(G4int argc, char** argv);
113  void UpdateStatus();
114 
118 
119  // seed generator
121 
122  G4MPIstatus* status_; // status for each node
123 
125 
126  // MPI rank
131 
132  // MPI communicator
133  MPI::Intracomm COMM_G4COMMAND_;
134 
135  // cout/cerr control
137  std::ofstream fscout_;
138 
139  // init/macro file
144 
145  // for beamOn
146  pthread_t thread_id_;
147 
148  // parallel parameters
150 };
151 
152 // ====================================================================
154 {
155  return session_;
156 }
157 
159 {
160  return verbose_;
161 }
162 
163 inline void G4MPImanager::SetVerbose(G4int iverbose)
164 {
165  G4int lv = iverbose;
166  if( iverbose > 1 ) lv = 1;
167  if( iverbose < 0 ) lv = 0;
168 
169  verbose_ = lv;
170  return;
171 }
172 
174 {
175  return rank_;
176 }
177 
179 {
180  return size_;
181 }
182 
184 {
185  return is_master_;
186 }
187 
189 {
190  return is_slave_;
191 }
192 
194 {
195  return qinitmacro_;
196 
197 }
198 
200 {
201  return init_file_name_;
202 
203 }
204 
206 {
207  return qbatchmode_;
208 }
209 
211 {
212  return macro_file_name_;
213 }
214 
216 {
217  master_weight_ = aweight;
218 
219  if( aweight < 0. ) master_weight_ = 0.;
220  if( aweight > 1. ) master_weight_ = 1.;
221 }
222 
224 {
225  return master_weight_;
226 }
227 
229 {
230  return seed_generator_;
231 }
232 
233 #endif
std::ofstream fscout_
G4bool IsInitMacro() const
void Initialize()
void JoinBeamOnThread()
G4String init_file_name_
G4int GetSize() const
void ShowSeeds()
const G4String & GetInitFileName() const
void SetVerbose(G4int iverbose)
void ExecuteThreadCommand(const G4String &command)
long G4long
Definition: G4Types.hh:80
G4double GetMasterWeight() const
pthread_t thread_id_
G4bool IsMaster() const
const G4String & GetMacroFileName() const
G4MPImessenger * messenger_
int G4int
Definition: G4Types.hh:78
G4int GetVerbose() const
G4int GetRank() const
G4bool qbatchmode_
G4bool IsBatchMode() const
G4String BcastCommand(const G4String &command)
void ShowHelp() const
void SetMasterWeight(G4double aweight)
bool G4bool
Definition: G4Types.hh:79
static G4MPImanager * g4mpi_
static G4MPImanager * GetManager()
G4double master_weight_
void ParseArguments(G4int argc, char **argv)
G4bool qinitmacro_
G4bool is_master_
void WaitBeamOn()
void DistributeSeeds()
void ShowStatus()
void Print(const G4String &message)
G4MPIsession * GetMPIsession() const
G4MPIstatus * status_
void UpdateStatus()
G4bool CheckThreadStatus()
void BeamOn(G4int nevent, G4bool qdivide=true)
double G4double
Definition: G4Types.hh:76
G4bool is_slave_
G4VMPIseedGenerator * seed_generator_
G4MPIsession * session_
G4VMPIseedGenerator * GetSeedGenerator() const
DISALLOW_COPY_AND_ASSIGN(G4MPImanager)
void ExecuteMacroFile(const G4String &fname, G4bool qbatch=false)
G4String macro_file_name_
G4bool IsSlave() const
MPI::Intracomm COMM_G4COMMAND_
void ExecuteBeamOnThread(const G4String &command)
void SetSeed(G4int inode, G4long seed)