31 #include "B2bDetectorConstruction.hh" 32 #include "B2ActionInitialization.hh" 35 #include "tbbUserWorkerInitialization.hh" 36 #include "SimpleTbbMasterRunManager.hh" 37 #include "G4Threading.hh" 39 #include "G4UImanager.hh" 40 #include "FTFP_BERT.hh" 41 #include "G4StepLimiterPhysics.hh" 43 #include "Randomize.hh" 46 #include "G4VisExecutive.hh" 50 #include "G4UIExecutive.hh" 54 #include <tbb/task_scheduler_init.h> 65 G4ThreadFunReturnType
startWork(G4ThreadFunArgType arg)
67 tbb::task_list* tasks =
static_cast<tbb::task_list*
>(arg);
71 std::cout<<
"Now calling 'tbb::task::spawn_work_and_wait' "<<std::endl;
72 tbb::task::spawn_root_and_wait( *tasks );
74 std::cerr<<
"Error occurred. Error info is:\""<<e.what()<<
"\""<<std::endl;
76 return static_cast<G4ThreadFunReturnType
>(0);
81 int main(
int argc,
char** argv)
85 G4Random::setTheEngine(
new CLHEP::RanecuEngine);
87 unsigned int numCoresAvailable= G4Threading::G4GetNumberOfCores();
88 unsigned int numberOfCoresToUse= (numCoresAvailable > 1 ) ? 2 : 1 ;
90 tbb::task_scheduler_init init( numberOfCoresToUse );
93 SimpleTbbMasterRunManager* runManager =
new SimpleTbbMasterRunManager;
97 runManager->SetNumberEventsPerTask(1);
98 runManager->SetTaskList(&tasks);
101 runManager->SetUserInitialization(
new tbbUserWorkerInitialization );
106 runManager->SetUserInitialization(
new B2bDetectorConstruction());
108 G4VModularPhysicsList* physicsList =
new FTFP_BERT;
109 physicsList->RegisterPhysics(
new G4StepLimiterPhysics());
110 runManager->SetUserInitialization(physicsList);
114 runManager->SetUserInitialization(
new B2ActionInitialization());
118 runManager->Initialize();
121 G4UImanager* UImanager = G4UImanager::GetUIpointer();
125 G4String command =
"/control/execute ";
127 UImanager->ApplyCommand(command+fileName);
133 runManager->BeamOn(nEvents);
136 G4UIExecutive* ui =
new G4UIExecutive(argc, argv);
137 UImanager->ApplyCommand(
"/control/execute init.mac");
139 UImanager->ApplyCommand(
"/control/execute gui.mac");
147 G4THREADCREATE(&aThread,
startWork,static_cast<G4ThreadFunArgType>(&tasks));
150 G4THREADJOIN(aThread);
int main(int argc, char **argv)
G4ThreadFunReturnType startWork(G4ThreadFunArgType arg)
cet::coded_exception< error, detail::translate > exception