LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
exMPI04.cc File Reference
#include "G4MPImanager.hh"
#include "G4MPIsession.hh"
#include "G4MPIextraWorker.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UserRunAction.hh"
#include "G4VisExecutive.hh"
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "RunActionMaster.hh"
#include "FTFP_BERT.hh"
#include "G4ScoringManager.hh"
#include "globals.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 A MPI example code. More...
 

Function Documentation

int main ( int  argc,
char **  argv 
)

A MPI example code.

Definition at line 50 of file exMPI04.cc.

References Initialize(), and session.

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
88 G4ScoringManager * scManager = G4ScoringManager::GetScoringManager();
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 }
static G4UIterminal * session
void Initialize()
Definition: errprop.cc:100