From 7e118e9b1ea40190b3ea55f070ecd41dcc4496e7 Mon Sep 17 00:00:00 2001 From: "Billy K. Poon" Date: Sun, 10 Dec 2023 13:51:33 -0800 Subject: [PATCH] boost: switch deprecated boost/timer.hpp to boost/timer/timer.hpp - Change header from boost/timer.hpp to boost/timer/timer.hpp - Change boost::timer to boost::timer::auto_cpu_timer - Handle switch to nanoseconds - Build Boost timer library if needed --- boost_adaptbx/SConscript | 38 ++++++++++++++++--- .../tests/python_streambuf_test_ext.cpp | 18 ++++----- cbflib_adaptbx/detectors/cbf_adaptor.h | 1 - cctbx/math/SConscript | 1 + cctbx/math/time_trigonometry.cpp | 10 ++--- scitbx/lbfgsb/boost_python/SConscript | 1 + scitbx/lbfgsb/dev/SConscript | 2 +- scitbx/lbfgsb/raw.h | 6 +-- spotfinder/core_toolbox/libdistl.cpp | 2 +- 9 files changed, 54 insertions(+), 25 deletions(-) diff --git a/boost_adaptbx/SConscript b/boost_adaptbx/SConscript index 02670e92ff..4ad2aef819 100644 --- a/boost_adaptbx/SConscript +++ b/boost_adaptbx/SConscript @@ -227,6 +227,7 @@ e.g. with "yum install python-dev" or "apt-get install python-dev". env.SharedLibrary( target="#lib/boost_tuple_ext", source="tuple_ext.cpp") + env.Append(LIBS=['boost_timer']) env.SharedLibrary( target="#lib/boost_adaptbx_python_streambuf_test_ext", source="tests/python_streambuf_test_ext.cpp") @@ -356,7 +357,7 @@ e.g. with "yum install python-dev" or "apt-get install python-dev". source=boost_system_src) #Boost.Chrono? - if boost_thread_uses_winthreads: + if os.path.isdir(os.path.join(env_etc.boost_dist, 'boost', 'chrono')): env_boost_chrono = env_boost_thread_and_co.Clone() simple_darwin_shlinkcom(env_etc, env, 'chrono') boost_chrono_src = [ @@ -365,10 +366,37 @@ e.g. with "yum install python-dev" or "apt-get install python-dev". os.path.join(env_etc.boost_dist, 'libs', 'chrono', 'src', '*.cpp'))] # For Windows (c.f. point 2 above) env_boost_chrono.Append(CPPDEFINES={'BOOST_CHRONO_DYN_LINK':1}) - env_boost_chrono.StaticLibrary( - target='#lib/boost_chrono', - source=boost_chrono_src, - LIBS=['boost_system']) + if boost_thread_uses_winthreads: + env_boost_chrono.StaticLibrary( + target='#lib/boost_chrono', + source=boost_chrono_src, + LIBS=['boost_system']) + else: + env_boost_chrono.SharedLibrary( + target='#lib/boost_chrono', + source=boost_chrono_src, + LIBS=['boost_system']) + + #Boost.Timer? + if os.path.isdir(os.path.join(env_etc.boost_dist, 'boost', 'timer')): + env_boost_timer = env_boost_thread_and_co.Clone() + simple_darwin_shlinkcom(env_etc, env, 'timer') + boost_timer_src = [ + '#' + os.path.relpath(p, os.path.dirname(env_etc.boost_dist)) + for p in glob.glob( + os.path.join(env_etc.boost_dist, 'libs', 'timer', 'src', '*.cpp'))] + # For Windows (c.f. point 2 above) + env_boost_timer.Append(CPPDEFINES={'BOOST_TIMER_DYN_LINK':1}) + if boost_thread_uses_winthreads: + env_boost_timer.StaticLibrary( + target='#lib/boost_timer', + source=boost_timer_src, + LIBS=['boost_chrono']) + else: + env_boost_timer.SharedLibrary( + target='#lib/boost_timer', + source=boost_timer_src, + LIBS=['boost_chrono']) # Build a Python extension using Boost.Thread so as to test it works. # This also constitutes a nice real-life example of diff --git a/boost_adaptbx/tests/python_streambuf_test_ext.cpp b/boost_adaptbx/tests/python_streambuf_test_ext.cpp index dc4c493e29..dfbfdaaecb 100644 --- a/boost_adaptbx/tests/python_streambuf_test_ext.cpp +++ b/boost_adaptbx/tests/python_streambuf_test_ext.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include namespace boost_adaptbx { namespace python { namespace { @@ -104,14 +104,14 @@ namespace boost_adaptbx { namespace python { namespace { } void time_read(char const *path, streambuf& input) { - boost::timer t; + boost::timer::auto_cpu_timer t; streambuf::istream is(input); work_for_time_read(is); - double py_t = t.elapsed(); + double py_t = t.elapsed().wall; std::ifstream std_is(path); - t.restart(); + t.start(); work_for_time_read(std_is); - double py_cpp = t.elapsed(); + double py_cpp = t.elapsed().wall; std::cout << "- Reading -\nPython adaptor: " << py_t; std::cout << "\nPure C++: " << py_cpp; if (py_t > py_cpp) { @@ -121,14 +121,14 @@ namespace boost_adaptbx { namespace python { namespace { } void time_write(char const *path, streambuf& output) { - boost::timer t; + boost::timer::auto_cpu_timer t; streambuf::ostream os(output); work_for_time_write(os); - double py_t = t.elapsed(); + double py_t = t.elapsed().wall; std::ofstream std_os(path); - t.restart(); + t.start(); work_for_time_write(std_os); - double py_cpp = t.elapsed(); + double py_cpp = t.elapsed().wall; std::cout << "- Writing -\nPython adaptor: " << py_t; std::cout << "\nPure C++: " << py_cpp; if (py_t > py_cpp) { diff --git a/cbflib_adaptbx/detectors/cbf_adaptor.h b/cbflib_adaptbx/detectors/cbf_adaptor.h index d3eb28ca0b..8916cc3b4f 100644 --- a/cbflib_adaptbx/detectors/cbf_adaptor.h +++ b/cbflib_adaptbx/detectors/cbf_adaptor.h @@ -16,7 +16,6 @@ #define cbf_failnez(x) { int err; err = (x); if (err) { \ std::cout<<"error code "< namespace iotbx { namespace detectors { diff --git a/cctbx/math/SConscript b/cctbx/math/SConscript index f8ebf573c6..b8de9b2e4d 100644 --- a/cctbx/math/SConscript +++ b/cctbx/math/SConscript @@ -3,6 +3,7 @@ env = env_base.Clone( CXXFLAGS=env_etc.cxxflags_base, ) env.Prepend(LIBS=["cctbx"]) +env.Append(LIBS='boost_timer') env.Append(LIBS=env_etc.libm) env_etc.include_registry.append( env=env, diff --git a/cctbx/math/time_trigonometry.cpp b/cctbx/math/time_trigonometry.cpp index aa992455ec..67b92d4dd5 100644 --- a/cctbx/math/time_trigonometry.cpp +++ b/cctbx/math/time_trigonometry.cpp @@ -1,23 +1,23 @@ #include #include -#include +#include int main() { unsigned const n = 1024, p = 1024; cctbx::math::cos_sin_table table(n); cctbx::math::cos_sin_exact exact; std::complex sum = 0; - boost::timer t; + boost::timer::auto_cpu_timer t; for (unsigned i=0; i #include #include -#include +#include #include @@ -168,8 +168,8 @@ namespace raw { void timer(FloatType& ttime) { - static boost::timer timer_; - ttime = static_cast(timer_.elapsed()); + static boost::timer::auto_cpu_timer timer_; + ttime = 1.0e-9 * static_cast(timer_.elapsed().wall); } //! Emulation of write statement with implicit loop. diff --git a/spotfinder/core_toolbox/libdistl.cpp b/spotfinder/core_toolbox/libdistl.cpp index f34910c65a..d94cf66e3e 100644 --- a/spotfinder/core_toolbox/libdistl.cpp +++ b/spotfinder/core_toolbox/libdistl.cpp @@ -55,7 +55,7 @@ */ #include -//#include +//#include //#include #include // to implement std::stack fix for stack overflow, see search_border_spot