Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:35:28

0001 #include "catch.hpp"
0002 
0003 #include <JANA/JApplication.h>
0004 #include <JANA/Utils/JCpuInfo.h>
0005 #include <JANA/Engine/JExecutionEngine.h>
0006 
0007 #include "ScaleTests.h"
0008 
0009 TEST_CASE("MissingEventSource") {
0010     JApplication app;
0011     app.Initialize();
0012     // Initialize succeeds
0013     try {
0014         app.Run();
0015         // Run() throws
0016         REQUIRE(0 == 1);
0017     }
0018     catch (JException& e) {
0019         REQUIRE(e.GetMessage() == "Cannot execute an empty topology! Hint: Have you provided an event source?");
0020     }
0021 }
0022 
0023 TEST_CASE("NThreads") {
0024 
0025     JApplication app;
0026     app.SetParameterValue("jana:nevents",3);
0027     app.SetParameterValue("jana:loglevel","warn");
0028     app.Add(new scaletest::DummySource);
0029 
0030     SECTION("If nthreads not provided, default to 1") {
0031         app.Run(false);
0032         auto threads = app.GetNThreads();
0033         REQUIRE(threads == 1);
0034         app.Stop(true);
0035     }
0036 
0037     SECTION("If nthreads=Ncores, use ncores") {
0038         auto ncores = JCpuInfo::GetNumCpus();
0039         app.SetParameterValue("nthreads", "Ncores");
0040         app.Run(false);
0041         auto threads = app.GetNThreads();
0042         REQUIRE(threads == ncores);
0043         app.Stop(true);
0044     }
0045 
0046     SECTION("If nthreads is something else, use that") {
0047         app.SetParameterValue("nthreads", 17);
0048         app.Run(false);
0049         auto threads = app.GetNThreads();
0050         REQUIRE(threads == 17);
0051         app.Stop(true);
0052     }
0053 }
0054 
0055 TEST_CASE("ScaleNWorkerUpdate") {
0056     JApplication app;
0057     app.SetParameterValue("nthreads",4);
0058     app.SetParameterValue("jana:loglevel","warn");
0059     app.Add(new scaletest::DummySource);
0060     app.Add(new scaletest::DummyProcessor);
0061     app.Add(new JFactoryGeneratorT<scaletest::DummyFactory>());
0062     app.Run(false);
0063     auto threads = app.GetNThreads();
0064     REQUIRE(threads == 4);
0065 
0066     app.Stop(true, false);
0067 
0068     app.Scale(8); // Scale blocks until workers have fired up
0069     threads = app.GetNThreads();
0070     REQUIRE(threads == 8);
0071     app.Stop(true);
0072 }
0073 
0074 TEST_CASE("ScaleThroughputImprovement", "[.][performance]") {
0075 
0076     JApplication app;
0077     app.SetParameterValue("jana:loglevel", "INFO");
0078     //app.SetTicker(false);
0079     app.Add(new scaletest::DummySource);
0080     app.Add(new scaletest::DummyProcessor);
0081     app.Add(new JFactoryGeneratorT<scaletest::DummyFactory>());
0082     app.Initialize();
0083     auto jee = app.GetService<JExecutionEngine>();
0084 
0085     jee->ScaleWorkers(1);
0086     jee->RunTopology();
0087     std::this_thread::sleep_for(std::chrono::seconds(5));
0088     auto throughput_hz_1 = jee->GetPerf().throughput_hz;
0089     std::cout << "nthreads=1: throughput_hz=" << throughput_hz_1 << std::endl;
0090     jee->PauseTopology();
0091     jee->RunSupervisor();
0092 
0093     jee->ScaleWorkers(2);
0094     jee->RunTopology();
0095     std::this_thread::sleep_for(std::chrono::seconds(5));
0096     auto throughput_hz_2 = jee->GetPerf().throughput_hz;
0097     std::cout << "nthreads=2: throughput_hz=" << throughput_hz_2 << std::endl;
0098     REQUIRE(jee->GetPerf().runstatus == JExecutionEngine::RunStatus::Running);
0099     jee->PauseTopology();
0100     jee->RunSupervisor();
0101 
0102     jee->ScaleWorkers(4);
0103     jee->RunTopology();
0104     std::this_thread::sleep_for(std::chrono::seconds(5));
0105     auto throughput_hz_4 = jee->GetPerf().throughput_hz;
0106     jee->PauseTopology();
0107     jee->RunSupervisor();
0108     std::cout << "nthreads=4: throughput_hz=" << throughput_hz_4 << std::endl;
0109 
0110     jee->FinishTopology();
0111 
0112     REQUIRE(throughput_hz_2 > throughput_hz_1*1.5);
0113     REQUIRE(throughput_hz_4 > throughput_hz_2*1.25);
0114 }