Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-07 08:47:25

0001 // Copyright 2022-2026, Jefferson Science Associates, LLC.
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 
0004 
0005 #define CATCH_CONFIG_MAIN
0006 #include <catch.hpp>
0007 
0008 #include <JANA/JApplication.h>
0009 #include <JANA/JFactoryGenerator.h>
0010 #include <JANA/CLI/JBenchmarker.h>
0011 #include <JANA/JEventUnfolder.h>
0012 #include <JANA/JEventProcessor.h>
0013 #include <JANA/JEventSource.h>
0014 #include <JANA/Utils/JBenchUtils.h>
0015 
0016 
0017 namespace jana::perftest::basic {
0018 
0019 struct Data { size_t x; };
0020 
0021 struct PESrc : public JEventSource {
0022 
0023     Output<Data> data_out {this};
0024     Parameter<int> latency_us {this, "latency_us", 0};
0025 
0026     PESrc() {
0027         SetPrefix("src");
0028         SetCallbackStyle(CallbackStyle::ExpertMode);
0029         data_out.SetShortName("1");
0030     }
0031     JEventSource::Result Emit(JEvent& event) override {
0032         data_out().push_back(new Data {event.GetEventNumber()*3 });
0033         JBenchUtils::consume_cpu_us(*latency_us);
0034         return Result::Success;
0035     };
0036 };
0037 
0038 struct PEFac : public JFactory {
0039     Input<Data> data_in {this};
0040     Output<Data> data_out {this};
0041     Parameter<int> latency_us {this, "latency_us", 0};
0042     PEFac() {
0043         SetPrefix("fac");
0044         SetLevel(JEventLevel::PhysicsEvent);
0045         data_in.SetDatabundleName("1");
0046         data_out.SetShortName("2");
0047     }
0048     void Process(const JEvent&) override {
0049         auto x = data_in().at(0)->x * 10;
0050         data_out().push_back(new Data {x});
0051         JBenchUtils::consume_cpu_us(*latency_us);
0052     };
0053 };
0054 
0055 struct PEProc : public JEventProcessor {
0056     Input<Data> data_in {this};
0057     Parameter<int> latency_us {this, "latency_us", 0};
0058     PEProc() {
0059         SetPrefix("proc");
0060         SetLevel(JEventLevel::PhysicsEvent);
0061         SetCallbackStyle(CallbackStyle::ExpertMode);
0062         data_in.SetDatabundleName("2");
0063     }
0064     void ProcessSequential(const JEvent&) override {
0065         (void) (data_in().at(0)->x);
0066         JBenchUtils::consume_cpu_us(*latency_us);
0067     };
0068 };
0069 
0070 
0071 TEST_CASE("BasicTopology_Mini") {
0072 
0073     LOG << "Running BasicTopology_Mini";
0074 
0075     JApplication app;
0076     app.SetParameterValue("src:latency_us", 0);  // Infinity Hz
0077     app.SetParameterValue("fac:latency_us", 0);  // Infinity Hz
0078     app.SetParameterValue("proc:latency_us", 0); // Infinity Hz
0079     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0080     app.SetParameterValue("benchmark:rates_filename", "basic_mini.dat");
0081     app.SetParameterValue("benchmark:use_log_scale", true);
0082     app.SetParameterValue("benchmark:minthreads", "1");
0083     app.SetParameterValue("benchmark:maxthreads", "32");
0084 
0085     app.Add(new PESrc);
0086     app.Add(new PEProc);
0087     app.Add(new JFactoryGeneratorT<PEFac>);
0088 
0089     JBenchmarker benchmarker(&app);
0090     benchmarker.RunUntilFinished();
0091 }
0092 
0093 TEST_CASE("BasicTopology_Small") {
0094 
0095     LOG << "Running BasicTopology_Small";
0096 
0097     JApplication app;
0098     app.SetParameterValue("src:latency_us", 0);
0099     app.SetParameterValue("fac:latency_us", 1000000/5000);   // 5 kHz
0100     app.SetParameterValue("proc:latency_us", 0);
0101     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0102     app.SetParameterValue("benchmark:rates_filename", "basic_small.dat");
0103     app.SetParameterValue("benchmark:use_log_scale", true);
0104     app.SetParameterValue("benchmark:minthreads", "1");
0105     app.SetParameterValue("benchmark:maxthreads", "32");
0106 
0107     app.Add(new PESrc);
0108     app.Add(new PEProc);
0109     app.Add(new JFactoryGeneratorT<PEFac>);
0110 
0111     JBenchmarker benchmarker(&app);
0112     benchmarker.RunUntilFinished();
0113 }
0114 
0115 TEST_CASE("BasicTopology_Small_Saturation") {
0116 
0117     LOG << "Running BasicTopology_Small_Saturation";
0118 
0119     JApplication app;
0120     app.SetParameterValue("src:latency_us", 1'000'000 / 40'000); // 40 kHz
0121     app.SetParameterValue("fac:latency_us", 1'000'000 / 5000);   // 5 kHz
0122     app.SetParameterValue("proc:latency_us", 1'000'000 / 40'000); // 40 kHz
0123     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0124     app.SetParameterValue("benchmark:rates_filename", "basic_small_saturation.dat");
0125     app.SetParameterValue("benchmark:use_log_scale", false);
0126     app.SetParameterValue("benchmark:minthreads", "1");
0127     app.SetParameterValue("benchmark:maxthreads", "16");
0128 
0129     app.Add(new PESrc);
0130     app.Add(new PEProc);
0131     app.Add(new JFactoryGeneratorT<PEFac>);
0132 
0133     JBenchmarker benchmarker(&app);
0134     benchmarker.RunUntilFinished();
0135 }
0136 
0137 TEST_CASE("BasicTopology_Medium") {
0138 
0139     LOG << "Running BasicTopology_Medium";
0140 
0141     JApplication app;
0142     app.SetParameterValue("src:latency_us", 0);
0143     app.SetParameterValue("fac:latency_us", 1000000/50);  // 50 Hz
0144     app.SetParameterValue("proc:latency_us", 0);
0145     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0146     app.SetParameterValue("benchmark:rates_filename", "basic_medium.dat");
0147     app.SetParameterValue("benchmark:use_log_scale", true);
0148     app.SetParameterValue("benchmark:minthreads", "1");
0149     app.SetParameterValue("benchmark:maxthreads", "32");
0150 
0151     app.Add(new PESrc);
0152     app.Add(new PEProc);
0153     app.Add(new JFactoryGeneratorT<PEFac>);
0154 
0155     JBenchmarker benchmarker(&app);
0156     benchmarker.RunUntilFinished();
0157 }
0158 
0159 TEST_CASE("BasicTopology_Medium_Saturation") {
0160 
0161     LOG << "Running BasicTopology_Medium_Saturation";
0162 
0163     JApplication app;
0164     app.SetParameterValue("src:latency_us", 1'000'000 / 400); // 400 Hz
0165     app.SetParameterValue("fac:latency_us", 1'000'000 / 50);  // 50 Hz
0166     app.SetParameterValue("proc:latency_us", 1'000'000 / 400); // 400 Hz
0167     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0168     app.SetParameterValue("benchmark:rates_filename", "basic_medium_saturation.dat");
0169     app.SetParameterValue("benchmark:use_log_scale", false);
0170     app.SetParameterValue("benchmark:minthreads", "1");
0171     app.SetParameterValue("benchmark:maxthreads", "16");
0172 
0173     app.Add(new PESrc);
0174     app.Add(new PEProc);
0175     app.Add(new JFactoryGeneratorT<PEFac>);
0176 
0177     JBenchmarker benchmarker(&app);
0178     benchmarker.RunUntilFinished();
0179 }
0180 TEST_CASE("BasicTopology_Large") {
0181 
0182     LOG << "Running BasicTopology_Large";
0183 
0184     JApplication app;
0185     app.SetParameterValue("src:latency_us", 0);          // Infinity Hz
0186     app.SetParameterValue("fac:latency_us", 1000000/5);  // 5 Hz
0187     app.SetParameterValue("proc:latency_us", 0);         // 100 Hz
0188     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0189     app.SetParameterValue("benchmark:rates_filename", "basic_large.dat");
0190     app.SetParameterValue("benchmark:use_log_scale", true);
0191     app.SetParameterValue("benchmark:minthreads", "1");
0192     app.SetParameterValue("benchmark:maxthreads", "32");
0193 
0194     app.Add(new PESrc);
0195     app.Add(new PEProc);
0196     app.Add(new JFactoryGeneratorT<PEFac>);
0197 
0198     JBenchmarker benchmarker(&app);
0199     benchmarker.RunUntilFinished();
0200 }
0201 
0202 TEST_CASE("BasicTopology_Large_Saturation") {
0203 
0204     LOG << "Running BasicTopology_Large_Saturation";
0205 
0206     JApplication app;
0207     app.SetParameterValue("src:latency_us", 1'000'000/40);  // 40 Hz
0208     app.SetParameterValue("fac:latency_us", 1'000'000/5);   // 5 Hz
0209     app.SetParameterValue("proc:latency_us", 1'000'000/40); // 40 Hz
0210     app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0211     app.SetParameterValue("benchmark:rates_filename", "basic_large_saturation.dat");
0212     app.SetParameterValue("benchmark:use_log_scale", false);
0213     app.SetParameterValue("benchmark:minthreads", "1");
0214     app.SetParameterValue("benchmark:maxthreads", "16");
0215 
0216     app.Add(new PESrc);
0217     app.Add(new PEProc);
0218     app.Add(new JFactoryGeneratorT<PEFac>);
0219 
0220     JBenchmarker benchmarker(&app);
0221     benchmarker.RunUntilFinished();
0222 }
0223 
0224 
0225 TEST_CASE("BasicTopology_JTest") {
0226     // 5Hz for full reconstruction
0227     // 20kHz for stripped-down reconstruction (not per-core)
0228     // Base memory allcation: 100 MB/core + 600MB
0229     // 1 thread/event, disentangle 1 event, turn into 40.
0230     // disentangled (single event size) : 12.5 kB / event (before blown up)
0231     // entangled "block of 40": dis * 40
0232     
0233     auto params = new JParameterManager;
0234     params->SetParameter("jana:loglevel", "off");
0235 
0236     // Log levels get set as soon as JApp gets constructed
0237     params->SetParameter("jtest:parser:cputime_ms", 2);
0238     params->SetParameter("jtest:plotter:cputime_ms", 2);
0239 
0240     params->SetParameter("benchmark:resultsdir", "docs/perf_tests");
0241     params->SetParameter("benchmark:rates_filename", "basic_jtest.dat");
0242     params->SetParameter("benchmark:use_log_scale", true);
0243     params->SetParameter("benchmark:minthreads", "1");
0244     params->SetParameter("benchmark:maxthreads", "32");
0245 
0246     JApplication app(params);
0247     auto logger = params->GetLogger("PerfTests");
0248     app.AddPlugin("JTest");
0249 
0250     LOG_WARN(logger) << "Running JTest tuned to imitate halld_recon" << LOG_END;
0251     JBenchmarker benchmarker(&app);
0252     benchmarker.RunUntilFinished();
0253 }
0254 
0255 
0256 } // namespace
0257 
0258