Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4MPImanager.hh
이 파일의 문서화 페이지로 가기
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:
113 
114  // internal use
115  void Initialize();
116  void ParseArguments(G4int argc, char** argv);
117  void UpdateStatus();
118 
122 
123  // seed generator
125 
126  G4MPIstatus* status_; // status for each node
127 
129 
130  // MPI rank
135 
136  // MPI communicator
137  MPI::Intracomm COMM_G4COMMAND_;
138 
139  // cout/cerr control
141  std::ofstream fscout_;
142 
143  // init/macro file
148 
149  // for beamOn
150  pthread_t thread_id_;
151 
152  // parallel parameters
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
G4MPIstatus * status_
void Initialize()
MPI::Intracomm COMM_G4COMMAND_
const G4String & GetMacroFileName() const
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
void ShowSeeds()
static G4MPImanager * g4mpi_
G4VMPIseedGenerator * GetSeedGenerator() const
void SetSeed(G4int inode, G4long seed)
void ExecuteBeamOnThread(const G4String &command)
G4bool qinitmacro_
pthread_t thread_id_
G4bool qbatchmode_
G4bool IsInitMacro() const
G4double master_weight_
G4bool is_master_
G4String macro_file_name_
G4bool IsSlave() const
G4String init_file_name_
G4MPIsession * session_
G4MPIsession * GetMPIsession() const
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4bool is_slave_
void ShowStatus()
G4MPImessenger * messenger_
long G4long
Definition: G4Types.hh:80
long seed
Definition: chem4.cc:68
void SetVerbose(G4int iverbose)
G4String BcastCommand(const G4String &command)
G4bool IsBatchMode() const
static G4MPImanager * GetManager()
void DistributeSeeds()
void JoinBeamOnThread()
G4double GetMasterWeight() const
void ExecuteThreadCommand(const G4String &command)
G4int GetSize() const
void SetMasterWeight(G4double aweight)
void BeamOn(G4int nevent, G4bool qdivide=true)
G4bool CheckThreadStatus()
Int_t nevent
int G4int
Definition: G4Types.hh:78
DISALLOW_COPY_AND_ASSIGN(G4MPImanager)
G4int GetRank() const
void Print(const G4String &message)
void UpdateStatus()
void ShowHelp() const
G4bool IsMaster() const
G4VMPIseedGenerator * seed_generator_
void ExecuteMacroFile(const G4String &fname, G4bool qbatch=false)
const G4String & GetInitFileName() const
G4int GetVerbose() const
std::ofstream fscout_
void ParseArguments(G4int argc, char **argv)
void WaitBeamOn()