Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleB2b.cc File Reference

Main program of the B2b example. More...

#include "B2bDetectorConstruction.hh"
#include "B2ActionInitialization.hh"
#include "tbbUserWorkerInitialization.hh"
#include "SimpleTbbMasterRunManager.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>
Include dependency graph for exampleB2b.cc:

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 exampleB2b.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 81 of file exampleB2b.cc.

82 {
83  // Choose the Random engine
84 
85  G4Random::setTheEngine(new CLHEP::RanecuEngine);
86 
87  unsigned int numCoresAvailable= G4Threading::G4GetNumberOfCores();
88  unsigned int numberOfCoresToUse= (numCoresAvailable > 1 ) ? 2 : 1 ;
89  //=== TBB engine initialization
90  tbb::task_scheduler_init init( numberOfCoresToUse );
91  tbb::task_list tasks;
92 
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  // Get the pointer to the User Interface manager
121  G4UImanager* UImanager = G4UImanager::GetUIpointer();
122 
123  if (argc!=1) // batch mode
124  {
125  G4String command = "/control/execute ";
126  G4String fileName = argv[1];
127  UImanager->ApplyCommand(command+fileName);
128  }
129  else
130  { // interactive mode : define UI session
131 #if 1
132  G4int nEvents= 50;
133  runManager->BeamOn(nEvents);
134 #else
135  #ifdef G4UI_USE
136  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
137  UImanager->ApplyCommand("/control/execute init.mac");
138  if (ui->IsGUI())
139  UImanager->ApplyCommand("/control/execute gui.mac");
140  ui->SessionStart();
141  delete ui;
142  #endif
143 #endif
144  }
145  //END-G4
146  G4Thread aThread;
147  G4THREADCREATE(&aThread,startWork,static_cast<G4ThreadFunArgType>(&tasks));
148 
149  //Wait for work to be finised
150  G4THREADJOIN(aThread);
151 
152  delete runManager;
153 
154  return 0;
155 }
#define G4THREADJOIN(worker)
Definition: G4Threading.hh:182
void RegisterPhysics(G4VPhysicsConstructor *)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
int G4int
Definition: G4Types.hh:78
G4int G4Thread
Definition: G4Threading.hh:174
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
void SetTaskList(tbb::task_list *tl)
#define G4THREADCREATE(worker, func, arg)
Definition: G4Threading.hh:181
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:143
virtual void SetUserInitialization(G4VUserPhysicsList *userPL)
G4ThreadFunReturnType startWork(G4ThreadFunArgType arg)
Definition: exampleB2b.cc:65
virtual void Initialize()
TFTFP_BERT< G4VModularPhysicsList > FTFP_BERT
Definition: FTFP_BERT.hh:63
G4bool IsGUI() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447

Here is the call graph for this function:

Definition at line 65 of file exampleB2b.cc.

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 calling 'tbb::task::spawn_work_and_wait' "<<std::endl;
72  tbb::task::spawn_root_and_wait( *tasks );
73  } catch(std::exception& e) {
74  std::cerr<<"Error occurred. Error info is:\""<<e.what()<<"\""<<std::endl;
75  }
76  return static_cast<G4ThreadFunReturnType>(0);
77 }
void * G4ThreadFunReturnType
Definition: G4Threading.hh:184

Here is the caller graph for this function: