PYTHIA  8.311
PythiaParallel.h
1 // PythiaParallel.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2024 Marius Utheim, Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 #ifndef PYTHIA_PARALLEL_H
7 #define PYTHIA_PARALLEL_H
8 
9 #include "Pythia8/Pythia.h"
10 #include "Pythia8/PythiaStdlib.h"
11 
12 namespace Pythia8 {
13 
14 //==========================================================================
15 
16 // Class for doing Pythia runs in parallel.
17 
19 
20 public:
21 
22  // Constructor.
23  PythiaParallel(string xmlDir = "../share/Pythia8/xmldoc",
24  bool printBanner = true);
25 
26  // Read in one update for a setting or particle data from a single line.
27  bool readString(string setting, bool warn = true) {
28  return pythiaHelper.readString(setting, warn); }
29 
30  // Read in updates for settings or particle data from user-defined file.
31  bool readFile(string fileName, bool warn = true,
32  int subrun = SUBRUNDEFAULT);
33  bool readFile(string fileName, int subrun) {
34  return readFile(fileName, true, subrun); }
35  bool readFile(istream& is = cin, bool warn = true,
36  int subrun = SUBRUNDEFAULT);
37  bool readFile(istream& is, int subrun) {
38  return readFile(is, true, subrun);}
39 
40  // Initialize all Pythia objects.
41  bool init();
42  bool init(function<bool(Pythia*)> additionalSetup);
43 
44  // Perform the specified action for each Pythia instance.
45  void foreach(function<void(Pythia*)> action);
46 
47  // Perform the specified action for each instance in parallel.
48  void foreachAsync(function<void(Pythia*)> action);
49 
50  // Write final statistics, combining errors from each Pythia instance.
51  void stat() { pythiaHelper.stat(); }
52 
53  // Generate events in parallel.
54  vector<long> run(long nEvents, function<void(Pythia*)> callback);
55  vector<long> run(function<void(Pythia*)> callback) {
56  return run(settings.mode("Main:numberOfEvents"), callback); }
57 
58  // Pythia object used for loading data.
60 
61  // Weighted average of the generated cross section for each Pythia instance.
62  double sigmaGen() const { return sigmaGenSave; }
63 
64  // Sum of weights from all Pythia instances.
65  double weightSum() const { return weightSumSave; }
66 
67  // The settings that will be used to initialize Pythia instances.
69 
70  // The particle database that will be used to initialize Pythia instances.
72 
73 private:
74 
75  // Object used for logging.
76  Logger& logger;
77 
78  // Flag if initialized.
79  bool isInit = false;
80 
81  // Sum of weights and weighted cross section.
82  double weightSumSave, sigmaGenSave;
83 
84  // Configuration flags.
85  int numThreads;
86  bool processAsync;
87  bool balanceLoad;
88  bool doNext;
89 
90  // Internal Pythia objects.
91  vector<unique_ptr<Pythia> > pythiaObjects;
92 
93 };
94 
95 //==========================================================================
96 
97 } // end namespace Pythia8
98 
99 #endif // Pythia8_PythiaParallel_H
Pythia pythiaHelper
Pythia object used for loading data.
Definition: PythiaParallel.h:59
Class for doing Pythia runs in parallel.
Definition: PythiaParallel.h:18
void stat()
Write final statistics, combining errors from each Pythia instance.
Definition: PythiaParallel.h:51
PythiaParallel(string xmlDir="../share/Pythia8/xmldoc", bool printBanner=true)
Constructor.
Definition: PythiaParallel.cc:21
Definition: Logger.h:23
double weightSum() const
Sum of weights from all Pythia instances.
Definition: PythiaParallel.h:65
Settings & settings
The settings that will be used to initialize Pythia instances.
Definition: PythiaParallel.h:68
vector< long > run(long nEvents, function< void(Pythia *)> callback)
Generate events in parallel.
bool init()
Initialize all Pythia objects.
Definition: PythiaParallel.cc:52
void stat()
Main routine to provide final statistics on generation.
Definition: Pythia.cc:1726
void foreachAsync(function< void(Pythia *)> action)
Perform the specified action for each instance in parallel.
Definition: PythiaParallel.cc:254
double sigmaGen() const
Weighted average of the generated cross section for each Pythia instance.
Definition: PythiaParallel.h:62
bool readString(string setting, bool warn=true)
Read in one update for a setting or particle data from a single line.
Definition: PythiaParallel.h:27
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
The Pythia class contains the top-level routines to generate an event.
Definition: Pythia.h:71
bool readFile(string fileName, bool warn=true, int subrun=SUBRUNDEFAULT)
Read in updates for settings or particle data from user-defined file.
Definition: PythiaParallel.cc:30
bool readString(string, bool warn=true, int subrun=SUBRUNDEFAULT)
Read in one update for a setting or particle data from a single line.
Definition: Pythia.cc:365
This class holds a map of all ParticleDataEntries.
Definition: ParticleData.h:422
ParticleData & particleData
The particle database that will be used to initialize Pythia instances.
Definition: PythiaParallel.h:71
Definition: Settings.h:195