Skip to content
Snippets Groups Projects
Unverified Commit cbd89b1e authored by Sam Yates's avatar Sam Yates Committed by GitHub
Browse files

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.
parent 59df0da0
No related branches found
No related tags found
No related merge requests found
...@@ -61,5 +61,6 @@ static inline bool operator<(cell_member_type lhs, const connection& rhs) { ...@@ -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) { static inline std::ostream& operator<<(std::ostream& o, arb::connection const& con) {
return o << "con [" << con.source() << " -> " << con.destination() return o << "con [" << con.source() << " -> " << con.destination()
<< " : weight " << con.weight() << " : weight " << con.weight()
<< ", delay " << con.delay() << "]"; << ", delay " << con.delay()
<< ", index " << con.index_on_domain() << "]";
} }
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
namespace arb { namespace arb {
void execution_context_deleter::operator()(execution_context* p) const {
delete p;
}
execution_context::execution_context(const proc_allocation& resources): execution_context::execution_context(const proc_allocation& resources):
distributed(make_local_context()), distributed(make_local_context()),
thread_pool(std::make_shared<threading::task_system>(resources.num_threads)), thread_pool(std::make_shared<threading::task_system>(resources.num_threads)),
...@@ -22,7 +26,7 @@ execution_context::execution_context(const proc_allocation& resources): ...@@ -22,7 +26,7 @@ execution_context::execution_context(const proc_allocation& resources):
{} {}
context make_context(const proc_allocation& p) { 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 #ifdef ARB_HAVE_MPI
...@@ -36,7 +40,7 @@ execution_context::execution_context(const proc_allocation& resources, MPI_Comm ...@@ -36,7 +40,7 @@ execution_context::execution_context(const proc_allocation& resources, MPI_Comm
template <> template <>
context make_context<MPI_Comm>(const proc_allocation& p, MPI_Comm comm) { 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 #endif
template <> template <>
...@@ -51,7 +55,7 @@ execution_context::execution_context( ...@@ -51,7 +55,7 @@ execution_context::execution_context(
template <> template <>
context make_context(const proc_allocation& p, dry_run_info d) { 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) { std::string distribution_type(const context& ctx) {
......
...@@ -49,7 +49,10 @@ struct execution_context; ...@@ -49,7 +49,10 @@ struct execution_context;
// //
// As execution_context is an incomplete type, an explicit deleter must be // As execution_context is an incomplete type, an explicit deleter must be
// provided. // 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. // Helpers for creating contexts. These are implemented in the back end.
......
...@@ -32,6 +32,6 @@ using spike = basic_spike<cell_member_type>; ...@@ -32,6 +32,6 @@ using spike = basic_spike<cell_member_type>;
// Custom stream operator for printing arb::spike<> values. // Custom stream operator for printing arb::spike<> values.
template <typename I> 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 << "]"; return o << "S[src " << s.source << ", t " << s.time << "]";
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment