Loading...
Searching...
No Matches
ts_scorers.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26/// \file parallel/ThreadsafeScorers/ts_scorers.cc
27/// \brief Main of the ThreadsafeScorers example
28//
29//
30//
31//
32/// ts_scorers example shows how to use global scorers. The benefit of using
33/// global scorers in memory-savings for problems with very large amounts
34/// of scoring volumes. Additionally, the global scorers are more precise
35/// w.r.t. the serial solution because of the lack of compounding
36/// round-off error from multiple threads
37///
38/// In this example, the global scorers are implemented as static member
39/// variables in TSRun because TSRun is thread-local. The G4atomic
40/// class is the core of the thread-safe scorers and can be uses
41//
42//
43//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46#include "G4Types.hh"
47
48#include "G4RunManagerFactory.hh"
49
50#include "G4Threading.hh"
51
52#include "Randomize.hh"
53
54// User Defined Classes
57#include "TSPhysicsList.hh"
58
59#include "G4TiMemory.hh"
60#include "G4UIExecutive.hh"
61#include "G4UImanager.hh"
62#include "G4VisExecutive.hh"
63#include "G4Track.hh"
64#include "G4Step.hh"
65
66// for std::system(const char*)
67#include <cstdlib>
68
69//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70
71void message(G4RunManager* runmanager)
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}
86
87//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88
89int main(int argc, char** argv)
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}
Definition of the TSActionInitialization class.
Definition of the TSDetectorConstruction class.
Definition of the TSPhysicsList class.
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.
int main()
Definition testCommon.cc:47
void message(G4RunManager *runmanager)
ts_scorers example shows how to use global scorers.
Definition ts_scorers.cc:71

Applications | User Support | Publications | Collaboration