Import Geant4 11.1.0.beta source tree
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28th 2020)
|
||||
//
|
||||
// class description:
|
||||
// This is a class creates a G4RunManager instance. Once can specify an
|
||||
// enumerated value to set the default. If "G4RunManagerType::Default"
|
||||
// is used,
|
||||
//
|
||||
|
||||
#ifndef G4RunManagerFactory_hh
|
||||
#define G4RunManagerFactory_hh 1
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4MTRunManager.hh"
|
||||
#include "G4TaskRunManager.hh"
|
||||
#include "G4VUserTaskQueue.hh"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <regex>
|
||||
|
||||
//============================================================================//
|
||||
|
||||
enum class G4RunManagerType : G4int
|
||||
{
|
||||
Serial = 0,
|
||||
SerialOnly = 1,
|
||||
MT = 2,
|
||||
MTOnly = 3,
|
||||
Tasking = 4,
|
||||
TaskingOnly = 5,
|
||||
TBB = 6,
|
||||
TBBOnly = 7,
|
||||
Default
|
||||
};
|
||||
|
||||
//============================================================================//
|
||||
|
||||
class G4RunManagerFactory
|
||||
{
|
||||
public:
|
||||
static G4RunManager* CreateRunManager(
|
||||
G4RunManagerType _type = G4RunManagerType::Default,
|
||||
G4VUserTaskQueue* _queue = nullptr, G4bool fail_if_unavail = true,
|
||||
G4int nthreads = 0);
|
||||
|
||||
// provide a version which specifies to fail if unavailable
|
||||
static G4RunManager* CreateRunManager(G4RunManagerType _type,
|
||||
G4bool fail_if_unavail,
|
||||
G4int nthreads = 0,
|
||||
G4VUserTaskQueue* _queue = nullptr)
|
||||
{
|
||||
return CreateRunManager(_type, _queue, fail_if_unavail, nthreads);
|
||||
}
|
||||
|
||||
static G4RunManager* CreateRunManager(G4RunManagerType _type, G4int nthreads,
|
||||
G4bool fail_if_unavail = true,
|
||||
G4VUserTaskQueue* _queue = nullptr)
|
||||
{
|
||||
return CreateRunManager(_type, _queue, fail_if_unavail, nthreads);
|
||||
}
|
||||
|
||||
// provide string versions of above
|
||||
template <typename... Args>
|
||||
static G4RunManager* CreateRunManager(std::string type, Args&&... args)
|
||||
{
|
||||
return CreateRunManager(GetType(type), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static std::string GetDefault();
|
||||
static std::string GetName(G4RunManagerType);
|
||||
static G4RunManagerType GetType(const std::string&);
|
||||
static std::set<std::string> GetOptions();
|
||||
static G4RunManager* GetMasterRunManager();
|
||||
static G4MTRunManager* GetMTMasterRunManager();
|
||||
static G4RunManagerKernel* GetMasterRunManagerKernel();
|
||||
};
|
||||
|
||||
#endif // G4TaskRunManagerCreator_h
|
||||
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28st 2020)
|
||||
//
|
||||
// class description:
|
||||
// This is a class for run control in GEANT4 for multi-threaded runs
|
||||
// It extends G4RunManager re-implementing multi-threaded behavior in
|
||||
// key methods. See documentation for G4RunManager
|
||||
// Users initializes an instance of this class instead of G4RunManager
|
||||
// to start a multi-threaded simulation.
|
||||
|
||||
#ifndef G4TaskRunManager_hh
|
||||
#define G4TaskRunManager_hh 1
|
||||
|
||||
#include "rundefs.hh"
|
||||
#include "G4MTBarrier.hh"
|
||||
#include "G4MTRunManager.hh"
|
||||
#include "G4RNGHelper.hh"
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4TBBTaskGroup.hh"
|
||||
#include "G4TaskGroup.hh"
|
||||
#include "G4TaskManager.hh"
|
||||
#include "G4ThreadPool.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4VUserTaskQueue.hh"
|
||||
#include "G4EnvironmentUtils.hh"
|
||||
#include "G4Profiler.hh"
|
||||
|
||||
#include "PTL/TaskRunManager.hh"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
class G4TaskRunManagerKernel;
|
||||
class G4ScoringManager;
|
||||
class G4UserTaskInitialization;
|
||||
class G4UserTaskThreadInitialization;
|
||||
class G4WorkerTaskRunManager;
|
||||
class G4RunManagerFactory;
|
||||
|
||||
//============================================================================//
|
||||
|
||||
class G4TaskRunManager
|
||||
: public G4MTRunManager
|
||||
, public PTL::TaskRunManager
|
||||
{
|
||||
friend class G4RunManagerFactory;
|
||||
|
||||
public:
|
||||
// the profiler aliases are only used when compiled with GEANT4_USE_TIMEMORY
|
||||
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>;
|
||||
|
||||
public:
|
||||
using InitializeSeedsCallback = std::function<G4bool(G4int, G4int&, G4int&)>;
|
||||
using RunTaskGroup = G4TaskGroup<void>;
|
||||
|
||||
public:
|
||||
// Parameters:
|
||||
// taskQueue : provide a custom task queue
|
||||
// useTBB : only relevant if GEANT4_USE_TBB defined
|
||||
// evtGrainsize : the number of events per task
|
||||
G4TaskRunManager(G4bool useTBB = G4GetEnv<G4bool>("G4USE_TBB", false));
|
||||
G4TaskRunManager(G4VUserTaskQueue* taskQueue,
|
||||
G4bool useTBB = G4GetEnv<G4bool>("G4USE_TBB", false),
|
||||
G4int evtGrainsize = 0);
|
||||
virtual ~G4TaskRunManager();
|
||||
|
||||
public:
|
||||
void SetGrainsize(G4int n) { eventGrainsize = n; }
|
||||
G4int GetGrainsize() const { return eventGrainsize; }
|
||||
inline G4int GetNumberOfTasks() const { return numberOfTasks; }
|
||||
inline G4int GetNumberOfEventsPerTask() const
|
||||
{
|
||||
return numberOfEventsPerTask;
|
||||
}
|
||||
|
||||
virtual void SetNumberOfThreads(G4int n) override;
|
||||
virtual G4int GetNumberOfThreads() const override
|
||||
{
|
||||
return PTL::TaskRunManager::GetNumberOfThreads();
|
||||
}
|
||||
virtual size_t GetNumberActiveThreads() const override
|
||||
{
|
||||
return PTL::TaskRunManager::GetNumberActiveThreads();
|
||||
}
|
||||
static G4ThreadId GetMasterThreadId();
|
||||
|
||||
public:
|
||||
// Inherited methods to re-implement for MT case
|
||||
virtual void Initialize() override;
|
||||
virtual void InitializeEventLoop(G4int n_event,
|
||||
const char* macroFile = nullptr,
|
||||
G4int n_select = -1) override;
|
||||
virtual void InitializeThreadPool() override;
|
||||
G4bool ThreadPoolIsInitialized() const { return poolInitialized; }
|
||||
|
||||
virtual void Initialize(uint64_t nthreads) override
|
||||
{
|
||||
PTL::TaskRunManager::Initialize(nthreads);
|
||||
}
|
||||
|
||||
virtual void TerminateOneEvent() override;
|
||||
virtual void ProcessOneEvent(G4int i_event) override;
|
||||
virtual void ConstructScoringWorlds() override;
|
||||
virtual void RunTermination() override;
|
||||
|
||||
// The following method should be invoked by G4WorkerTaskRunManager for each
|
||||
// event. False is returned if no more event to be processed. Note: G4Event
|
||||
// object must be instantiated by a worker thread. In case no more
|
||||
// event remains to be processed, that worker thread must delete that G4Event
|
||||
// object. If a worker runs with its own random number sequence, the Boolean
|
||||
// flag reseedRequired should be set to false. This is *NOT* allowed for the
|
||||
// first event.
|
||||
virtual G4bool SetUpAnEvent(G4Event*, G4long& s1, G4long& s2, G4long& s3,
|
||||
G4bool reseedRequired = true) override;
|
||||
// Same as above method, but the seeds are set only once over "eventModulo"
|
||||
// events. The return value shows the number of events the caller Worker has
|
||||
// to process (between 1 and eventModulo depending on number of events yet to
|
||||
// be processed). G4Event object has the event ID of the first event of this
|
||||
// bunch. If zero is returned no more event needs to be processed, and worker
|
||||
// thread must delete that G4Event.
|
||||
virtual G4int SetUpNEvents(G4Event*, G4SeedsQueue* seedsQueue,
|
||||
G4bool reseedRequired = true) override;
|
||||
|
||||
// Method called by Initialize() method
|
||||
|
||||
protected:
|
||||
virtual void ComputeNumberOfTasks();
|
||||
// Initialize the seeds list, if derived class does not implement this method
|
||||
// A default generation will be used (nevents*2 random seeds)
|
||||
// Return true if initialization is done.
|
||||
virtual G4bool InitializeSeeds(G4int /*nevts*/) override { return false; }
|
||||
virtual void RefillSeeds() override;
|
||||
// Adds one seed to the list of seeds
|
||||
virtual void StoreRNGStatus(const G4String& filenamePrefix) override;
|
||||
virtual void CreateAndStartWorkers() override;
|
||||
// Creates worker threads and signal to start
|
||||
|
||||
protected:
|
||||
virtual void TerminateWorkers() override;
|
||||
|
||||
public: // with description
|
||||
static G4TaskRunManager* GetMasterRunManager()
|
||||
{
|
||||
auto* _rm = G4MTRunManager::GetMasterRunManager();
|
||||
return dynamic_cast<G4TaskRunManager*>(_rm);
|
||||
}
|
||||
// Returns the singleton instance of the run manager common to all threads
|
||||
// implementing the master behavior
|
||||
static G4TaskRunManagerKernel* GetMTMasterRunManagerKernel();
|
||||
// Returns the singleton instance of the run manager kernel common to all
|
||||
// threads
|
||||
|
||||
public:
|
||||
// To be invoked solely from G4WorkerTaskRunManager to merge the results
|
||||
void MergeScores(const G4ScoringManager* localScoringManager);
|
||||
void MergeRun(const G4Run* localRun);
|
||||
|
||||
public:
|
||||
virtual void RequestWorkersProcessCommandsStack() override;
|
||||
// Called to force workers to request and process the UI commands stack
|
||||
// This will block untill all workers have processed UI commands
|
||||
virtual void ThisWorkerProcessCommandsStackDone() override;
|
||||
// Called by workers to signal to master it has completed processing of
|
||||
// UI commands
|
||||
// virtual WorkerActionRequest ThisWorkerWaitForNextAction();
|
||||
// Worker thread barrier
|
||||
// This method should be used by workers' run manager to wait,
|
||||
// after an event loop for the next action to be performed
|
||||
// (for example execute a new run)
|
||||
// This returns the action to be performed
|
||||
virtual void WaitForReadyWorkers() override {}
|
||||
virtual void WaitForEndEventLoopWorkers() override;
|
||||
virtual void ThisWorkerReady() override {}
|
||||
virtual void ThisWorkerEndEventLoop() override {}
|
||||
virtual WorkerActionRequest ThisWorkerWaitForNextAction() override
|
||||
{
|
||||
return WorkerActionRequest::UNDEFINED;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void NewActionRequest(WorkerActionRequest) override {}
|
||||
virtual void AddEventTask(G4int);
|
||||
|
||||
public:
|
||||
inline void SetInitializeSeedsCallback(InitializeSeedsCallback f)
|
||||
{
|
||||
initSeedsCallback = f;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void AbortRun(G4bool softAbort = false) override;
|
||||
virtual void AbortEvent() override;
|
||||
|
||||
private:
|
||||
// grainsize
|
||||
bool workersStarted = false;
|
||||
G4int eventGrainsize = 0;
|
||||
G4int numberOfEventsPerTask = -1;
|
||||
G4int numberOfTasks = -1;
|
||||
CLHEP::HepRandomEngine* masterRNGEngine = nullptr;
|
||||
// Pointer to the master thread random engine
|
||||
G4TaskRunManagerKernel* MTkernel = nullptr;
|
||||
|
||||
protected:
|
||||
// Barriers: synch points between master and workers
|
||||
RunTaskGroup* workTaskGroup = nullptr;
|
||||
|
||||
// aliases to inherited member values
|
||||
G4bool& poolInitialized = PTL::TaskRunManager::m_is_initialized;
|
||||
G4ThreadPool*& threadPool = PTL::TaskRunManager::m_thread_pool;
|
||||
G4VUserTaskQueue*& taskQueue = PTL::TaskRunManager::m_task_queue;
|
||||
G4TaskManager*& taskManager = PTL::TaskRunManager::m_task_manager;
|
||||
|
||||
InitializeSeedsCallback initSeedsCallback = [](G4int, G4int&, G4int&) {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // G4TaskRunManager_hh
|
||||
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28st 2020)
|
||||
//
|
||||
// class description:
|
||||
//
|
||||
// This is a class for mandatory control of GEANT4 kernel.
|
||||
// This class implements Worker behavior in a MT application.
|
||||
//
|
||||
// This class is constructed by G4TaskRunManager. If a user uses his/her own
|
||||
// class instead of G4TaskRunManager, this class must be instantiated by
|
||||
// him/herself at the very beginning of the application and must be deleted
|
||||
// at the very end of the application. Also, following methods must be
|
||||
// invoked in the proper order.
|
||||
// DefineWorldVolume
|
||||
// InitializePhysics
|
||||
// RunInitialization
|
||||
// RunTermination
|
||||
//
|
||||
// User must provide his/her own classes derived from the following
|
||||
// abstract class and register it to the RunManagerKernel.
|
||||
// G4VUserPhysicsList - Particle types, Processes and Cuts
|
||||
//
|
||||
// G4TaskRunManagerKernel does not have any eveny loop. Handling of events
|
||||
// is managed by G4RunManager.
|
||||
//
|
||||
// This class re-implements only the method that require special treatment
|
||||
// to implement worker behavior
|
||||
|
||||
#ifndef G4TaskRunManagerKernel_hh
|
||||
#define G4TaskRunManagerKernel_hh 1
|
||||
|
||||
#include "rundefs.hh"
|
||||
#include "G4RunManagerKernel.hh"
|
||||
#include "G4TaskRunManager.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
class G4WorkerThread;
|
||||
class G4WorkerTaskRunManager;
|
||||
#include <vector>
|
||||
|
||||
class G4TaskRunManagerKernel : public G4RunManagerKernel
|
||||
{
|
||||
public:
|
||||
G4TaskRunManagerKernel();
|
||||
virtual ~G4TaskRunManagerKernel();
|
||||
|
||||
public: // with descroption
|
||||
static G4WorkerThread* GetWorkerThread();
|
||||
// G4ThreadPool tasks
|
||||
static void InitializeWorker();
|
||||
static void ExecuteWorkerInit();
|
||||
static void ExecuteWorkerTask();
|
||||
static void TerminateWorkerRunEventLoop();
|
||||
static void TerminateWorker();
|
||||
static void TerminateWorkerRunEventLoop(G4WorkerTaskRunManager*);
|
||||
static void TerminateWorker(G4WorkerTaskRunManager*);
|
||||
|
||||
static std::vector<G4String>& InitCommandStack();
|
||||
// Fill decay tables with particle definition pointers of
|
||||
// decay products. This method has to be invoked by
|
||||
// MTRunManager before event loop starts on workers.
|
||||
void SetUpDecayChannels();
|
||||
// This method should be invoked by G4TaskRunManager
|
||||
void BroadcastAbortRun(G4bool softAbort);
|
||||
|
||||
protected:
|
||||
void SetupShadowProcess() const;
|
||||
G4RUN_DLL static std::vector<G4String> initCmdStack;
|
||||
};
|
||||
|
||||
#endif // G4TaskRunManagerKernel_hh
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28st 2020)
|
||||
//
|
||||
// class description:
|
||||
//
|
||||
// This class is used for multi-threaded Geant4.
|
||||
// The object of this class can be set to G4MTRunManager, but not to
|
||||
// G4RunManager. G4UserTaskInitialization class has five virtual methods as
|
||||
// the user hooks which are invoked at several occasions of the life cycle
|
||||
// of each thread.
|
||||
//
|
||||
// - virtual void WorkerInitialize() const
|
||||
// This method is called after the tread is created but before the
|
||||
// G4WorkerTaskRunManager is instantiated.
|
||||
// - virtual void WorkerStart() const
|
||||
// This method is called once at the beginning of simulation job when
|
||||
// kernel classes and user action classes have already instantiated but
|
||||
// geometry and physics have not been yet initialized. This situation is
|
||||
// identical to "PreInit" state in the sequential mode.
|
||||
// - virtual void WorkerRunStart() const
|
||||
// This method is called before an event loop. Geometry and physics have
|
||||
// already been set up for the thread. All threads are synchronized and
|
||||
// ready to start the local event loop. This situation is identical to
|
||||
// "Idle" state in the sequential mode.
|
||||
// - virtual void WorkerRunEnd() const
|
||||
// This method is called for each thread when the local event loop is
|
||||
// done, but before the synchronization over threads.
|
||||
// - virtual void WorkerStop() const
|
||||
// This method is called once at the end of simulation job.
|
||||
//
|
||||
// Note: This object should be instantiated only once and set to
|
||||
// G4MTRunManager,
|
||||
// while these five methods are invoked for each worker thread. Thus, to
|
||||
// store thread-local objects, use G4ThreadLocal keyword.
|
||||
//
|
||||
|
||||
#ifndef G4UserTaskInitialization_hh
|
||||
#define G4UserTaskInitialization_hh
|
||||
|
||||
#include "G4UserWorkerInitialization.hh"
|
||||
|
||||
class G4UserTaskInitialization : public G4UserWorkerInitialization
|
||||
{
|
||||
public: // with description
|
||||
G4UserTaskInitialization();
|
||||
virtual ~G4UserTaskInitialization();
|
||||
|
||||
virtual void WorkerInitialize() const;
|
||||
// This method is called after the tread is created but before the
|
||||
// G4WorkerTaskRunManager is instantiated.
|
||||
|
||||
virtual void WorkerStart() const;
|
||||
// This method is called once at the beginning of simulation job
|
||||
// when kernel classes and user action classes have already instantiated
|
||||
// but geometry and physics have not been yet initialized. This situation
|
||||
// is identical to "PreInit" state in the sequential mode.
|
||||
|
||||
virtual void WorkerRunStart() const;
|
||||
// This method is called before an event loop. Geometry and physics have
|
||||
// already been set up for the thread. All threads are synchronized and
|
||||
// ready to start the local event loop. This situation is identical to
|
||||
// "Idle" state in the sequential mode.
|
||||
|
||||
virtual void WorkerRunEnd() const;
|
||||
// This method is called for each thread, when the local event loop has
|
||||
// finished but before the synchronization over threads.
|
||||
|
||||
virtual void WorkerStop() const;
|
||||
// This method is called once at the end of simulation job.
|
||||
// Implement here a clean up action.
|
||||
};
|
||||
|
||||
#endif // G4UserTaskInitialization_hh
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28st 2020)
|
||||
//
|
||||
// class description:
|
||||
//
|
||||
// This class is used for multi-threaded Geant4.
|
||||
// It encapsulates the mechanism of starting/stopping threads.
|
||||
|
||||
#ifndef G4UserTaskThreadInitialization_hh
|
||||
#define G4UserTaskThreadInitialization_hh
|
||||
|
||||
class G4VUserPrimaryGeneratorAction;
|
||||
class G4UserRunAction;
|
||||
class G4UserEventAction;
|
||||
class G4UserStackingAction;
|
||||
class G4UserTrackingAction;
|
||||
class G4UserSteppingAction;
|
||||
|
||||
class G4WorkerThread;
|
||||
class G4WorkerTaskRunManager;
|
||||
|
||||
#include "G4Threading.hh"
|
||||
#include "G4UserWorkerThreadInitialization.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
class G4UserTaskThreadInitialization : public G4UserWorkerThreadInitialization
|
||||
{
|
||||
public: // with description
|
||||
G4UserTaskThreadInitialization();
|
||||
virtual ~G4UserTaskThreadInitialization();
|
||||
|
||||
virtual G4Thread* CreateAndStartWorker(G4WorkerThread* workerThreadContext);
|
||||
// Called by the kernel to create a new thread/worker
|
||||
// and start work.
|
||||
// Usere should not re-implement this function (in derived class), except only
|
||||
// if he/she wants to verwrite the default threading model (see StartThread
|
||||
// function)
|
||||
|
||||
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine* aRNGEngine) const;
|
||||
// Called by worker threads to set the Random Number Generator Engine
|
||||
// The default implementation "clones" the engine from the master thread
|
||||
// User needs to re-implement this method if using a non-standard
|
||||
// RNG Engine (i.e. a different one w.r.t. the one provided in the CLHEP
|
||||
// version supported by G4.
|
||||
// Important: this method is called by all threads at the same time
|
||||
// if is user responsibilitiy to make it thread-safe
|
||||
|
||||
virtual void JoinWorker(G4Thread* aThread);
|
||||
// Called by the kernel when threads need to be terminated. Implements logic
|
||||
// of joining the aThread. Calling thread will wait for aThread to end. Usere
|
||||
// should not re-implement this function (in derived class), except only if
|
||||
// he/she wants to verwrite the default threading model (see StartThread
|
||||
// function)
|
||||
|
||||
virtual G4WorkerRunManager* CreateWorkerRunManager() const;
|
||||
// Called by StartThread function to create a run-manager implementing worker
|
||||
// behvior. User should re-implemtn this function in derived class to
|
||||
// instantiate his/her user-defined WorkerRunManager. By default this method
|
||||
// instantiates G4WorkerTaskRunManager object.
|
||||
};
|
||||
|
||||
#endif // G4UserTaskThreadInitialization_hh
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28st 2020)
|
||||
//
|
||||
// class description:
|
||||
//
|
||||
// This is a class for run control in GEANT4 for multi-threaded runs
|
||||
// It extends G4RunManager re-implementing multi-threaded behavior in
|
||||
// key methods. See documentation for G4RunManager. User should never
|
||||
// initialize instances of this class, that are usually handled by
|
||||
// G4MTRunManager. There exists one instance of this class for each
|
||||
// worker in a MT application.
|
||||
|
||||
#ifndef G4WorkerTaskRunManager_h
|
||||
#define G4WorkerTaskRunManager_h 1
|
||||
|
||||
#include "G4RNGHelper.hh"
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4WorkerRunManager.hh"
|
||||
|
||||
class G4WorkerThread;
|
||||
class G4WorkerTaskRunManagerKernel;
|
||||
|
||||
class G4WorkerTaskRunManager : public G4WorkerRunManager
|
||||
{
|
||||
public:
|
||||
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>;
|
||||
|
||||
public:
|
||||
typedef std::vector<G4String> G4StrVector;
|
||||
|
||||
public:
|
||||
static G4WorkerTaskRunManager* GetWorkerRunManager();
|
||||
static G4WorkerTaskRunManagerKernel* GetWorkerRunManagerKernel();
|
||||
G4WorkerTaskRunManager();
|
||||
|
||||
// Modified for worker behavior
|
||||
virtual void RunInitialization() override;
|
||||
virtual void DoEventLoop(G4int n_event, const char* macroFile = nullptr,
|
||||
G4int n_select = -1) override;
|
||||
virtual void ProcessOneEvent(G4int i_event) override;
|
||||
virtual G4Event* GenerateEvent(G4int i_event) override;
|
||||
virtual void RunTermination() override;
|
||||
virtual void TerminateEventLoop() override;
|
||||
virtual void DoWork() override;
|
||||
virtual void RestoreRndmEachEvent(G4bool flag) override
|
||||
{
|
||||
readStatusFromFile = flag;
|
||||
}
|
||||
|
||||
virtual void DoCleanup();
|
||||
virtual void ProcessUI();
|
||||
G4WorkerThread* GetWorkerThread() const { return workerContext; }
|
||||
G4StrVector GetCommandStack() const { return processedCommandStack; }
|
||||
|
||||
protected:
|
||||
virtual void StoreRNGStatus(const G4String& filenamePrefix) override;
|
||||
|
||||
private:
|
||||
void SetupDefaultRNGEngine();
|
||||
|
||||
private:
|
||||
G4StrVector processedCommandStack;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ProfilerConfig> workerRunProfiler;
|
||||
};
|
||||
|
||||
#endif // G4WorkerTaskRunManager_h
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Author: Jonathan Madsen (May 28st 2020)
|
||||
//
|
||||
// class description:
|
||||
//
|
||||
// This is a class for mandatory control of GEANT4 kernel.
|
||||
// This class implements Worker behavior in a MT application.
|
||||
//
|
||||
// This class is constructed by G4WorkerTaskRunManager. If a user uses
|
||||
// his/her own class instead of G4WorkerTaskRunManager, this class must be
|
||||
// instantiated by him/herself at the very beginning of the application and
|
||||
// must be deleted at the very end of the application. Also, following
|
||||
// methods must be invoked in the proper order.
|
||||
// DefineWorldVolume
|
||||
// InitializePhysics
|
||||
// RunInitialization
|
||||
// RunTermination
|
||||
//
|
||||
// User must provide his/her own classes derived from the following
|
||||
// abstract class and register it to the RunManagerKernel.
|
||||
// G4VUserPhysicsList - Particle types, Processes and Cuts
|
||||
//
|
||||
// G4WorkerTaskRunManagerKernel does not have any eveny loop. Handling of
|
||||
// events is managed by G4RunManager.
|
||||
//
|
||||
// This class re-implements only the method that require special treatment
|
||||
// to implement worker behavior
|
||||
//
|
||||
|
||||
#ifndef G4WorkerTaskRunManagerKernel_h
|
||||
#define G4WorkerTaskRunManagerKernel_h 1
|
||||
|
||||
#include "G4RunManagerKernel.hh"
|
||||
|
||||
class G4WorkerTaskRunManagerKernel : public G4RunManagerKernel
|
||||
{
|
||||
public:
|
||||
G4WorkerTaskRunManagerKernel();
|
||||
virtual ~G4WorkerTaskRunManagerKernel();
|
||||
|
||||
protected:
|
||||
// Overwrite default behavior
|
||||
void SetupShadowProcess() const;
|
||||
};
|
||||
|
||||
#endif // G4WorkerTaskRunManagerKernel_h
|
||||
Reference in New Issue
Block a user