Loading...
Searching...
No Matches
Functions
ts_scorers.cc File Reference

Main of the ThreadsafeScorers example. More...

#include "G4Types.hh"
#include "G4RunManagerFactory.hh"
#include "G4Threading.hh"
#include "Randomize.hh"
#include "TSActionInitialization.hh"
#include "TSDetectorConstruction.hh"
#include "TSPhysicsList.hh"
#include "G4TiMemory.hh"
#include "G4UIExecutive.hh"
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include <cstdlib>

Go to the source code of this file.

Functions

void message (G4RunManager *runmanager)
 ts_scorers example shows how to use global scorers.
 
int main (int argc, char **argv)
 

Detailed Description

Main of the ThreadsafeScorers example.

Definition in file ts_scorers.cc.

Function Documentation

◆ message()

void message ( G4RunManager runmanager)

ts_scorers example shows how to use global scorers.

The benefit of using global scorers in memory-savings for problems with very large amounts of scoring volumes. Additionally, the global scorers are more precise w.r.t. the serial solution because of the lack of compounding round-off error from multiple threads

In this example, the global scorers are implemented as static member variables in TSRun because TSRun is thread-local. The G4atomic class is the core of the thread-safe scorers and can be uses

Definition at line 71 of file ts_scorers.cc.

72{
73 G4MTRunManager* man = dynamic_cast<G4MTRunManager*>(runmanager);
74 if(man)
75 {
76 man->SetNumberOfThreads(G4Threading::G4GetNumberOfCores());
77 G4cout << "\n\n\t--> Running in multithreaded mode with "
78 << man->GetNumberOfThreads() << " threads\n\n"
79 << G4endl;
80 }
81 else
82 {
83 G4cout << "\n\n\t--> Running in serial mode\n\n" << G4endl;
84 }
85}

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 89 of file ts_scorers.cc.

90{
91 // initialize timemory
92 G4Profiler::Configure(argc, argv);
93
94 G4String macro;
95 if(argc > 1)
96 macro = argv[argc - 1];
97
98 // Detect interactive mode (if no arguments) and define UI session
99 //
100 G4UIExecutive* ui = 0;
101 if(macro.empty())
102 ui = new G4UIExecutive(argc, argv);
103
104 // Set the random seed
105 CLHEP::HepRandom::setTheSeed(1245214UL);
106
107#if defined(GEANT4_USE_TIMEMORY)
108 // The following exists for:
109 // - G4ProfileType::Run
110 // - G4ProfileType::Event
111 // - G4ProfileType::Track
112 // - G4ProfileType::Step
113 // - G4ProfileType::User
114 //
115 using TrackProfilerConfig = G4ProfilerConfig<G4ProfileType::Track>;
116 using TrackTool = typename TrackProfilerConfig::type;
117
118 TrackProfilerConfig::GetQueryFunctor() = [](const G4Track* _track) {
119 // only profile if _track != nullptr and dynamic-profiler != nullptr
120 // and /profiler/track/enable is true
121 //
122 return G4Profiler::GetEnabled(G4ProfileType::Track) && _track &&
123 _track->GetDynamicParticle();
124 };
125
126 TrackProfilerConfig::GetLabelFunctor() = [](const G4Track* _track) {
127 // create a label for the profiling entry. This can be customized
128 // to include and information necessary in the returning string
129 auto pdef = _track->GetDynamicParticle()->GetParticleDefinition();
130 static std::string _prefix = "G4Track/";
131 return _prefix + pdef->GetParticleName();
132 };
133
134 // env option to display track profiles as a hierarchy
135 bool track_tree = tim::get_env<bool>("G4PROFILER_TRACK_TREE", true);
136 // env option to enable timeline entries (every entry is unique, HUGE amount
137 // of data!)
138 bool track_time = tim::get_env<bool>("G4PROFILER_TRACK_TIMELINE", false);
139 // default scope is tree
140 auto _scope = tim::scope::config{};
141 if(track_tree == false)
142 _scope += tim::scope::flat{};
143 if(track_time == true)
144 _scope += tim::scope::timeline{};
145 TrackProfilerConfig::GetToolFunctor() = [=](const std::string& _label) {
146 // Configure the profiling tool for a given label. By default,
147 // G4Track and G4Step tools are "flat profiles" but this can be disabled
148 // to include tree
149 return new TrackTool(_label, _scope);
150 };
151#endif
152
153 G4RunManager* runmanager =
154 G4RunManagerFactory::CreateRunManager(G4RunManagerType::Tasking);
155
156 message(runmanager);
157
158 runmanager->SetUserInitialization(new TSDetectorConstruction);
159
160 runmanager->SetUserInitialization(new TSPhysicsList);
161
162 runmanager->SetUserInitialization(new TSActionInitialization);
163
164 runmanager->Initialize();
165
166 // Initialize visualization
167 //
168 G4VisManager* visManager = new G4VisExecutive;
169 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
170 // G4VisManager* visManager = new G4VisExecutive("Quiet");
171 visManager->Initialize();
172
173 // Get the pointer to the User Interface manager
174 G4UImanager* UImanager = G4UImanager::GetUIpointer();
175
176 // Process macro or start UI session
177 //
178 if(!ui)
179 {
180 // batch mode
181 G4String command = "/control/execute ";
182 UImanager->ApplyCommand(command + macro);
183 }
184 else
185 {
186 ui->SessionStart();
187 }
188
189 // Job termination
190 // Free the store: user actions, physics_list and detector_description are
191 // owned and deleted by the run manager, so they should not be deleted
192 // in the main() program !
193 delete visManager;
194 delete runmanager;
195
196 return 0;
197}
Standard ActionInitialization class creating a RunAction instance for the master thread and RunAction...
This is a very, very extensive physics list and step-limiters are applied to many particles.
void message(G4RunManager *runmanager)
ts_scorers example shows how to use global scorers.
Definition ts_scorers.cc:71

Applications | User Support | Publications | Collaboration