Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:28:28

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 /// @file exMPI04.cc
0026 //
0027 /// @brief A MPI example code
0028 
0029 #include "G4MPIextraWorker.hh"
0030 #include "G4MPImanager.hh"
0031 #include "G4MPIsession.hh"
0032 
0033 #ifdef G4MULTITHREADED
0034 #  include "G4MTRunManager.hh"
0035 #else
0036 #  include "G4RunManager.hh"
0037 #endif
0038 
0039 #include "ActionInitialization.hh"
0040 #include "DetectorConstruction.hh"
0041 #include "FTFP_BERT.hh"
0042 #include "RunActionMaster.hh"
0043 
0044 #include "G4ScoringManager.hh"
0045 #include "G4UImanager.hh"
0046 #include "G4UserRunAction.hh"
0047 #include "G4VisExecutive.hh"
0048 #include "globals.hh"
0049 
0050 int main(int argc, char** argv)
0051 {
0052   // --------------------------------------------------------------------
0053   // Application options
0054   // --------------------------------------------------------------------
0055   bool useNtuple = true;
0056   bool mergeNtuple = true;
0057 
0058   // --------------------------------------------------------------------
0059   // MPI session
0060   // --------------------------------------------------------------------
0061   // At first, G4MPImanager/G4MPIsession should be created.
0062   G4int nofExtraWorkers = 0;
0063 #ifndef G4MULTITHREADED
0064   if (mergeNtuple) nofExtraWorkers = 1;
0065 #endif
0066   G4MPImanager* g4MPI = new G4MPImanager(argc, argv, nofExtraWorkers);
0067   g4MPI->SetVerbose(1);
0068 
0069   // MPI session (G4MPIsession) instead of G4UIterminal
0070   // Terminal availability depends on your MPI implementation.
0071   G4MPIsession* session = g4MPI->GetMPIsession();
0072 
0073   // LAM/MPI users can use G4tcsh.
0074   G4String prompt = "";
0075   prompt += "G4MPI";
0076   prompt += "(%s)[%/]:";
0077   session->SetPrompt(prompt);
0078 
0079   // --------------------------------------------------------------------
0080   // user application setting
0081   // --------------------------------------------------------------------
0082 #ifdef G4MULTITHREADED
0083   G4MTRunManager* runManager = new G4MTRunManager();
0084   runManager->SetNumberOfThreads(4);
0085 #else
0086   G4RunManager* runManager = new G4RunManager();
0087 #endif
0088   G4ScoringManager* scManager = G4ScoringManager::GetScoringManager();
0089   scManager->SetVerboseLevel(1);
0090   // setup your application
0091   runManager->SetUserInitialization(new DetectorConstruction);
0092   runManager->SetUserInitialization(new FTFP_BERT);
0093   runManager->SetUserInitialization(new ActionInitialization(useNtuple, mergeNtuple));
0094 
0095   runManager->Initialize();
0096 
0097   // extra worker (for collecting ntuple data)
0098   if (g4MPI->IsExtraWorker()) {
0099     G4cout << "Set extra worker" << G4endl;
0100     G4UserRunAction* runAction = const_cast<G4UserRunAction*>(runManager->GetUserRunAction());
0101     g4MPI->SetExtraWorker(new G4MPIextraWorker(runAction));
0102   }
0103 
0104   G4VisExecutive* visManager = new G4VisExecutive;
0105   visManager->Initialize();
0106   G4cout << G4endl;
0107 
0108   // --------------------------------------------------------------------
0109   // ready for go
0110   // MPIsession treats both interactive and batch modes.
0111   // Just start your session as below.
0112   // --------------------------------------------------------------------
0113   session->SessionStart();
0114 
0115   // --------------------------------------------------------------------
0116   // termination
0117   // --------------------------------------------------------------------
0118   delete visManager;
0119   delete g4MPI;
0120   delete runManager;
0121 
0122   return EXIT_SUCCESS;
0123 }