source: trunk/examples/extended/parallel/MPI/mpi_interface/include/G4MPImanager.hh@ 1350

Last change on this file since 1350 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 5.8 KB
Line 
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//
26// $Id: G4MPImanager.hh,v 1.2 2010/05/18 06:03:27 kmura Exp $
27// $Name: geant4-09-04-beta-01 $
28//
29// ====================================================================
30// G4MPImanager.hh
31//
32// 2007 Q
33// ====================================================================
34#ifndef G4MPI_MANAGER_H
35#define G4MPI_MANAGER_H
36
37#include "mpi.h"
38#include "globals.hh"
39#include <pthread.h>
40#include <fstream>
41
42// ====================================================================
43//
44// class definition
45//
46// ====================================================================
47class G4MPImessenger;
48class G4MPIsession;
49class G4MPIstatus;
50class G4VMPIseedGenerator;
51
52class G4MPImanager {
53private:
54 static G4MPImanager* theManager;
55 G4MPImessenger* messenger;
56 G4MPIsession* session;
57
58 G4int verbose;
59 G4MPIstatus* status; // status for each node
60
61 // MPI rank
62 G4bool isMaster;
63 G4bool isSlave;
64 G4int rank;
65 G4int size;
66
67 // MPI communicator
68 MPI::Intracomm COMM_G4COMMAND;
69
70 // cout/cerr control
71 G4bool qfcout;
72 std::ofstream fscout;
73
74 // init/macro file
75 G4bool qinitmacro;
76 G4String initFileName;
77 G4bool qbatchmode;
78 G4String macroFileName;
79
80 // internal use
81 void Initialize();
82 void ParseArguments(G4int argc, char** argv);
83 void Wait(G4int ausec) const;
84 void UpdateStatus();
85
86 // for beamOn
87 pthread_t threadID;
88
89 // seed generator
90 G4VMPIseedGenerator* seedGenerator;
91
92 // parallel parameters
93 G4double masterWeight;
94
95public:
96
97 enum { // MPI master rank
98 RANK_MASTER= 0
99 };
100
101 enum { // MPI tag
102 TAG_G4COMMAND= 100,
103 TAG_G4STATUS= 200,
104 TAG_G4SEED= 300,
105 TAG_DATA= 1000
106 };
107
108 G4MPImanager();
109 G4MPImanager(int argc, char** argv);
110 ~G4MPImanager();
111
112 static G4MPImanager* GetManager();
113
114 // set/get methods
115 G4MPIsession* GetMPIsession() const;
116
117 G4int GetVerbose() const;
118 void SetVerbose(G4int iverbose);
119
120 G4int GetSize() const;
121 G4int GetRank() const;
122
123 G4bool IsMaster() const;
124 G4bool IsSlave() const;
125
126 G4bool IsInitMacro() const;
127 const G4String& GetInitFileName() const;
128
129 G4bool IsBatchMode() const;
130 const G4String& GetMacroFileName() const;
131
132 void SetMasterWeight(G4double aweight);
133 G4double GetMasterWeight() const;
134
135 G4VMPIseedGenerator* GetSeedGenerator() const;
136
137 // MPI methods
138 G4String BcastCommand(const G4String& command);
139 void ShowStatus();
140 void ShowSeeds();
141 void SetSeed(G4int inode, G4long seed);
142 void WaitBeamOn();
143
144 // methods for MPI environment
145 void DistributeSeeds();
146 void ExecuteMacroFile(const G4String& fname, G4bool qbatch=false);
147 G4bool CheckThreadStatus();
148 void ExecuteThreadCommand(const G4String& command);
149 void ExecuteBeamOnThread(const G4String& command);
150 void JoinBeamOnThread();
151
152 void BeamOn(G4int nevent, G4bool qdivide=true);
153 void Print(const G4String& message);
154
155 // misc
156 void ShowHelp() const;
157
158};
159
160// ====================================================================
161// inline functions
162// ====================================================================
163
164inline G4MPIsession* G4MPImanager::GetMPIsession() const
165{
166 return session;
167}
168
169inline G4int G4MPImanager::GetVerbose() const
170{
171 return verbose;
172}
173
174inline void G4MPImanager::SetVerbose(G4int iverbose)
175{
176 G4int lv=iverbose;
177 if(iverbose>1) lv=1;
178 if(iverbose<0) lv=0;
179
180 verbose= lv;
181 return;
182}
183
184inline G4int G4MPImanager::GetRank() const
185{
186 return rank;
187}
188
189inline G4int G4MPImanager::GetSize() const
190{
191 return size;
192}
193
194inline G4bool G4MPImanager::IsMaster() const
195{
196 return isMaster;
197}
198
199inline G4bool G4MPImanager::IsSlave() const
200{
201 return isSlave;
202}
203
204inline G4bool G4MPImanager::IsInitMacro() const
205{
206 return qinitmacro;
207
208}
209
210inline const G4String& G4MPImanager::GetInitFileName() const
211{
212 return initFileName;
213
214}
215
216inline G4bool G4MPImanager::IsBatchMode() const
217{
218 return qbatchmode;
219}
220
221inline const G4String& G4MPImanager::GetMacroFileName() const
222{
223 return macroFileName;
224}
225
226inline void G4MPImanager::SetMasterWeight(G4double aweight)
227{
228 masterWeight= aweight;
229
230 if(aweight<0.) masterWeight= 0.;
231 if(aweight>1.) masterWeight= 1.;
232}
233
234inline G4double G4MPImanager::GetMasterWeight() const
235{
236 return masterWeight;
237}
238
239inline G4VMPIseedGenerator* G4MPImanager::GetSeedGenerator() const
240{
241 return seedGenerator;
242}
243
244#endif
Note: See TracBrowser for help on using the repository browser.