Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:28

0001 // PythiaParallel.h is a part of the PYTHIA event generator.
0002 // Copyright (C) 2024 Marius Utheim, Torbjorn Sjostrand.
0003 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
0004 // Please respect the MCnet Guidelines, see GUIDELINES for details.
0005 
0006 #ifndef PYTHIA_PARALLEL_H
0007 #define PYTHIA_PARALLEL_H
0008 
0009 #include "Pythia8/Pythia.h"
0010 #include "Pythia8/PythiaStdlib.h"
0011 
0012 namespace Pythia8 {
0013 
0014 //==========================================================================
0015 
0016 // Class for doing Pythia runs in parallel.
0017 
0018 class PythiaParallel {
0019 
0020 public:
0021 
0022   // Constructor.
0023   PythiaParallel(string xmlDir = "../share/Pythia8/xmldoc",
0024     bool printBanner = true);
0025 
0026   // Read in one update for a setting or particle data from a single line.
0027   bool readString(string setting, bool warn = true) {
0028     return pythiaHelper.readString(setting, warn); }
0029 
0030   // Read in updates for settings or particle data from user-defined file.
0031   bool readFile(string fileName, bool warn = true,
0032     int subrun = SUBRUNDEFAULT);
0033   bool readFile(string fileName, int subrun) {
0034     return readFile(fileName, true, subrun); }
0035   bool readFile(istream& is = cin, bool warn = true,
0036     int subrun = SUBRUNDEFAULT);
0037   bool readFile(istream& is, int subrun) {
0038     return readFile(is, true, subrun);}
0039 
0040   // Initialize all Pythia objects.
0041   bool init();
0042   bool init(function<bool(Pythia*)> additionalSetup);
0043 
0044   // Perform the specified action for each Pythia instance.
0045   void foreach(function<void(Pythia*)> action);
0046 
0047   // Perform the specified action for each instance in parallel.
0048   void foreachAsync(function<void(Pythia*)> action);
0049 
0050   // Write final statistics, combining errors from each Pythia instance.
0051   void stat() { pythiaHelper.stat(); }
0052 
0053   // Generate events in parallel.
0054   vector<long> run(long nEvents, function<void(Pythia*)> callback);
0055   vector<long> run(function<void(Pythia*)> callback) {
0056     return run(settings.mode("Main:numberOfEvents"), callback); }
0057 
0058   // Pythia object used for loading data.
0059   Pythia pythiaHelper;
0060 
0061   // Weighted average of the generated cross section for each Pythia instance.
0062   double sigmaGen() const { return sigmaGenSave; }
0063 
0064   // Sum of weights from all Pythia instances.
0065   double weightSum() const { return weightSumSave; }
0066 
0067   // The settings that will be used to initialize Pythia instances.
0068   Settings& settings;
0069 
0070   // The particle database that will be used to initialize Pythia instances.
0071   ParticleData& particleData;
0072 
0073 private:
0074 
0075   // Object used for logging.
0076   Logger& logger;
0077 
0078   // Flag if initialized.
0079   bool isInit = false;
0080 
0081   // Sum of weights and weighted cross section.
0082   double weightSumSave, sigmaGenSave;
0083 
0084   // Configuration flags.
0085   int numThreads;
0086   bool processAsync;
0087   bool balanceLoad;
0088   bool doNext;
0089 
0090   // Internal Pythia objects.
0091   vector<unique_ptr<Pythia> > pythiaObjects;
0092 
0093 };
0094 
0095 //==========================================================================
0096 
0097 } // end namespace Pythia8
0098 
0099 #endif // Pythia8_PythiaParallel_H