Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  kTAG_HISTO = 1001,
56  kTAG_RUN = 1002,
57  kTAG_CMDSCR = 1003
58  };
59 
60  G4MPImanager();
61  G4MPImanager(int argc, char** argv);
62  ~G4MPImanager();
63 
64  static G4MPImanager* GetManager();
65 
66  // set/get methods
67  G4MPIsession* GetMPIsession() const;
68 
69  G4int GetVerbose() const;
70  void SetVerbose(G4int iverbose);
71 
72  G4int GetSize() const;
73  G4int GetRank() const;
74 
75  G4bool IsMaster() const;
76  G4bool IsSlave() const;
77 
78  G4bool IsInitMacro() const;
79  const G4String& GetInitFileName() const;
80 
81  G4bool IsBatchMode() const;
82  const G4String& GetMacroFileName() const;
83 
84  void SetMasterWeight(G4double aweight);
85  G4double GetMasterWeight() const;
86 
88 
89  // MPI methods
90  G4String BcastCommand(const G4String& command);
91  void ShowStatus();
92  void ShowSeeds();
93  void SetSeed(G4int inode, G4long seed);
94  void WaitBeamOn();
95 
96  // methods for MPI environment
97  void DistributeSeeds();
98  void ExecuteMacroFile(const G4String& fname, G4bool qbatch=false);
100  void ExecuteThreadCommand(const G4String& command);
101  void ExecuteBeamOnThread(const G4String& command);
102  void JoinBeamOnThread();
103 
104  void BeamOn(G4int nevent, G4bool qdivide=true);
105  void Print(const G4String& message);
106 
107  // misc
108  void ShowHelp() const;
109 
110  //MPI::Intracomm* GetComm() const { return &COMM_G4COMMAND_; }
111 private:
112  DISALLOW_COPY_AND_ASSIGN(G4MPImanager);
113 
114  // internal use
115  void Initialize();
116  void ParseArguments(G4int argc, char** argv);
117  void UpdateStatus();
118 
119  static G4MPImanager* g4mpi_;
120  G4MPImessenger* messenger_;
121  G4MPIsession* session_;
122 
123  // seed generator
124  G4VMPIseedGenerator* seed_generator_;
125 
126  G4MPIstatus* status_; // status for each node
127 
128  G4int verbose_;
129 
130  // MPI rank
131  G4bool is_master_;
132  G4bool is_slave_;
133  G4int rank_;
134  G4int size_;
135 
136  // MPI communicator
137  MPI::Intracomm COMM_G4COMMAND_;
138 
139  // cout/cerr control
140  G4bool qfcout_;
141  std::ofstream fscout_;
142 
143  // init/macro file
144  G4bool qinitmacro_;
145  G4String init_file_name_;
146  G4bool qbatchmode_;
147  G4String macro_file_name_;
148 
149  // for beamOn
150  pthread_t thread_id_;
151 
152  // parallel parameters
153  G4double master_weight_;
154 };
155 
156 // ====================================================================
158 {
159  return session_;
160 }
161 
163 {
164  return verbose_;
165 }
166 
167 inline void G4MPImanager::SetVerbose(G4int iverbose)
168 {
169  G4int lv = iverbose;
170  if( iverbose > 1 ) lv = 1;
171  if( iverbose < 0 ) lv = 0;
172 
173  verbose_ = lv;
174  return;
175 }
176 
178 {
179  return rank_;
180 }
181 
183 {
184  return size_;
185 }
186 
188 {
189  return is_master_;
190 }
191 
193 {
194  return is_slave_;
195 }
196 
198 {
199  return qinitmacro_;
200 
201 }
202 
204 {
205  return init_file_name_;
206 
207 }
208 
210 {
211  return qbatchmode_;
212 }
213 
215 {
216  return macro_file_name_;
217 }
218 
220 {
221  master_weight_ = aweight;
222 
223  if( aweight < 0. ) master_weight_ = 0.;
224  if( aweight > 1. ) master_weight_ = 1.;
225 }
226 
228 {
229  return master_weight_;
230 }
231 
233 {
234  return seed_generator_;
235 }
236 
237 #endif
G4bool IsInitMacro() const
void JoinBeamOnThread()
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
G4bool IsMaster() const
const G4String & GetMacroFileName() const
int G4int
Definition: G4Types.hh:78
G4int GetVerbose() const
G4int GetRank() const
G4bool IsBatchMode() const
G4String BcastCommand(const G4String &command)
long seed
Definition: chem4.cc:68
void ShowHelp() const
void SetMasterWeight(G4double aweight)
bool G4bool
Definition: G4Types.hh:79
static G4MPImanager * GetManager()
void WaitBeamOn()
void DistributeSeeds()
void ShowStatus()
void Print(const G4String &message)
G4MPIsession * GetMPIsession() const
string fname
Definition: test.py:308
G4bool CheckThreadStatus()
void BeamOn(G4int nevent, G4bool qdivide=true)
double G4double
Definition: G4Types.hh:76
G4VMPIseedGenerator * GetSeedGenerator() const
void ExecuteMacroFile(const G4String &fname, G4bool qbatch=false)
G4bool IsSlave() const
void ExecuteBeamOnThread(const G4String &command)
void SetSeed(G4int inode, G4long seed)