From cbd89b1ee69efe11e8cb95e8817d75b76b06eaa2 Mon Sep 17 00:00:00 2001 From: Sam Yates <halfflat@gmail.com> Date: Mon, 3 Feb 2020 11:54:10 +0100 Subject: [PATCH] Some API fixes/cleanup from PR #899 (#951) Split out from Alex's PR for quicker inclusion into master. * Supply `execution_context` deleter for `std::unique_ptr` via class, so that a function does not have to be supplied as an argument at construction. * Supply `arb::basic_spike` by const reference to `ostream` writer. * Add domain index to `connection` `ostream` writer. --- arbor/connection.hpp | 3 ++- arbor/execution_context.cpp | 10 +++++++--- arbor/include/arbor/context.hpp | 5 ++++- arbor/include/arbor/spike.hpp | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arbor/connection.hpp b/arbor/connection.hpp index cdcfe994..9ed342f8 100644 --- a/arbor/connection.hpp +++ b/arbor/connection.hpp @@ -61,5 +61,6 @@ static inline bool operator<(cell_member_type lhs, const connection& rhs) { static inline std::ostream& operator<<(std::ostream& o, arb::connection const& con) { return o << "con [" << con.source() << " -> " << con.destination() << " : weight " << con.weight() - << ", delay " << con.delay() << "]"; + << ", delay " << con.delay() + << ", index " << con.index_on_domain() << "]"; } diff --git a/arbor/execution_context.cpp b/arbor/execution_context.cpp index 2ef429f2..3e4cd629 100644 --- a/arbor/execution_context.cpp +++ b/arbor/execution_context.cpp @@ -14,6 +14,10 @@ namespace arb { +void execution_context_deleter::operator()(execution_context* p) const { + delete p; +} + execution_context::execution_context(const proc_allocation& resources): distributed(make_local_context()), thread_pool(std::make_shared<threading::task_system>(resources.num_threads)), @@ -22,7 +26,7 @@ execution_context::execution_context(const proc_allocation& resources): {} context make_context(const proc_allocation& p) { - return context(new execution_context(p), [](execution_context* p){delete p;}); + return context(new execution_context(p)); } #ifdef ARB_HAVE_MPI @@ -36,7 +40,7 @@ execution_context::execution_context(const proc_allocation& resources, MPI_Comm template <> context make_context<MPI_Comm>(const proc_allocation& p, MPI_Comm comm) { - return context(new execution_context(p, comm), [](execution_context* p){delete p;}); + return context(new execution_context(p, comm)); } #endif template <> @@ -51,7 +55,7 @@ execution_context::execution_context( template <> context make_context(const proc_allocation& p, dry_run_info d) { - return context(new execution_context(p, d), [](execution_context* p){delete p;}); + return context(new execution_context(p, d)); } std::string distribution_type(const context& ctx) { diff --git a/arbor/include/arbor/context.hpp b/arbor/include/arbor/context.hpp index b1210c3f..ff03b2e0 100644 --- a/arbor/include/arbor/context.hpp +++ b/arbor/include/arbor/context.hpp @@ -49,7 +49,10 @@ struct execution_context; // // As execution_context is an incomplete type, an explicit deleter must be // provided. -using context = std::unique_ptr<execution_context, void (*)(execution_context*)>; +struct execution_context_deleter { + void operator()(execution_context*) const; +}; +using context = std::unique_ptr<execution_context, execution_context_deleter>; // Helpers for creating contexts. These are implemented in the back end. diff --git a/arbor/include/arbor/spike.hpp b/arbor/include/arbor/spike.hpp index 4ae56ee0..69b1558e 100644 --- a/arbor/include/arbor/spike.hpp +++ b/arbor/include/arbor/spike.hpp @@ -32,6 +32,6 @@ using spike = basic_spike<cell_member_type>; // Custom stream operator for printing arb::spike<> values. template <typename I> -std::ostream& operator<<(std::ostream& o, arb::basic_spike<I> s) { +std::ostream& operator<<(std::ostream& o, arb::basic_spike<I> const& s) { return o << "S[src " << s.source << ", t " << s.time << "]"; } -- GitLab