Skip to content

Commit a9110c0

Browse files
committed
Final polish.
1 parent fb9f361 commit a9110c0

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

arbor/label_resolution.cpp

+6-15
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ namespace arb {
1717

1818
// cell_label_range methods
1919
cell_label_range::cell_label_range(std::vector<cell_size_type> size_vec,
20-
std::vector<cell_tag_type> label_vec,
20+
const std::vector<cell_tag_type>& label_vec,
2121
std::vector<lid_range> range_vec):
22-
sizes(std::move(size_vec)), ranges(std::move(range_vec))
23-
{
22+
sizes(std::move(size_vec)), ranges(std::move(range_vec)) {
2423
std::transform(label_vec.begin(), label_vec.end(),
2524
std::back_inserter(labels),
2625
hash_value<const std::string&>);
@@ -30,8 +29,7 @@ cell_label_range::cell_label_range(std::vector<cell_size_type> size_vec,
3029
cell_label_range::cell_label_range(std::vector<cell_size_type> size_vec,
3130
std::vector<hash_type> label_vec,
3231
std::vector<lid_range> range_vec):
33-
sizes(std::move(size_vec)), labels(std::move(label_vec)), ranges(std::move(range_vec))
34-
{
32+
sizes(std::move(size_vec)), labels(std::move(label_vec)), ranges(std::move(range_vec)) {
3533
arb_assert(check_invariant());
3634
};
3735

@@ -75,10 +73,11 @@ bool cell_labels_and_gids::check_invariant() const {
7573
/* The n-th local item (by index) to its identifier (lid). The lids are organised
7674
in potentially discontiguous ranges.
7775
78-
idx --------
76+
idx -------- len0 <= idx < len0 + len1
7977
\
8078
v
8179
| [s0, e0) [s1, e1), ... [sk, ek), ... |
80+
len0 len1
8281
*/
8382
cell_lid_type label_resolution_map::range_set::at(unsigned idx) const {
8483
if (0 == size) throw arbor_internal_error("no valid lids");
@@ -94,14 +93,6 @@ const label_resolution_map::range_set& label_resolution_map::at(cell_gid_type gi
9493
return map.at(std::make_pair(gid, hash));
9594
}
9695

97-
const label_resolution_map::range_set& label_resolution_map::at(cell_gid_type gid, const cell_tag_type& tag) const {
98-
return map.at(std::make_pair(gid, hash_value(tag)));
99-
}
100-
101-
std::size_t label_resolution_map::count(cell_gid_type gid, const cell_tag_type& tag) const {
102-
return map.count(std::make_pair(gid, hash_value(tag)));
103-
}
104-
10596
std::size_t label_resolution_map::count(cell_gid_type gid, hash_type hash) const {
10697
return map.count(std::make_pair(gid, hash));
10798
}
@@ -139,7 +130,7 @@ cell_lid_type resolver::resolve(cell_gid_type gid, const cell_local_label_type&
139130
auto hash = hash_value(tag);
140131
if (!label_map_->count(gid, hash)) throw arb::bad_connection_label(gid, tag, "label does not exist");
141132
const auto& range_set = label_map_->at(gid, hash);
142-
if (range_set.size < 1) throw arb::bad_connection_label(gid, tag, "no valid lids");
133+
if (range_set.size <= 0) throw arb::bad_connection_label(gid, tag, "no valid lids");
143134
auto idx = 0ul;
144135
if (pol == lid_selection_policy::assert_univalent) {
145136
// must have single-entry range_set

arbor/label_resolution.hpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ struct ARB_ARBOR_API cell_label_range {
2323
cell_label_range& operator=(const cell_label_range&) = default;
2424
cell_label_range& operator=(cell_label_range&&) = default;
2525

26-
cell_label_range(std::vector<cell_size_type> size_vec, std::vector<cell_tag_type> label_vec, std::vector<lid_range> rapfnge_vec);
27-
cell_label_range(std::vector<cell_size_type> size_vec, std::vector<hash_type> label_vec, std::vector<lid_range> range_vec);
26+
cell_label_range(std::vector<cell_size_type> size_vec,
27+
const std::vector<cell_tag_type>& label_vec,
28+
std::vector<lid_range> range_vec);
29+
cell_label_range(std::vector<cell_size_type> size_vec,
30+
std::vector<hash_type> label_vec,
31+
std::vector<lid_range> range_vec);
2832

2933
void add_cell();
3034

@@ -36,10 +40,8 @@ struct ARB_ARBOR_API cell_label_range {
3640

3741
// The number of labels associated with each cell.
3842
std::vector<cell_size_type> sizes;
39-
4043
// The labels corresponding to each cell, partitioned according to sizes_.
4144
std::vector<hash_type> labels;
42-
4345
// The lid_range corresponding to each label.
4446
std::vector<lid_range> ranges;
4547
};
@@ -60,20 +62,17 @@ struct ARB_ARBOR_API cell_labels_and_gids {
6062
// Class constructed from `cell_labels_and_ranges`:
6163
// Represents the information in the object in a more
6264
// structured manner for lid resolution in `resolver`
63-
class ARB_ARBOR_API label_resolution_map {
64-
public:
65+
struct ARB_ARBOR_API label_resolution_map {
6566
struct range_set {
66-
std::vector<lid_range> ranges;
6767
std::size_t size = 0;
68+
std::vector<lid_range> ranges;
6869
cell_lid_type at(unsigned idx) const;
6970
};
7071

7172
label_resolution_map() = default;
7273
explicit label_resolution_map(const cell_labels_and_gids&);
7374

74-
const range_set& at(cell_gid_type gid, const cell_tag_type& tag) const;
7575
const range_set& at(cell_gid_type gid, hash_type hash) const;
76-
std::size_t count(cell_gid_type gid, const cell_tag_type& tag) const;
7776
std::size_t count(cell_gid_type gid, hash_type hash) const;
7877

7978
private:

example/brunel/brunel.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ int main(int argc, char** argv) {
213213
unsigned num_threads = arbenv::default_concurrency();
214214
int gpu_id = arbenv::find_private_gpu(MPI_COMM_WORLD);
215215
auto context = arb::make_context(arb::proc_allocation{num_threads, gpu_id}, MPI_COMM_WORLD);
216-
root = arb::rank(context)==0;
216+
root = arb::rank(context) == 0;
217217
#else
218218
auto context = arb::make_context(arbenv::default_allocation());
219219
#endif
@@ -230,7 +230,10 @@ int main(int argc, char** argv) {
230230

231231
// read parameters
232232
auto o = read_options(argc, argv);
233-
if (!o) {return 0; }
233+
if (!o) {
234+
std::cerr << "Couldm't read options.\n";
235+
return -1;
236+
}
234237
cl_options options = o.value();
235238

236239
std::fstream spike_out;
@@ -279,9 +282,7 @@ int main(int argc, char** argv) {
279282
hints[cell_kind::cable].gpu_group_size = group_size;
280283
auto dec = partition_load_balance(recipe, context, hints);
281284

282-
simulation sim(recipe,
283-
context,
284-
dec);
285+
simulation sim(recipe, context, dec);
285286

286287
// Set up spike recording.
287288
std::vector<arb::spike> recorded_spikes;
@@ -356,10 +357,12 @@ void add_subset(cell_gid_type gid,
356357
std::vector<bool> seen(end - start, false);
357358
if (gid >= start && gid < end) seen[gid - start] = true;
358359
std::mt19937 gen(gid + 42);
360+
auto conn = arb::cell_connection{{0, src}, {tgt}, weight, delay*U::ms};
359361
while(m > 0) {
360362
cell_gid_type val = rand_range(gen, start, end);
361363
if (seen[val - start]) continue;
362-
conns.push_back({{val, src}, {tgt}, weight, delay*U::ms});
364+
conn.source.gid = val;
365+
conns.push_back(conn);
363366
seen[val - start] = true;
364367
m--;
365368
}

0 commit comments

Comments
 (0)