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 << 27 #include "G4WorkerThread.hh" 33 #include "G4AutoLock.hh" << 28 #include "G4WorkerRunManager.hh" 34 #include "G4MTRunManagerKernel.hh" 29 #include "G4MTRunManagerKernel.hh" 35 #include "G4UImanager.hh" << 36 #include "G4VUserActionInitialization.hh" 30 #include "G4VUserActionInitialization.hh" >> 31 #include "G4UImanager.hh" 37 #include "G4VUserPhysicsList.hh" 32 #include "G4VUserPhysicsList.hh" 38 #include "G4WorkerRunManager.hh" << 33 #include "G4AutoLock.hh" 39 #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(G4WorkerThread* wTC) 46 { 44 { 47 // Note: this method is called by G4MTRunMan << 45 //Note: this method is called by G4MTRunManager, here we are still sequential 48 // here we are still sequential. << 46 //Create a new thread/worker structure 49 // Create a new thread/worker structure << 47 G4Thread* worker = new G4Thread; 50 auto worker = new G4Thread; << 48 #ifdef WIN32 51 G4THREADCREATE(worker, &G4MTRunManagerKernel << 49 G4THREADCREATE(worker, (LPTHREAD_START_ROUTINE)&G4MTRunManagerKernel::StartThread , wTC ); 52 return worker; << 50 #else >> 51 G4THREADCREATE(worker, &G4MTRunManagerKernel::StartThread , wTC ); >> 52 #endif >> 53 return worker; 53 } 54 } 54 #else 55 #else 55 G4Thread* G4UserWorkerThreadInitialization::Cr 56 G4Thread* G4UserWorkerThreadInitialization::CreateAndStartWorker(G4WorkerThread*) 56 { 57 { 57 return new G4Thread; << 58 return new G4Thread; 58 } 59 } 59 #endif 60 #endif 60 61 61 // ------------------------------------------- << 62 //Avoid compilation warning in sequential 62 #ifdef G4MULTITHREADED 63 #ifdef G4MULTITHREADED 63 void G4UserWorkerThreadInitialization::JoinWor 64 void G4UserWorkerThreadInitialization::JoinWorker(G4Thread* aThread) 64 { 65 { 65 G4THREADJOIN(*aThread); << 66 G4THREADJOIN(*aThread); >> 67 } >> 68 #else >> 69 void G4UserWorkerThreadInitialization::JoinWorker(G4Thread*) >> 70 { 66 } 71 } 67 #else // Avoid compilation warning in sequent << 68 void G4UserWorkerThreadInitialization::JoinWor << 69 #endif 72 #endif 70 73 71 // ------------------------------------------- << 74 G4UserWorkerThreadInitialization::G4UserWorkerThreadInitialization() 72 namespace << 75 {;} 73 { << 76 74 G4Mutex rngCreateMutex = G4MUTEX_INITIALIZER; << 77 G4UserWorkerThreadInitialization::~G4UserWorkerThreadInitialization() >> 78 {;} >> 79 >> 80 namespace { >> 81 G4Mutex rngCreateMutex = G4MUTEX_INITIALIZER; 75 } 82 } 76 83 77 // ------------------------------------------- << 84 #include "globals.hh" >> 85 78 void G4UserWorkerThreadInitialization::SetupRN 86 void G4UserWorkerThreadInitialization::SetupRNGEngine(const CLHEP::HepRandomEngine* aNewRNG) const 79 { 87 { 80 G4AutoLock l(&rngCreateMutex); << 88 G4AutoLock l(&rngCreateMutex); 81 // No default available, let's create the in << 89 //No default available, let's create the instance of random stuff 82 // A Call to this just forces the creation t << 90 //A Call to this just forces the creation to defaults 83 G4Random::getTheEngine(); << 91 G4Random::getTheEngine(); 84 // Poor man's solution to check which RNG En << 92 //Poor man's solution to check which RNG Engine is used in master thread 85 CLHEP::HepRandomEngine* retRNG = nullptr; << 93 CLHEP::HepRandomEngine* retRNG= 0; 86 << 94 87 // Need to make these calls thread safe << 95 // Need to make these calls thread safe 88 if (dynamic_cast<const CLHEP::HepJamesRandom << 96 if ( dynamic_cast<const CLHEP::HepJamesRandom*>(aNewRNG) ) { 89 retRNG = new CLHEP::HepJamesRandom; << 97 retRNG= new CLHEP::HepJamesRandom; 90 } << 98 } 91 else if (dynamic_cast<const CLHEP::MixMaxRng << 99 if ( dynamic_cast<const CLHEP::RanecuEngine*>(aNewRNG) ) { 92 retRNG = new CLHEP::MixMaxRng; << 100 retRNG= new CLHEP::RanecuEngine; 93 } << 101 } 94 else if (dynamic_cast<const CLHEP::RanecuEng << 102 if ( dynamic_cast<const CLHEP::Ranlux64Engine*>(aNewRNG) ) { 95 retRNG = new CLHEP::RanecuEngine; << 103 retRNG= new CLHEP::Ranlux64Engine; 96 } << 104 } 97 else if (dynamic_cast<const CLHEP::RanluxppE << 105 if ( dynamic_cast<const CLHEP::MTwistEngine*>(aNewRNG) ) { 98 retRNG = new CLHEP::RanluxppEngine; << 106 retRNG= new CLHEP::MTwistEngine; 99 } << 107 } 100 else if (dynamic_cast<const CLHEP::Ranlux64E << 108 if ( dynamic_cast<const CLHEP::DualRand*>(aNewRNG) ) { 101 const auto theRNG = dynamic_cast<const CLH << 109 retRNG= new CLHEP::DualRand; 102 retRNG = new CLHEP::Ranlux64Engine(123, th << 110 } 103 } << 111 if ( dynamic_cast<const CLHEP::RanluxEngine*>(aNewRNG) ) { 104 else if (dynamic_cast<const CLHEP::MTwistEng << 112 retRNG= new CLHEP::RanluxEngine; 105 retRNG = new CLHEP::MTwistEngine; << 113 } 106 } << 114 if ( dynamic_cast<const CLHEP::RanshiEngine*>(aNewRNG) ) { 107 else if (dynamic_cast<const CLHEP::DualRand* << 115 retRNG= new CLHEP::RanshiEngine; 108 retRNG = new CLHEP::DualRand; << 116 } 109 } << 117 110 else if (dynamic_cast<const CLHEP::RanluxEng << 118 if( retRNG != 0 ) { 111 const auto theRNG = dynamic_cast<const CLH << 119 G4Random::setTheEngine( retRNG ); 112 retRNG = new CLHEP::RanluxEngine(123, theR << 120 }else{ 113 } << 121 // Does a new method, such as aNewRng->newEngine() exist to clone it ? 114 else if (dynamic_cast<const CLHEP::RanshiEng << 122 G4ExceptionDescription msg; 115 retRNG = new CLHEP::RanshiEngine; << 123 msg<< " Unknown type of RNG Engine - " << G4endl 116 } << 124 << " Can cope only with HepJamesRandom, Ranecu, Ranlux64, MTwistEngine, DualRand, Ranlux or Ranshi." 117 << 125 << G4endl 118 if (retRNG != nullptr) { << 126 << " Cannot clone this type of RNG engine, as required for this thread" << G4endl 119 G4Random::setTheEngine(retRNG); << 127 << " Aborting " << G4endl; 120 } << 128 G4Exception("G4UserWorkerInitializition::SetupRNGEngine()", 121 else { << 129 "Run10099",FatalException,msg); 122 // Does a new method, such as aNewRng->new << 130 } 123 G4ExceptionDescription msg; << 124 msg << " Unknown type of RNG Engine - " << << 125 << " Can cope only with HepJamesRandom << 126 << " Ranlux++, MTwistEngine, DualRand, << 127 << " Cannot clone this type of RNG eng << 128 << " Aborting " << G4endl; << 129 G4Exception("G4UserWorkerThreadInitializat << 130 msg); << 131 } << 132 } 131 } 133 132 134 // ------------------------------------------- << 135 G4WorkerRunManager* G4UserWorkerThreadInitiali 133 G4WorkerRunManager* G4UserWorkerThreadInitialization::CreateWorkerRunManager() const 136 { 134 { 137 return new G4WorkerRunManager(); << 135 return new G4WorkerRunManager(); 138 } 136 } >> 137 139 138