Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4UserWorkerThreadInitialization implementa << 27 // << 28 // Authors: M.Asai, A.Dotti (SLAC), 16 Septemb << 29 // ------------------------------------------- << 30 << 31 #include "G4UserWorkerThreadInitialization.hh" 26 #include "G4UserWorkerThreadInitialization.hh" 32 << 33 #include "G4AutoLock.hh" 27 #include "G4AutoLock.hh" 34 #include "G4MTRunManagerKernel.hh" 28 #include "G4MTRunManagerKernel.hh" 35 #include "G4UImanager.hh" 29 #include "G4UImanager.hh" 36 #include "G4VUserActionInitialization.hh" 30 #include "G4VUserActionInitialization.hh" 37 #include "G4VUserPhysicsList.hh" 31 #include "G4VUserPhysicsList.hh" 38 #include "G4WorkerRunManager.hh" 32 #include "G4WorkerRunManager.hh" 39 #include "G4WorkerThread.hh" 33 #include "G4WorkerThread.hh" 40 << 41 #include <sstream> 34 #include <sstream> 42 35 43 // ------------------------------------------- << 36 // Will need this for TPMalloc >> 37 //#ifdef G4MULTITHREADED >> 38 //#define TPMALLOCDEFINESTUB >> 39 //#include "tpmalloc/tpmallocstub.h" >> 40 //#endif >> 41 44 #ifdef G4MULTITHREADED 42 #ifdef G4MULTITHREADED 45 G4Thread* G4UserWorkerThreadInitialization::Cr << 43 G4Thread* G4UserWorkerThreadInitialization::CreateAndStartWorker( >> 44 G4WorkerThread* wTC) 46 { 45 { 47 // Note: this method is called by G4MTRunMan << 46 // Note: this method is called by G4MTRunManager, here we are still sequential 48 // here we are still sequential. << 49 // Create a new thread/worker structure 47 // Create a new thread/worker structure 50 auto worker = new G4Thread; << 48 G4Thread* worker = new G4Thread; 51 G4THREADCREATE(worker, &G4MTRunManagerKernel 49 G4THREADCREATE(worker, &G4MTRunManagerKernel::StartThread, wTC); 52 return worker; 50 return worker; 53 } 51 } 54 #else 52 #else 55 G4Thread* G4UserWorkerThreadInitialization::Cr << 53 G4Thread* G4UserWorkerThreadInitialization::CreateAndStartWorker( >> 54 G4WorkerThread*) 56 { 55 { 57 return new G4Thread; 56 return new G4Thread; 58 } 57 } 59 #endif 58 #endif 60 59 61 // ------------------------------------------- << 60 // Avoid compilation warning in sequential 62 #ifdef G4MULTITHREADED 61 #ifdef G4MULTITHREADED 63 void G4UserWorkerThreadInitialization::JoinWor 62 void G4UserWorkerThreadInitialization::JoinWorker(G4Thread* aThread) 64 { 63 { 65 G4THREADJOIN(*aThread); 64 G4THREADJOIN(*aThread); 66 } 65 } 67 #else // Avoid compilation warning in sequent << 66 #else 68 void G4UserWorkerThreadInitialization::JoinWor 67 void G4UserWorkerThreadInitialization::JoinWorker(G4Thread*) {} 69 #endif 68 #endif 70 69 71 // ------------------------------------------- << 70 G4UserWorkerThreadInitialization::G4UserWorkerThreadInitialization() { ; } >> 71 >> 72 G4UserWorkerThreadInitialization::~G4UserWorkerThreadInitialization() { ; } >> 73 72 namespace 74 namespace 73 { 75 { 74 G4Mutex rngCreateMutex = G4MUTEX_INITIALIZER; << 76 G4Mutex rngCreateMutex = G4MUTEX_INITIALIZER; 75 } 77 } 76 78 77 // ------------------------------------------- << 79 #include "globals.hh" 78 void G4UserWorkerThreadInitialization::SetupRN << 80 void G4UserWorkerThreadInitialization::SetupRNGEngine( >> 81 const CLHEP::HepRandomEngine* aNewRNG) const 79 { 82 { 80 G4AutoLock l(&rngCreateMutex); 83 G4AutoLock l(&rngCreateMutex); 81 // No default available, let's create the in 84 // No default available, let's create the instance of random stuff 82 // A Call to this just forces the creation t 85 // A Call to this just forces the creation to defaults 83 G4Random::getTheEngine(); 86 G4Random::getTheEngine(); 84 // Poor man's solution to check which RNG En 87 // Poor man's solution to check which RNG Engine is used in master thread 85 CLHEP::HepRandomEngine* retRNG = nullptr; << 88 CLHEP::HepRandomEngine* retRNG = 0; 86 89 87 // Need to make these calls thread safe 90 // Need to make these calls thread safe 88 if (dynamic_cast<const CLHEP::HepJamesRandom << 91 if(dynamic_cast<const CLHEP::HepJamesRandom*>(aNewRNG)) >> 92 { 89 retRNG = new CLHEP::HepJamesRandom; 93 retRNG = new CLHEP::HepJamesRandom; 90 } 94 } 91 else if (dynamic_cast<const CLHEP::MixMaxRng << 95 if(dynamic_cast<const CLHEP::MixMaxRng*>(aNewRNG)) >> 96 { 92 retRNG = new CLHEP::MixMaxRng; 97 retRNG = new CLHEP::MixMaxRng; 93 } 98 } 94 else if (dynamic_cast<const CLHEP::RanecuEng << 99 if(dynamic_cast<const CLHEP::RanecuEngine*>(aNewRNG)) >> 100 { 95 retRNG = new CLHEP::RanecuEngine; 101 retRNG = new CLHEP::RanecuEngine; 96 } 102 } 97 else if (dynamic_cast<const CLHEP::RanluxppE << 103 if(dynamic_cast<const CLHEP::Ranlux64Engine*>(aNewRNG)) 98 retRNG = new CLHEP::RanluxppEngine; << 104 { 99 } << 105 const CLHEP::Ranlux64Engine* theRNG = 100 else if (dynamic_cast<const CLHEP::Ranlux64E << 106 dynamic_cast<const CLHEP::Ranlux64Engine*>(aNewRNG); 101 const auto theRNG = dynamic_cast<const CLH << 102 retRNG = new CLHEP::Ranlux64Engine(123, th 107 retRNG = new CLHEP::Ranlux64Engine(123, theRNG->getLuxury()); 103 } 108 } 104 else if (dynamic_cast<const CLHEP::MTwistEng << 109 if(dynamic_cast<const CLHEP::MTwistEngine*>(aNewRNG)) >> 110 { 105 retRNG = new CLHEP::MTwistEngine; 111 retRNG = new CLHEP::MTwistEngine; 106 } 112 } 107 else if (dynamic_cast<const CLHEP::DualRand* << 113 if(dynamic_cast<const CLHEP::DualRand*>(aNewRNG)) >> 114 { 108 retRNG = new CLHEP::DualRand; 115 retRNG = new CLHEP::DualRand; 109 } 116 } 110 else if (dynamic_cast<const CLHEP::RanluxEng << 117 if(dynamic_cast<const CLHEP::RanluxEngine*>(aNewRNG)) 111 const auto theRNG = dynamic_cast<const CLH << 118 { >> 119 const CLHEP::RanluxEngine* theRNG = >> 120 dynamic_cast<const CLHEP::RanluxEngine*>(aNewRNG); 112 retRNG = new CLHEP::RanluxEngine(123, theR 121 retRNG = new CLHEP::RanluxEngine(123, theRNG->getLuxury()); 113 } 122 } 114 else if (dynamic_cast<const CLHEP::RanshiEng << 123 if(dynamic_cast<const CLHEP::RanshiEngine*>(aNewRNG)) >> 124 { 115 retRNG = new CLHEP::RanshiEngine; 125 retRNG = new CLHEP::RanshiEngine; 116 } 126 } 117 127 118 if (retRNG != nullptr) { << 128 if(retRNG != 0) >> 129 { 119 G4Random::setTheEngine(retRNG); 130 G4Random::setTheEngine(retRNG); 120 } 131 } 121 else { << 132 else >> 133 { 122 // Does a new method, such as aNewRng->new 134 // Does a new method, such as aNewRng->newEngine() exist to clone it ? 123 G4ExceptionDescription msg; 135 G4ExceptionDescription msg; 124 msg << " Unknown type of RNG Engine - " << 136 msg << " Unknown type of RNG Engine - " << G4endl 125 << " Can cope only with HepJamesRandom 137 << " Can cope only with HepJamesRandom, MixMaxRng, Ranecu, Ranlux64," 126 << " Ranlux++, MTwistEngine, DualRand, << 138 << " MTwistEngine, DualRand, Ranlux or Ranshi." << G4endl 127 << " Cannot clone this type of RNG eng << 139 << " Cannot clone this type of RNG engine, as required for this thread" 128 << " Aborting " << G4endl; << 140 << G4endl << " Aborting " << G4endl; 129 G4Exception("G4UserWorkerThreadInitializat << 141 G4Exception("G4UserWorkerInitializition::SetupRNGEngine()", "Run0122", 130 msg); << 142 FatalException, msg); 131 } 143 } 132 } 144 } 133 145 134 // ------------------------------------------- << 146 G4WorkerRunManager* G4UserWorkerThreadInitialization::CreateWorkerRunManager() 135 G4WorkerRunManager* G4UserWorkerThreadInitiali << 147 const 136 { 148 { 137 return new G4WorkerRunManager(); 149 return new G4WorkerRunManager(); 138 } 150 } 139 151