diff --git a/Sim/Computation/DWBAComputation.h b/Sim/Computation/DWBAComputation.h index aafa7c0a56a5e99526d43e0dfc77aeecb711f719..48fd859af572782282aa8e84fde24ffe0f2755dd 100644 --- a/Sim/Computation/DWBAComputation.h +++ b/Sim/Computation/DWBAComputation.h @@ -41,11 +41,9 @@ public: std::vector<DiffuseElement>::iterator end_it); ~DWBAComputation() override; -private: - //! Performs a single-threaded DWBA computation for a DiffuseElement%s - //! in range m_begin_it ... m_end_it. Results are stored in those elements. void runProtected() override; +private: std::vector<DiffuseElement>::iterator m_begin_it, m_end_it; }; diff --git a/Sim/Computation/DepthprobeComputation.h b/Sim/Computation/DepthprobeComputation.h index 7fc75a6a2e8df2bd2ad68cc0e15711afbdcf7565..efc7108151fdbb188b1cca8fe4df7ffc33693278 100644 --- a/Sim/Computation/DepthprobeComputation.h +++ b/Sim/Computation/DepthprobeComputation.h @@ -37,9 +37,9 @@ public: DepthprobeElementIter end_it); ~DepthprobeComputation() override; -private: void runProtected() override; +private: DepthprobeElementIter m_begin_it, m_end_it; }; diff --git a/Sim/Computation/SpecularComputation.h b/Sim/Computation/SpecularComputation.h index 8a10a5c7c6e41d1ed980d5ec42f258c05eda848b..9a040ef892d798992cce3099395f747b8758ef27 100644 --- a/Sim/Computation/SpecularComputation.h +++ b/Sim/Computation/SpecularComputation.h @@ -36,9 +36,9 @@ public: SpecularElementIter end_it); ~SpecularComputation() override; -private: void runProtected() override; +private: //! these iterators define the span of detector bins this simulation will work on const SpecularElementIter m_begin_it, m_end_it; }; diff --git a/Sim/Simulation/DepthprobeSimulation.cpp b/Sim/Simulation/DepthprobeSimulation.cpp index 91497a09a573963aeef5c81a47782676b7ba679a..2c2f483024866c969db2318eb0f7cb8afa96daee 100644 --- a/Sim/Simulation/DepthprobeSimulation.cpp +++ b/Sim/Simulation/DepthprobeSimulation.cpp @@ -138,13 +138,14 @@ void DepthprobeSimulation::initElementVector() } } -std::unique_ptr<IComputation> -DepthprobeSimulation::createComputation(const ReSample& re_sample, size_t start, size_t n_elements) +void DepthprobeSimulation::runComputation(const ReSample& re_sample, size_t start, + size_t n_elements) { ASSERT(start < m_depth_eles.size() && start + n_elements <= m_depth_eles.size()); const auto& begin = m_depth_eles.begin() + static_cast<long>(start); - return std::make_unique<DepthprobeComputation>(re_sample, options(), progress(), begin, - begin + static_cast<long>(n_elements)); + DepthprobeComputation(re_sample, options(), progress(), begin, + begin + static_cast<long>(n_elements)) + .runProtected(); } void DepthprobeSimulation::normalize(size_t start, size_t n_elements) diff --git a/Sim/Simulation/DepthprobeSimulation.h b/Sim/Simulation/DepthprobeSimulation.h index e31bc5de1ade2e8f1c15a410a9af53a36fbde701..37a2c135c27a2f5af496635e2cdc9f93875e7ad0 100644 --- a/Sim/Simulation/DepthprobeSimulation.h +++ b/Sim/Simulation/DepthprobeSimulation.h @@ -66,9 +66,7 @@ private: void initElementVector() override; - //! Generates a single threaded computation for a given range of simulation elements - std::unique_ptr<IComputation> createComputation(const ReSample& re_sample, size_t start, - size_t n_elements) override; + void runComputation(const ReSample& re_sample, size_t start, size_t n_elements) override; //! Normalizes the detector counts to beam intensity, to solid angle, and to exposure angle. void normalize(size_t start, size_t n_elements) override; diff --git a/Sim/Simulation/ISimulation.cpp b/Sim/Simulation/ISimulation.cpp index 63f66195e9c6e4c273437e4c1efd748f82734d6f..4911506972955fade7ec262053b734faa92c9c5e 100644 --- a/Sim/Simulation/ISimulation.cpp +++ b/Sim/Simulation/ISimulation.cpp @@ -220,8 +220,7 @@ void ISimulation::runSingleSimulation(const ReSample& re_sample, size_t batch_st if (n_threads == 1) { // Run computation in current thread. try { - const auto& c = createComputation(re_sample, batch_start, batch_size); - c->runProtected(); // <---- here most work is done (unthreaded case)! + runComputation(re_sample, batch_start, batch_size); } catch (const std::exception& ex) { throw std::runtime_error(std::string("Unexpected error in simulation:\n") + ex.what()); } @@ -239,8 +238,7 @@ void ISimulation::runSingleSimulation(const ReSample& re_sample, size_t batch_st threads.emplace_back(new std::thread( [this, &re_sample, &failure_messages, &mutex, thread_start, thread_size]() { try { - const auto& c = createComputation(re_sample, thread_start, thread_size); - c->runProtected(); // <---- here most work is done (threaded case)! + runComputation(re_sample, thread_start, thread_size); } catch (const std::exception& ex) { mutex.lock(); failure_messages.push_back(ex.what()); diff --git a/Sim/Simulation/ISimulation.h b/Sim/Simulation/ISimulation.h index 00d759bd0c2336a93880d66a096e6f35c73d6f0c..afb4691d9f2fadf43ff6382c67b2ef88380ede28 100644 --- a/Sim/Simulation/ISimulation.h +++ b/Sim/Simulation/ISimulation.h @@ -100,14 +100,13 @@ private: //! Initializes the vector of ISimulation elements. virtual void initElementVector() = 0; - //! Generate a single threaded computation for a given range of simulation elements. + //! Runs a single threaded computation for a given range of simulation elements. //! @param re_sample Preprocessed version of our sample //! @param start Index of the first element to include into computation //! @param n_elements Number of elements to process - virtual std::unique_ptr<IComputation> createComputation(const ReSample& re_sample, size_t start, - size_t n_elements) = 0; + virtual void runComputation(const ReSample& re_sample, size_t start, size_t n_elements) = 0; - //! Normalize the detector counts to beam intensity, to solid angle, and to exposure angle. + //! Normalizes the detector counts to beam intensity, to solid angle, and to exposure angle. virtual void normalize(size_t start, size_t n_elements) = 0; virtual void addBackgroundIntensity(size_t start, size_t n_elements) = 0; @@ -115,7 +114,7 @@ private: virtual void addDataToCache(double weight) = 0; //... Virtual getters: - //! Force polarized computation even in absence of sample magnetization or external fields + //! Forces polarized computation even in absence of sample magnetization or external fields virtual bool force_polarized() const = 0; //! Returns the number of elements this simulation needs to calculate. diff --git a/Sim/Simulation/OffspecSimulation.cpp b/Sim/Simulation/OffspecSimulation.cpp index f37a00894968c4d31ee048df3e2091c7a6a410ff..9c38e251af8b6ec89c787a7376400ddc5e176898 100644 --- a/Sim/Simulation/OffspecSimulation.cpp +++ b/Sim/Simulation/OffspecSimulation.cpp @@ -140,13 +140,12 @@ void OffspecSimulation::initDistributionHandler() } } -std::unique_ptr<IComputation> OffspecSimulation::createComputation(const ReSample& re_sample, - size_t start, size_t n_elements) +void OffspecSimulation::runComputation(const ReSample& re_sample, size_t start, size_t n_elements) { ASSERT(start < m_eles.size() && start + n_elements <= m_eles.size()); const auto& begin = m_eles.begin() + static_cast<long>(start); - return std::make_unique<DWBAComputation>(re_sample, options(), progress(), begin, - begin + static_cast<long>(n_elements)); + DWBAComputation(re_sample, options(), progress(), begin, begin + static_cast<long>(n_elements)) + .runProtected(); } void OffspecSimulation::normalize(size_t start, size_t n_elements) diff --git a/Sim/Simulation/OffspecSimulation.h b/Sim/Simulation/OffspecSimulation.h index 5f625a0dd1aa3f78cbb4a2b826a2450f9f3d6415..4e655463bbb87fd5a8c83c71b8d67f7f82258a44 100644 --- a/Sim/Simulation/OffspecSimulation.h +++ b/Sim/Simulation/OffspecSimulation.h @@ -73,11 +73,8 @@ private: void initElementVector() override; - //! Generates a single threaded computation for a given range of simulation elements - std::unique_ptr<IComputation> createComputation(const ReSample& re_sample, size_t start, - size_t n_elements) override; + void runComputation(const ReSample& re_sample, size_t start, size_t n_elements) override; - //! Normalizes the detector counts to beam intensity, to solid angle, and to exposure angle. void normalize(size_t start, size_t n_elements) override; void addBackgroundIntensity(size_t start, size_t n_elements) override; diff --git a/Sim/Simulation/ScatteringSimulation.cpp b/Sim/Simulation/ScatteringSimulation.cpp index 103ebd9df73c18632ca063b13184d4697e40d2fc..b0b6d84c036066778b00be14da76cdcc061765bf 100644 --- a/Sim/Simulation/ScatteringSimulation.cpp +++ b/Sim/Simulation/ScatteringSimulation.cpp @@ -119,13 +119,13 @@ void ScatteringSimulation::initElementVector() m_eles = generateElements(beam()); } -std::unique_ptr<IComputation> -ScatteringSimulation::createComputation(const ReSample& re_sample, size_t start, size_t n_elements) +void ScatteringSimulation::runComputation(const ReSample& re_sample, size_t start, + size_t n_elements) { ASSERT(start < m_eles.size() && start + n_elements <= m_eles.size()); const auto& begin = m_eles.begin() + static_cast<long>(start); - return std::make_unique<DWBAComputation>(re_sample, options(), progress(), begin, - begin + static_cast<long>(n_elements)); + DWBAComputation(re_sample, options(), progress(), begin, begin + static_cast<long>(n_elements)) + .runProtected(); } void ScatteringSimulation::normalize(size_t start, size_t n_elements) diff --git a/Sim/Simulation/ScatteringSimulation.h b/Sim/Simulation/ScatteringSimulation.h index fad15681a55d00b6721c324e8a02dba0a4169e1a..f6fe01bf6fdb52131e685ee8c8d616669a2746e5 100644 --- a/Sim/Simulation/ScatteringSimulation.h +++ b/Sim/Simulation/ScatteringSimulation.h @@ -77,11 +77,8 @@ private: void initElementVector() override; - //! Generates a single threaded computation for a given range of simulation elements - std::unique_ptr<IComputation> createComputation(const ReSample& re_sample, size_t start, - size_t n_elements) override; + void runComputation(const ReSample& re_sample, size_t start, size_t n_elements) override; - //! Normalizes the detector counts to beam intensity, to solid angle, and to exposure angle. void normalize(size_t start, size_t n_elements) override; void addBackgroundIntensity(size_t start, size_t n_elements) override; diff --git a/Sim/Simulation/SpecularSimulation.cpp b/Sim/Simulation/SpecularSimulation.cpp index 4e7b7135e1ae896d21c89f98432d9f3c45250210..8c53b8bf04554bf356a1b49aa9f639db4a68d589 100644 --- a/Sim/Simulation/SpecularSimulation.cpp +++ b/Sim/Simulation/SpecularSimulation.cpp @@ -50,13 +50,13 @@ void SpecularSimulation::initElementVector() m_eles = m_scan->generateElements(); } -std::unique_ptr<IComputation> SpecularSimulation::createComputation(const ReSample& re_sample, - size_t start, size_t n_elements) +void SpecularSimulation::runComputation(const ReSample& re_sample, size_t start, size_t n_elements) { ASSERT(start < m_eles.size() && start + n_elements <= m_eles.size()); const auto& begin = m_eles.begin() + static_cast<long>(start); - return std::make_unique<SpecularComputation>(re_sample, options(), progress(), begin, - begin + static_cast<long>(n_elements)); + SpecularComputation(re_sample, options(), progress(), begin, + begin + static_cast<long>(n_elements)) + .runProtected(); } void SpecularSimulation::normalize(size_t start, size_t n_elements) diff --git a/Sim/Simulation/SpecularSimulation.h b/Sim/Simulation/SpecularSimulation.h index 345133991f2f268d4db62684363dfb1906f394a7..57bcc9d4a53ae2bf939567b51c5fb66b154436f1 100644 --- a/Sim/Simulation/SpecularSimulation.h +++ b/Sim/Simulation/SpecularSimulation.h @@ -47,11 +47,8 @@ private: //... Overridden executors: void initElementVector() override; - //! Generates a single threaded computation for a given range of simulation elements - std::unique_ptr<IComputation> createComputation(const ReSample& re_sample, size_t start, - size_t n_elements) override; + void runComputation(const ReSample& re_sample, size_t start, size_t n_elements) override; - //! Normalizes the detector counts to beam intensity, to solid angle, and to exposure angle. void normalize(size_t start_ind, size_t n_elements) override; void addBackgroundIntensity(size_t start_ind, size_t n_elements) override;