ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exMPI04.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file exMPI04.cc
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 // ********************************************************************
26 //
28 
29 #include "G4MPImanager.hh"
30 #include "G4MPIsession.hh"
31 #include "G4MPIextraWorker.hh"
32 
33 #ifdef G4MULTITHREADED
34 #include "G4MTRunManager.hh"
35 #else
36 #include "G4RunManager.hh"
37 #endif
38 
39 #include "G4UImanager.hh"
40 #include "G4UserRunAction.hh"
41 #include "G4VisExecutive.hh"
42 
43 #include "ActionInitialization.hh"
44 #include "DetectorConstruction.hh"
45 #include "RunActionMaster.hh"
46 #include "FTFP_BERT.hh"
47 #include "G4ScoringManager.hh"
48 #include "globals.hh"
49 
50 int main(int argc, char** argv)
51 {
52  // --------------------------------------------------------------------
53  // Application options
54  // --------------------------------------------------------------------
55  bool useNtuple = true;
56  bool mergeNtuple = true;
57 
58  // --------------------------------------------------------------------
59  // MPI session
60  // --------------------------------------------------------------------
61  // At first, G4MPImanager/G4MPIsession should be created.
62  G4int nofExtraWorkers = 0;
63 #ifndef G4MULTITHREADED
64  if ( mergeNtuple ) nofExtraWorkers = 1;
65 #endif
66  G4MPImanager* g4MPI = new G4MPImanager(argc, argv, nofExtraWorkers);
67  g4MPI->SetVerbose(1);
68 
69  // MPI session (G4MPIsession) instead of G4UIterminal
70  // Terminal availability depends on your MPI implementation.
71  G4MPIsession* session = g4MPI-> GetMPIsession();
72 
73  // LAM/MPI users can use G4tcsh.
74  G4String prompt = "";
75  prompt += "G4MPI";
76  prompt += "(%s)[%/]:";
77  session-> SetPrompt(prompt);
78 
79  // --------------------------------------------------------------------
80  // user application setting
81  // --------------------------------------------------------------------
82 #ifdef G4MULTITHREADED
83  G4MTRunManager* runManager = new G4MTRunManager();
84  runManager-> SetNumberOfThreads(4);
85 #else
86  G4RunManager* runManager = new G4RunManager();
87 #endif
89  scManager->SetVerboseLevel(1);
90  // setup your application
91  runManager-> SetUserInitialization(new DetectorConstruction);
92  runManager-> SetUserInitialization(new FTFP_BERT);
93  runManager-> SetUserInitialization(
94  new ActionInitialization(useNtuple, mergeNtuple));
95 
96  runManager-> Initialize();
97 
98  // extra worker (for collecting ntuple data)
99  if ( g4MPI->IsExtraWorker() ) {
100  G4cout << "Set extra worker" << G4endl;
101  G4UserRunAction* runAction
102  = const_cast<G4UserRunAction*>(runManager->GetUserRunAction());
103  g4MPI->SetExtraWorker(new G4MPIextraWorker(runAction));
104  }
105 
106  G4VisExecutive* visManager = new G4VisExecutive;
107  visManager-> Initialize();
108  G4cout << G4endl;
109 
110  // --------------------------------------------------------------------
111  // ready for go
112  // MPIsession treats both interactive and batch modes.
113  // Just start your session as below.
114  // --------------------------------------------------------------------
115  session-> SessionStart();
116 
117  // --------------------------------------------------------------------
118  // termination
119  // --------------------------------------------------------------------
120  delete visManager;
121  delete g4MPI;
122  delete runManager;
123 
124  return EXIT_SUCCESS;
125 }