Import Geant4 10.7.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2020-06-26 10:23:25 +02:00
parent c02c370437
commit 67ba86d073
1871 changed files with 174422 additions and 131884 deletions
@@ -0,0 +1,100 @@
//
// ********************************************************************
// * 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,
MT = 1,
Tasking = 2,
TBB = 3,
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();
};
#endif // G4TaskRunManagerCreator_h
+53
View File
@@ -0,0 +1,53 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file wraps a TBB task_group into a G4TaskGroup
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28st 2020)
// ---------------------------------------------------------------
#pragma once
#if defined(GEANT4_USE_TBB)
# include "PTL/TBBTaskGroup.hh"
#else
# include "PTL/TaskGroup.hh"
#endif
#if defined(GEANT4_USE_TBB)
template <typename Tp, typename Arg = Tp>
using G4TBBTaskGroup = PTL::TBBTaskGroup<Tp, Arg>;
#else
template <typename Tp, typename Arg = Tp>
using G4TBBTaskGroup = PTL::TaskGroup<Tp, Arg>;
#endif
+44
View File
@@ -0,0 +1,44 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file defines the task types for G4TaskManager and G4ThreadPool
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/Task.hh"
template <typename _Ret, typename _Arg, typename... _Args>
using G4Task = PTL::Task<_Ret, _Arg, _Args...>;
+45
View File
@@ -0,0 +1,45 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file creates the a class for handling a group of tasks that
// can be independently joined
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/TaskGroup.hh"
template <typename _Tp, typename _Arg = _Tp>
using G4TaskGroup = PTL::TaskGroup<_Tp, _Arg>;
+44
View File
@@ -0,0 +1,44 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file creates a class for handling the wrapping of functions
// into task objects and submitting to thread pool
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/TaskManager.hh"
using G4TaskManager = PTL::TaskManager;
+247
View File
@@ -0,0 +1,247 @@
//
// ********************************************************************
// * 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 "taskdefs.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 "PTL/TaskRunManager.hh"
#include <list>
#include <map>
class G4TaskRunManagerKernel;
class G4ScoringManager;
class G4UserTaskInitialization;
class G4UserTaskThreadInitialization;
class G4WorkerTaskRunManager;
//============================================================================//
class G4TaskRunManager
: public G4MTRunManager
, public PTL::TaskRunManager
{
public:
using InitializeSeedsCallback = std::function<G4bool(G4int, G4int&, G4int&)>;
using WorkerRunSet = std::set<G4WorkerTaskRunManager**>;
using RunTaskGroup = G4TaskGroup<void>;
using RunTaskGroupTBB = G4TBBTaskGroup<WorkerRunSet, G4WorkerTaskRunManager**>;
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
private:
// grainsize
G4int eventGrainsize;
G4int numberOfEventsPerTask;
G4int numberOfTasks;
// List of workers run managers
// List of all workers run managers
CLHEP::HepRandomEngine* masterRNGEngine;
// Pointer to the mastet thread random engine
protected:
virtual void TerminateWorkers() override;
private:
// Handling of master thread scoring worlds, access to it is needed by workers
G4TASK_DLL static G4ScoringManager* masterScM;
G4TASK_DLL static masterWorlds_t masterWorlds;
// Singleton implementing master thread behavior
static G4TaskRunManager* fMasterRM;
G4TaskRunManagerKernel* MTkernel;
public: // with description
static G4TaskRunManager* GetMasterRunManager();
// Returns the singleton instance of the run manager common to all threads
// implementing the master behavior
static G4RunManagerKernel* GetMasterRunManagerKernel();
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;
}
virtual void NewActionRequest(WorkerActionRequest) override {}
protected:
// WorkerActionRequest nextActionRequest;
// virtual void NewActionRequest( WorkerActionRequest newRequest );
virtual void AddEventTask(G4int, G4int);
public:
inline void SetInitializeSeedsCallback(InitializeSeedsCallback f)
{
initSeedsCallback = f;
}
public:
virtual void AbortRun(G4bool softAbort = false) override;
virtual void AbortEvent() override;
protected:
// Barriers: synch points between master and workers
RunTaskGroup* workTaskGroup = nullptr;
RunTaskGroupTBB* workTaskGroupTBB = 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,94 @@
//
// ********************************************************************
// * 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 "G4RunManagerKernel.hh"
#include "G4TaskRunManager.hh"
#include "G4Threading.hh"
#include "taskdefs.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 G4WorkerTaskRunManager** ExecuteWorkerTask(G4int nevts);
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;
G4TASK_DLL static std::vector<G4String> initCmdStack;
};
#endif // G4TaskRunManagerKernel_hh
@@ -0,0 +1,129 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ---------------------------------------------------------------
// GEANT4 template class header
// Class Description:
// This class delegates which singletons a task references
// ---------------------------------------------------------------
// Author: Jonathan Madsen
// ---------------------------------------------------------------
#include "G4AutoLock.hh"
#include "G4Threading.hh"
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>
namespace G4Traits
{
template <typename T>
struct TaskSingletonKey
{
using type = G4int;
using compare_type = std::less<type>;
};
}
// ------------------------------------------------------------------------------------ //
/// \class G4TaskSingletonEvaluator
/// \brief This structure must be specialized and use overloads to the constructor
///
template <typename T>
struct G4TaskSingletonEvaluator;
// ------------------------------------------------------------------------------------ //
template <typename T>
class G4TaskSingletonDelegator;
// ------------------------------------------------------------------------------------ //
template <typename T>
class G4TaskSingletonData
{
using key_type = typename G4Traits::TaskSingletonKey<T>::type;
using compare_type = typename G4Traits::TaskSingletonKey<T>::compare_type;
friend struct G4TaskSingletonEvaluator<T>;
friend class G4TaskSingletonDelegator<T>;
using this_type = G4TaskSingletonData<T>;
private:
static std::unique_ptr<this_type>& GetInstance()
{
static auto _instance = std::unique_ptr<this_type>(new this_type);
return _instance;
}
private:
std::map<key_type, T*, compare_type> m_data;
};
// ------------------------------------------------------------------------------------ //
template <typename T>
struct G4TaskSingletonEvaluator
{
using key_type = typename G4Traits::TaskSingletonKey<T>::type;
using data_type = G4TaskSingletonData<T>;
template <typename... Args>
G4TaskSingletonEvaluator(key_type&, Args&&...)
{
throw std::runtime_error("Not specialized!");
}
};
// ------------------------------------------------------------------------------------ //
template <typename T>
class G4TaskSingletonDelegator
{
public:
using pointer = T*;
using evaluator_type = G4TaskSingletonEvaluator<T>;
using data_type = G4TaskSingletonData<T>;
using key_type = typename G4Traits::TaskSingletonKey<T>;
template <typename... Args>
static void Configure(Args&&... args)
{
auto& _data = data_type::GetInstance();
evaluator_type _eval(std::forward<Args>(args)...);
auto _ptr = _data->m_data.at(_eval.index);
_eval.modifier(_ptr);
T::SetInstance(_data->m_data.at(_key));
}
};
// ------------------------------------------------------------------------------------ //
+37
View File
@@ -0,0 +1,37 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ---------------------------------------------------------------
// GEANT4 class header
// Class Description:
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/ThreadData.hh"
using G4ThreadData = PTL::ThreadData;
+44
View File
@@ -0,0 +1,44 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file creates a class for an efficient thread-pool that
// accepts work in the form of tasks.
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/ThreadPool.hh"
using G4ThreadPool = PTL::ThreadPool;
@@ -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
+37
View File
@@ -0,0 +1,37 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ---------------------------------------------------------------
// GEANT4 class header
// Class Description:
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28st 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/UserTaskQueue.hh"
using G4UserTaskQueue = PTL::UserTaskQueue;
@@ -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
+44
View File
@@ -0,0 +1,44 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file creates an abstract base class for the thread-pool tasking
// system
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/VTask.hh"
using G4VTask = PTL::VTask;
+44
View File
@@ -0,0 +1,44 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
// ---------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// This file creates an abstract base class for the grouping the thread-pool
// tasking system into independently joinable units
//
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28th 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/VTaskGroup.hh"
using G4VTaskGroup = PTL::VTaskGroup;
@@ -0,0 +1,39 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ---------------------------------------------------------------
// GEANT4 class header
// Class Description:
// Abstract base class for creating a task queue used by
// G4ThreadPool
// ---------------------------------------------------------------
// Author: Jonathan Madsen (May 28st 2020)
// ---------------------------------------------------------------
#pragma once
#include "PTL/VUserTaskQueue.hh"
using G4VUserTaskQueue = PTL::VUserTaskQueue;
@@ -0,0 +1,91 @@
//
// ********************************************************************
// * 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:
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 DoBeamOn(G4int evts);
virtual void DoWork(G4int nevts);
virtual void InitializeForNewRun();
void SetConfirmBeamOn(G4bool val) { fConfirmBeamOn = val; }
G4WorkerThread* GetWorkerThread() const { return workerContext; }
virtual void ProcessUI();
G4StrVector GetCommandStack() const { return processedCommandStack; }
protected:
virtual void StoreRNGStatus(const G4String& filenamePrefix) override;
private:
void SetupDefaultRNGEngine();
private:
G4bool fConfirmBeamOn;
G4StrVector processedCommandStack;
};
#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
+50
View File
@@ -0,0 +1,50 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
// Defines for Windows DLLs import/export
//
#ifndef TASKDEFS_HH
#define TASKDEFS_HH
#include "G4Types.hh"
#ifdef WIN32
//
// Unique identifier for global module
//
# if defined G4TASKING_ALLOC_EXPORT
# define G4TASK_DLL G4DLLEXPORT
# else
# define G4TASK_DLL G4DLLIMPORT
# endif
#else
# define G4TASK_DLL
#endif
#endif /* G4TASKDEFS_HH */