From 4fb85aa0d32b3d576160eeb22f0e2c11811baac7 Mon Sep 17 00:00:00 2001 From: Robin Leroy Date: Sat, 31 May 2014 17:34:42 +0200 Subject: [PATCH] UAAAH --- LICENSE.txt | 2 +- Principia.sln | 14 +++- benchmarks/benchmarks.vcxproj | 4 + benchmarks/benchmarks.vcxproj.filters | 8 ++ ...tic_partitioned_runge_kutta_integrator.cpp | 49 ++--------- ...tic_partitioned_runge_kutta_integrator.hpp | 17 ++++ ...artitioned_runge_kutta_integrator_body.hpp | 40 +++++++++ clr_benchmarks/clr_benchmarks.vcxproj | 84 +++++++++++++++++++ clr_benchmarks/clr_benchmarks.vcxproj.filters | 21 +++++ clr_benchmarks/main.cpp | 7 ++ .../symplectic_partitioned_runge_kutta.cpp | 19 +++++ .../clr_benchmarks_adapter.vcxproj | 2 +- ...tic_partitioned_runge_kutta_integrator.cpp | 41 ++------- ...tic_partitioned_runge_kutta_integrator.hpp | 4 +- ...artitioned_runge_kutta_integrator_body.hpp | 4 + ...artitioned_runge_kutta_integrator_test.cpp | 31 ++----- testing_utilities/numerical_analysis.hpp | 25 ++++++ testing_utilities/numerical_analysis_body.hpp | 20 +++++ testing_utilities/testing_utilities.vcxproj | 2 + .../testing_utilities.vcxproj.filters | 6 ++ 20 files changed, 295 insertions(+), 105 deletions(-) create mode 100644 benchmarks/symplectic_partitioned_runge_kutta_integrator.hpp create mode 100644 benchmarks/symplectic_partitioned_runge_kutta_integrator_body.hpp create mode 100644 clr_benchmarks/clr_benchmarks.vcxproj create mode 100644 clr_benchmarks/clr_benchmarks.vcxproj.filters create mode 100644 clr_benchmarks/main.cpp create mode 100644 clr_benchmarks/symplectic_partitioned_runge_kutta.cpp create mode 100644 testing_utilities/numerical_analysis.hpp create mode 100644 testing_utilities/numerical_analysis_body.hpp diff --git a/LICENSE.txt b/LICENSE.txt index d57671e023..efec3196fd 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/Principia.sln b/Principia.sln index 22f0440404..457349b0e6 100644 --- a/Principia.sln +++ b/Principia.sln @@ -22,6 +22,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project Property Sheets", "Project Property Sheets", "{E12187B5-1432-4401-B671-FC3E06256CFD}" ProjectSection(SolutionItems) = preProject copy_libglog_dll.props = copy_libglog_dll.props + google_benchmark.props = google_benchmark.props google_test_framework.props = google_test_framework.props include_solution.props = include_solution.props EndProjectSection @@ -34,14 +35,23 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testing_utilities", "testin EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "integrators", "integrators\integrators.vcxproj", "{86AFF67D-38CD-487E-B4C1-B93984A9ED0D}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{71A8A85A-3694-4E4F-85C1-D2A1FE773EB7}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmarks", "benchmarks\benchmarks.vcxproj", "{7B174B21-0837-4BEE-864E-08AD3C74046A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clr_benchmarks_adapter", "clr_benchmarks_adapter\clr_benchmarks_adapter.vcxproj", "{940828E3-AAA8-4AA0-B371-03516A1E0242}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clr_benchmarks", "clr_benchmarks\clr_benchmarks.vcxproj", "{36F3CAF9-1F27-42DC-B5C5-29CB2B8497F4}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Git Auxiliary Files", "Git Auxiliary Files", "{0F8586AA-FAEF-4EC5-9D87-A96B9F7561EE}" + ProjectSection(SolutionItems) = preProject + .gitattributes = .gitattributes + .gitignore = .gitignore + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Legal", "Legal", "{4B25658F-A202-4286-B0CA-5CE54882787C}" + ProjectSection(SolutionItems) = preProject + LICENSE.txt = LICENSE.txt + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/benchmarks/benchmarks.vcxproj b/benchmarks/benchmarks.vcxproj index 9cccc5e173..d333b0e47c 100644 --- a/benchmarks/benchmarks.vcxproj +++ b/benchmarks/benchmarks.vcxproj @@ -91,6 +91,10 @@ + + + + diff --git a/benchmarks/benchmarks.vcxproj.filters b/benchmarks/benchmarks.vcxproj.filters index 3f11d59e3d..6aefa43d14 100644 --- a/benchmarks/benchmarks.vcxproj.filters +++ b/benchmarks/benchmarks.vcxproj.filters @@ -18,4 +18,12 @@ Source Files + + + Header Files + + + Source Files + + \ No newline at end of file diff --git a/benchmarks/symplectic_partitioned_runge_kutta_integrator.cpp b/benchmarks/symplectic_partitioned_runge_kutta_integrator.cpp index c85ccf9c16..c245183605 100644 --- a/benchmarks/symplectic_partitioned_runge_kutta_integrator.cpp +++ b/benchmarks/symplectic_partitioned_runge_kutta_integrator.cpp @@ -1,4 +1,5 @@ - +#include "benchmarks/symplectic_partitioned_runge_kutta_integrator.hpp" + // .\Release\benchmarks_tests.exe --benchmark_repetitions=5 --benchmark_min_time=300 // NOLINT(whitespace/line_length) // Benchmarking on 1 X 3310 MHz CPU // 2014/05/30-20:51:41 @@ -11,13 +12,11 @@ // BM_SolveHarmonicOscillator 1231751867 1225231854 50 1.37019e-013, 1.37057e-013 // NOLINT(whitespace/line_length) // BM_SolveHarmonicOscillator_mean 1256726528 1220847667 251 1.37019e-013, 1.37057e-013 // NOLINT(whitespace/line_length) // BM_SolveHarmonicOscillator_stddev 66665752 5858502 251 1.37019e-013, 1.37057e-013 // NOLINT(whitespace/line_length) + #define GLOG_NO_ABBREVIATED_SEVERITIES -#undef TRACE_SYMPLECTIC_PARTITIONED_RUNGE_KUTTA_INTEGRATOR #include -#include -#include "integrators/symplectic_partitioned_runge_kutta_integrator.hpp" // Must come last to avoid conflicts when defining the CHECK macros. #include "benchmark/benchmark.h" @@ -26,44 +25,12 @@ using principia::integrators::SPRKIntegrator; namespace principia { namespace benchmarks { -namespace { - -inline void compute_harmonic_oscillator_force(double const t, - std::vector const& q, - std::vector* result) { - (*result)[0] = -q[0]; -} - -inline void compute_harmonic_oscillator_velocity(std::vector const& p, - std::vector* result) { - (*result)[0] = p[0]; -} - -} // namespace - -void SolveHarmonicOscillator(benchmark::State* state, - double* q_error, - double* p_error) { - SPRKIntegrator integrator; - SPRKIntegrator::Parameters parameters; +void SolveHarmonicOscillatorAndComputeError(benchmark::State* state, + double* q_error, + double* p_error) { SPRKIntegrator::Solution solution; - integrator.Initialize(integrator.Order5Optimal()); - - parameters.q0 = {1.0}; - parameters.p0 = {0.0}; - parameters.t0 = 0.0; -#ifdef _DEBUG - parameters.tmax = 100.0; -#else - parameters.tmax = 1000.0; -#endif - parameters.Δt = 1.0E-4; - parameters.sampling_period = 1; - integrator.Solve(&compute_harmonic_oscillator_force, - &compute_harmonic_oscillator_velocity, - parameters, - &solution); + SolveHarmonicOscillator(&solution); state->PauseTiming(); *q_error = 0; @@ -84,7 +51,7 @@ static void BM_SolveHarmonicOscillator( double q_error; double p_error; while (state.KeepRunning()) { - SolveHarmonicOscillator(&state, &q_error, &p_error); + SolveHarmonicOscillatorAndComputeError(&state, &q_error, &p_error); } std::stringstream ss; ss << q_error << ", " << p_error; diff --git a/benchmarks/symplectic_partitioned_runge_kutta_integrator.hpp b/benchmarks/symplectic_partitioned_runge_kutta_integrator.hpp new file mode 100644 index 0000000000..600fd32fda --- /dev/null +++ b/benchmarks/symplectic_partitioned_runge_kutta_integrator.hpp @@ -0,0 +1,17 @@ +#pragma once + +#undef TRACE_SYMPLECTIC_PARTITIONED_RUNGE_KUTTA_INTEGRATOR + +#include "integrators/symplectic_partitioned_runge_kutta_integrator.hpp" + +using principia::integrators::SPRKIntegrator; + +namespace principia { +namespace benchmarks { + +inline void SolveHarmonicOscillator(SPRKIntegrator::Solution* solution); + +} // namespace benchmarks +} // namespace principia + +#include "benchmarks/symplectic_partitioned_runge_kutta_integrator_body.hpp" diff --git a/benchmarks/symplectic_partitioned_runge_kutta_integrator_body.hpp b/benchmarks/symplectic_partitioned_runge_kutta_integrator_body.hpp new file mode 100644 index 0000000000..7837868292 --- /dev/null +++ b/benchmarks/symplectic_partitioned_runge_kutta_integrator_body.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include + +#undef TRACE_SYMPLECTIC_PARTITIONED_RUNGE_KUTTA_INTEGRATOR + +#include "integrators/symplectic_partitioned_runge_kutta_integrator.hpp" +#include "testing_utilities/numerical_analysis.hpp" + +using principia::integrators::SPRKIntegrator; + +namespace principia { +namespace benchmarks { + +inline void SolveHarmonicOscillator(SPRKIntegrator::Solution* solution) { + using principia::testing_utilities::ComputeHarmonicOscillatorForce; + using principia::testing_utilities::ComputeHarmonicOscillatorVelocity; + SPRKIntegrator integrator; + SPRKIntegrator::Parameters parameters; + + integrator.Initialize(integrator.Order5Optimal()); + + parameters.q0 = {1.0}; + parameters.p0 = {0.0}; + parameters.t0 = 0.0; +#ifdef _DEBUG + parameters.tmax = 100.0; +#else + parameters.tmax = 1000.0; +#endif + parameters.Δt = 1.0E-4; + parameters.sampling_period = 1; + integrator.Solve(&ComputeHarmonicOscillatorForce, + &ComputeHarmonicOscillatorVelocity, + parameters, + solution); +} + +} // namespace benchmarks +} // namespace principia diff --git a/clr_benchmarks/clr_benchmarks.vcxproj b/clr_benchmarks/clr_benchmarks.vcxproj new file mode 100644 index 0000000000..465b3df9c5 --- /dev/null +++ b/clr_benchmarks/clr_benchmarks.vcxproj @@ -0,0 +1,84 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {36F3CAF9-1F27-42DC-B5C5-29CB2B8497F4} + clr_benchmarks + + + + Application + true + v120 + MultiByte + true + + + Application + false + v120 + true + MultiByte + true + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + {940828e3-aaa8-4aa0-b371-03516a1e0242} + + + + + + diff --git a/clr_benchmarks/clr_benchmarks.vcxproj.filters b/clr_benchmarks/clr_benchmarks.vcxproj.filters new file mode 100644 index 0000000000..520c1a38c0 --- /dev/null +++ b/clr_benchmarks/clr_benchmarks.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/clr_benchmarks/main.cpp b/clr_benchmarks/main.cpp new file mode 100644 index 0000000000..277c45f923 --- /dev/null +++ b/clr_benchmarks/main.cpp @@ -0,0 +1,7 @@ +#include "benchmark/benchmark.h" + +int main(int argc, const char* argv[]) { + benchmark::Initialize(&argc, argv); + + benchmark::RunSpecifiedBenchmarks(); +} diff --git a/clr_benchmarks/symplectic_partitioned_runge_kutta.cpp b/clr_benchmarks/symplectic_partitioned_runge_kutta.cpp new file mode 100644 index 0000000000..068991e834 --- /dev/null +++ b/clr_benchmarks/symplectic_partitioned_runge_kutta.cpp @@ -0,0 +1,19 @@ +#define GLOG_NO_ABBREVIATED_SEVERITIES + +// Must come last to avoid conflicts when defining the CHECK macros. +#include "benchmark/benchmark.h" + +namespace principia { +namespace clr_benchmarks { + +static void BM_CLR_SolveHarmonicOscillator( + benchmark::State& state) { // NOLINT(runtime/references) + while (state.KeepRunning()) { + principia::clr_benchmarks_adapter::SPRKIntegratorCLRBenchmark::SolveHarmonicOscillator(); + } +} + +BENCHMARK(BM_CLR_SolveHarmonicOscillator); + +} // namespace clr_benchmarks +} // namespace principia diff --git a/clr_benchmarks_adapter/clr_benchmarks_adapter.vcxproj b/clr_benchmarks_adapter/clr_benchmarks_adapter.vcxproj index 59381e1b57..e6eec65ad7 100644 --- a/clr_benchmarks_adapter/clr_benchmarks_adapter.vcxproj +++ b/clr_benchmarks_adapter/clr_benchmarks_adapter.vcxproj @@ -76,4 +76,4 @@ - \ No newline at end of file + diff --git a/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.cpp b/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.cpp index 78f8e3b50b..a687fb6cc0 100644 --- a/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.cpp +++ b/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.cpp @@ -1,49 +1,18 @@ -#include "clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.hpp" +#include "clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.hpp" // NOLINT(whitespace/line_length) +#include "benchmarks/symplectic_partitioned_runge_kutta_integrator.hpp" #undef TRACE_SYMPLECTIC_PARTITIONED_RUNGE_KUTTA_INTEGRATOR #include "integrators/symplectic_partitioned_runge_kutta_integrator.hpp" using principia::integrators::SPRKIntegrator; namespace principia { -namespace clr_benchmarks { - -namespace { - -inline void compute_harmonic_oscillator_force(double const t, - std::vector const& q, - std::vector* result) { - (*result)[0] = -q[0]; -} - -inline void compute_harmonic_oscillator_velocity(std::vector const& p, - std::vector* result) { - (*result)[0] = p[0]; -} - -} // namespace +namespace clr_benchmarks_adapter { void SPRKIntegratorCLRBenchmark::SolveHarmonicOscillator() { - SPRKIntegrator integrator; - SPRKIntegrator::Parameters parameters; SPRKIntegrator::Solution solution; - - parameters.q0 = {1.0}; - parameters.p0 = {0.0}; - parameters.t0 = 0.0; -#ifdef _DEBUG - parameters.tmax = 100.0; -#else - parameters.tmax = 1000.0; -#endif - parameters.Δt = 1.0E-4; - parameters.coefficients = integrator.Order5Optimal(); - parameters.sampling_period = 1; - integrator.Solve(&compute_harmonic_oscillator_force, - &compute_harmonic_oscillator_velocity, - parameters, - &solution); + principia::benchmarks::SolveHarmonicOscillator(&solution); } -} // namespace clr_benchmarks +} // namespace clr_benchmarks_adapter } // namespace principia diff --git a/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.hpp b/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.hpp index 0d1088d7a8..7bcba334ed 100644 --- a/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.hpp +++ b/clr_benchmarks_adapter/symplectic_partitioned_runge_kutta_integrator.hpp @@ -1,12 +1,12 @@ #pragma once namespace principia { -namespace clr_benchmarks { +namespace clr_benchmarks_adapter { public ref class SPRKIntegratorCLRBenchmark abstract sealed { public: static void SolveHarmonicOscillator(); }; -} // namespace clr_benchmarks +} // namespace clr_benchmarks_adapter } // namespace principia diff --git a/integrators/symplectic_partitioned_runge_kutta_integrator_body.hpp b/integrators/symplectic_partitioned_runge_kutta_integrator_body.hpp index 489277d7b6..3b9ba140ee 100644 --- a/integrators/symplectic_partitioned_runge_kutta_integrator_body.hpp +++ b/integrators/symplectic_partitioned_runge_kutta_integrator_body.hpp @@ -51,11 +51,15 @@ SPRKIntegrator::Order5Optimal() const { } inline void SPRKIntegrator::Initialize(Coefficients const& coefficients) { +#ifndef _MANAGED CHECK_EQ(2, coefficients.size()); +#endif a_ = coefficients[0]; b_ = coefficients[1]; stages_ = b_.size(); +#ifndef _MANAGED CHECK_EQ(stages_, a_.size()); +#endif // Runge-Kutta time weights. c_.resize(stages_); diff --git a/integrators/symplectic_partitioned_runge_kutta_integrator_test.cpp b/integrators/symplectic_partitioned_runge_kutta_integrator_test.cpp index 19ceba9fe6..cb780c106b 100644 --- a/integrators/symplectic_partitioned_runge_kutta_integrator_test.cpp +++ b/integrators/symplectic_partitioned_runge_kutta_integrator_test.cpp @@ -12,13 +12,17 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "quantities/dimensionless.hpp" +#include "testing_utilities/numerical_analysis.hpp" #include "testing_utilities/numerics.hpp" #include "testing_utilities/statistics.hpp" -using principia::testing_utilities::AbsoluteError; using testing::AllOf; using testing::Gt; using testing::Lt; +using principia::quantities::Dimensionless; +using principia::testing_utilities::AbsoluteError; +using principia::testing_utilities::ComputeHarmonicOscillatorForce; +using principia::testing_utilities::ComputeHarmonicOscillatorVelocity; using principia::testing_utilities::BidimensionalDatasetMathematicaInput; using principia::testing_utilities::Slope; using principia::testing_utilities::PearsonProductMomentCorrelationCoefficient; @@ -26,23 +30,6 @@ using principia::testing_utilities::PearsonProductMomentCorrelationCoefficient; namespace principia { namespace integrators { -namespace { - -using quantities::Dimensionless; - -inline void compute_harmonic_oscillator_force(double const t, - std::vector const& q, - std::vector* result) { - (*result)[0] = -q[0]; -} - -inline void compute_harmonic_oscillator_velocity(std::vector const& p, - std::vector* result) { - (*result)[0] = p[0]; -} - -} // namespace - class SPRKTest : public testing::Test { public: static void SetUpTestCase() { @@ -70,8 +57,8 @@ TEST_F(SPRKTest, HarmonicOscillator) { #endif parameters_.Δt = 1.0E-4; parameters_.sampling_period = 1; - integrator_.Solve(&compute_harmonic_oscillator_force, - &compute_harmonic_oscillator_velocity, + integrator_.Solve(&ComputeHarmonicOscillatorForce, + &ComputeHarmonicOscillatorVelocity, parameters_, &solution_); double q_error = 0; double p_error = 0; @@ -105,8 +92,8 @@ TEST_F(SPRKTest, Convergence) { std::vector log_q_errors(step_sizes); std::vector log_p_errors(step_sizes); for (int i = 0; i < step_sizes; ++i, parameters_.Δt /= step_reduction) { - integrator_.Solve(&compute_harmonic_oscillator_force, - &compute_harmonic_oscillator_velocity, + integrator_.Solve(&ComputeHarmonicOscillatorForce, + &ComputeHarmonicOscillatorVelocity, parameters_, &solution_); log_step_sizes[i] = std::log10(parameters_.Δt); log_q_errors[i] = std::log10( diff --git a/testing_utilities/numerical_analysis.hpp b/testing_utilities/numerical_analysis.hpp new file mode 100644 index 0000000000..b87fbd81e8 --- /dev/null +++ b/testing_utilities/numerical_analysis.hpp @@ -0,0 +1,25 @@ +// Right-hand sides for various differential equations frequently used to test +// the properties of integrators. + +#pragma once + +#include + +namespace principia { +namespace testing_utilities { + +// The one-dimensional unit harmonic oscillator, +// q' = p, |ComputeHarmonicOscillatorVelocity|, +// p' = -q, |ComputeHarmonicOscillatorForce|. + +void ComputeHarmonicOscillatorVelocity(std::vector const& p, + std::vector* result); + +void ComputeHarmonicOscillatorForce(double const t, + std::vector const& q, + std::vector* result); + +} // namespace testing_utilities +} // namespace principia + +#include "testing_utilities/numerical_analysis_body.hpp" diff --git a/testing_utilities/numerical_analysis_body.hpp b/testing_utilities/numerical_analysis_body.hpp new file mode 100644 index 0000000000..331bffbcd6 --- /dev/null +++ b/testing_utilities/numerical_analysis_body.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace principia { +namespace testing_utilities { + +inline void ComputeHarmonicOscillatorForce(double const t, + std::vector const& q, + std::vector* result) { + (*result)[0] = -q[0]; +} + +inline void ComputeHarmonicOscillatorVelocity(std::vector const& p, + std::vector* result) { + (*result)[0] = p[0]; +} + +} // namespace testing_utilities +} // namespace principia diff --git a/testing_utilities/testing_utilities.vcxproj b/testing_utilities/testing_utilities.vcxproj index 534f54a046..5df36fe76f 100644 --- a/testing_utilities/testing_utilities.vcxproj +++ b/testing_utilities/testing_utilities.vcxproj @@ -17,6 +17,8 @@ + + diff --git a/testing_utilities/testing_utilities.vcxproj.filters b/testing_utilities/testing_utilities.vcxproj.filters index b95de94b31..7eae10a0eb 100644 --- a/testing_utilities/testing_utilities.vcxproj.filters +++ b/testing_utilities/testing_utilities.vcxproj.filters @@ -44,6 +44,12 @@ Source Files + + Header Files + + + Source Files +