Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
extended/parallel/TBB/B2b/exampleB2b.cc File Reference

Main program of the B2b example. More...

#include "B2bDetectorConstruction.hh"
#include "B2ActionInitialization.hh"
#include "tbbUserWorkerInitialization.hh"
#include "tbbMasterRunManager.hh"
#include "G4Threading.hh"
#include "G4UImanager.hh"
#include "FTFP_BERT.hh"
#include "G4StepLimiterPhysics.hh"
#include "Randomize.hh"
#include <tbb/task_scheduler_init.h>
#include <tbb/task.h>

Go to the source code of this file.

Functions

G4ThreadFunReturnType startWork (G4ThreadFunArgType arg)
 
int main (int argc, char **argv)
 

Detailed Description

Main program of the B2b example.

Definition in file extended/parallel/TBB/B2b/exampleB2b.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 81 of file extended/parallel/TBB/B2b/exampleB2b.cc.

References G4UImanager::ApplyCommand(), G4Threading::G4GetNumberOfCores(), G4THREADCREATE, G4THREADJOIN, G4UImanager::GetUIpointer(), G4MTRunManager::Initialize(), G4VisManager::Initialize(), G4UIExecutive::IsGUI(), G4VModularPhysicsList::RegisterPhysics(), G4UIExecutive::SessionStart(), tbbMasterRunManager::SetNumberEventsPerTask(), tbbMasterRunManager::SetTaskList(), G4MTRunManager::SetUserInitialization(), and startWork().

82 {
83  // Choose the Random engine
84 
85  G4Random::setTheEngine(new CLHEP::RanecuEngine);
86 
87 
88  //=== TBB engine initialization
89  tbb::task_scheduler_init init( G4Threading::G4GetNumberOfCores() );
90  tbb::task_list tasks;
91 
92 
93  tbbMasterRunManager* runManager = new tbbMasterRunManager;
94 
95  //Set TBB specific data to run-manager, 1 event per tbb::task (e.g. Nevents == N tasks)
96  //Note that a /run/beamOn command will just create tasks and add them to tasks
97  runManager->SetNumberEventsPerTask(1); //Not needed since 1 is however default
98  runManager->SetTaskList(&tasks);
99  //Set user-initialization that specify threading model, in this case TBB.
100  //This overwrites default that uses pthreads
102 
103  //==== Geant4 specific stuff, from now up to END-G4 comment is copy from MT example
104  // Set mandatory initialization classes
105 
107 
108  G4VModularPhysicsList* physicsList = new FTFP_BERT;
109  physicsList->RegisterPhysics(new G4StepLimiterPhysics());
110  runManager->SetUserInitialization(physicsList);
111 
112  // Set user action classes
113 
115 
116  // Initialize G4 kernel
117 
118  runManager->Initialize();
119 
120 #ifdef G4VIS_USE
121  // Initialize visualization
122  G4VisManager* visManager = new G4VisExecutive;
123  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
124  // G4VisManager* visManager = new G4VisExecutive("Quiet");
125  visManager->Initialize();
126 #endif
127 
128  // Get the pointer to the User Interface manager
129  G4UImanager* UImanager = G4UImanager::GetUIpointer();
130 
131  if (argc!=1) // batch mode
132  {
133  G4String command = "/control/execute ";
134  G4String fileName = argv[1];
135  UImanager->ApplyCommand(command+fileName);
136  }
137  else
138  { // interactive mode : define UI session
139 #ifdef G4UI_USE
140  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
141 #ifdef G4VIS_USE
142  UImanager->ApplyCommand("/control/execute init_vis.mac");
143 #else
144  UImanager->ApplyCommand("/control/execute init.mac");
145 #endif
146  if (ui->IsGUI())
147  UImanager->ApplyCommand("/control/execute gui.mac");
148  ui->SessionStart();
149  delete ui;
150 #endif
151  }
152  //END-G4
153  G4Thread aThread;
154  G4THREADCREATE(&aThread,startWork,static_cast<G4ThreadFunArgType>(&tasks));
155 
156  //Wait for work to be finised
157  G4THREADJOIN(aThread);
158 
159 #ifdef G4VIS_USE
160  delete visManager;
161 #endif
162 
163  delete runManager;
164 
165  return 0;
166 }
#define G4THREADJOIN(worker)
Definition: G4Threading.hh:164
void RegisterPhysics(G4VPhysicsConstructor *)
void SetNumberEventsPerTask(G4int nt)
G4int G4Thread
Definition: G4Threading.hh:157
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
#define G4THREADCREATE(worker, func, arg)
Definition: G4Threading.hh:163
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:102
virtual void SetUserInitialization(G4VUserPhysicsList *userPL)
G4ThreadFunReturnType startWork(G4ThreadFunArgType arg)
void Initialize()
virtual void Initialize()
TFTFP_BERT< G4VModularPhysicsList > FTFP_BERT
Definition: FTFP_BERT.hh:63
void SetTaskList(tbb::task_list *tl)
G4bool IsGUI() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419

Definition at line 65 of file extended/parallel/TBB/B2b/exampleB2b.cc.

Referenced by main().

66 {
67  tbb::task_list* tasks = static_cast<tbb::task_list*>(arg);
68  //We assume at least one /run/beamOn was executed, thus the tasklist is now filled,
69  //lets start TBB
70  try {
71  std::cout<<"Now spawn work and waiting"<<std::endl;
72  tbb::task::spawn_root_and_wait( *tasks );
73  } catch(std::exception& e) {
74  std::cerr<<"Error occurred. Error test is:\""<<e.what()<<"\""<<std::endl;
75  }
76  return static_cast<G4ThreadFunReturnType>(0);
77 }
void * G4ThreadFunReturnType
Definition: G4Threading.hh:165