| 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.1 2007/11/16 14:05:40 kmura Exp $
|
|---|
| 27 | // $Name: $
|
|---|
| 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 | // ====================================================================
|
|---|
| 47 | class G4MPImessenger;
|
|---|
| 48 | class G4MPIsession;
|
|---|
| 49 | class G4MPIstatus;
|
|---|
| 50 | class G4VMPIseedGenerator;
|
|---|
| 51 |
|
|---|
| 52 | class G4MPImanager {
|
|---|
| 53 | private:
|
|---|
| 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 |
|
|---|
| 95 | public:
|
|---|
| 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 |
|
|---|
| 143 | // methods for MPI environment
|
|---|
| 144 | void DistributeSeeds();
|
|---|
| 145 | void ExecuteMacroFile(const G4String& fname, G4bool qbatch=false);
|
|---|
| 146 | G4bool CheckThreadStatus();
|
|---|
| 147 | void ExecuteThreadCommand(const G4String& command);
|
|---|
| 148 | void ExecuteBeamOnThread(const G4String& command);
|
|---|
| 149 | void JoinBeamOnThread();
|
|---|
| 150 |
|
|---|
| 151 | void BeamOn(G4int nevent, G4bool qdivide=true);
|
|---|
| 152 | void Print(const G4String& message);
|
|---|
| 153 |
|
|---|
| 154 | // misc
|
|---|
| 155 | void ShowHelp() const;
|
|---|
| 156 |
|
|---|
| 157 | };
|
|---|
| 158 |
|
|---|
| 159 | // ====================================================================
|
|---|
| 160 | // inline functions
|
|---|
| 161 | // ====================================================================
|
|---|
| 162 |
|
|---|
| 163 | inline G4MPIsession* G4MPImanager::GetMPIsession() const
|
|---|
| 164 | {
|
|---|
| 165 | return session;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | inline G4int G4MPImanager::GetVerbose() const
|
|---|
| 169 | {
|
|---|
| 170 | return verbose;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | inline void G4MPImanager::SetVerbose(G4int iverbose)
|
|---|
| 174 | {
|
|---|
| 175 | G4int lv=iverbose;
|
|---|
| 176 | if(iverbose>1) lv=1;
|
|---|
| 177 | if(iverbose<0) lv=0;
|
|---|
| 178 |
|
|---|
| 179 | verbose= lv;
|
|---|
| 180 | return;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | inline G4int G4MPImanager::GetRank() const
|
|---|
| 184 | {
|
|---|
| 185 | return rank;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | inline G4int G4MPImanager::GetSize() const
|
|---|
| 189 | {
|
|---|
| 190 | return size;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | inline G4bool G4MPImanager::IsMaster() const
|
|---|
| 194 | {
|
|---|
| 195 | return isMaster;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | inline G4bool G4MPImanager::IsSlave() const
|
|---|
| 199 | {
|
|---|
| 200 | return isSlave;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | inline G4bool G4MPImanager::IsInitMacro() const
|
|---|
| 204 | {
|
|---|
| 205 | return qinitmacro;
|
|---|
| 206 |
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | inline const G4String& G4MPImanager::GetInitFileName() const
|
|---|
| 210 | {
|
|---|
| 211 | return initFileName;
|
|---|
| 212 |
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | inline G4bool G4MPImanager::IsBatchMode() const
|
|---|
| 216 | {
|
|---|
| 217 | return qbatchmode;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | inline const G4String& G4MPImanager::GetMacroFileName() const
|
|---|
| 221 | {
|
|---|
| 222 | return macroFileName;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | inline void G4MPImanager::SetMasterWeight(G4double aweight)
|
|---|
| 226 | {
|
|---|
| 227 | masterWeight= aweight;
|
|---|
| 228 |
|
|---|
| 229 | if(aweight<0.) masterWeight= 0.;
|
|---|
| 230 | if(aweight>1.) masterWeight= 1.;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | inline G4double G4MPImanager::GetMasterWeight() const
|
|---|
| 234 | {
|
|---|
| 235 | return masterWeight;
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | inline G4VMPIseedGenerator* G4MPImanager::GetSeedGenerator() const
|
|---|
| 239 | {
|
|---|
| 240 | return seedGenerator;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | #endif
|
|---|