Skip to content

Commit 8bc097f

Browse files
committed
Use m_data_indices to store sizes of vector part
m_data_sizes turned out to be unnecessary since the information about size of every part of vector can be calculated from m_data_indices.
1 parent 374c8d5 commit 8bc097f

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

include/boost/compute/distributed/vector.hpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class vector
8989
m_allocators.back()
9090
.allocate(_minimum_capacity())
9191
);
92-
m_data_sizes.push_back(0);
9392
m_data_indices.push_back(0);
9493
}
94+
m_data_indices.push_back(0);
9595
}
9696

9797
/// Creates a distributed vector with space for \p count elements
@@ -303,7 +303,6 @@ class vector
303303
: m_queue(std::move(m_queue)),
304304
m_size(other.m_size),
305305
m_data(std::move(other.m_data)),
306-
m_data_sizes(std::move(other.m_data_sizes)),
307306
m_data_indices(std::move(other.m_data_indices)),
308307
m_allocators(std::move(other.m_allocators))
309308
{
@@ -315,14 +314,13 @@ class vector
315314
{
316315
if(m_size) {
317316
for(size_t i = 0; i < m_allocators.size(); i++) {
318-
m_allocators[i].deallocate(m_data[i], m_data_sizes[i]);
317+
m_allocators[i].deallocate(m_data[i], part_size(i));
319318
}
320319
}
321320

322321
m_queue = std::move(other.m_queue);
323322
m_size = other.m_size;
324323
m_data = std::move(other.m_data);
325-
m_data_sizes = std::move(other.m_data_sizes);
326324
m_data_indices = std::move(other.m_data_indices);
327325
m_allocators = std::move(other.m_allocators);
328326

@@ -337,7 +335,7 @@ class vector
337335
{
338336
if(m_size) {
339337
for(size_t i = 0; i < m_allocators.size(); i++) {
340-
m_allocators[i].deallocate(m_data[i], m_data_sizes[i]);
338+
m_allocators[i].deallocate(m_data[i], part_size(i));
341339
}
342340
}
343341
}
@@ -355,12 +353,16 @@ class vector
355353

356354
std::vector<size_type> parts_sizes() const
357355
{
358-
return m_data_sizes;
356+
std::vector<size_type> part_sizes(parts());
357+
for(size_t i = 0; i < parts(); i++) {
358+
part_sizes[i] = part_size(i);
359+
}
360+
return part_sizes;
359361
}
360362

361363
size_type part_size(size_t n) const
362364
{
363-
return m_data_sizes[n];
365+
return m_data_indices[n+1] - m_data_indices[n];
364366
}
365367

366368
std::vector<size_t> parts_starts() const
@@ -401,14 +403,14 @@ class vector
401403
iterator end(size_t n)
402404
{
403405
return ::boost::compute::make_buffer_iterator<T>(
404-
m_data[n].get_buffer(), m_data_sizes[n]
406+
m_data[n].get_buffer(), m_data_indices[n+1] - m_data_indices[n]
405407
);
406408
}
407409

408410
const_iterator end(size_t n) const
409411
{
410412
return ::boost::compute::make_buffer_iterator<T>(
411-
m_data[n].get_buffer(), m_data_sizes[n]
413+
m_data[n].get_buffer(), m_data_indices[n+1] - m_data_indices[n]
412414
);
413415
}
414416

@@ -507,7 +509,6 @@ class vector
507509
void swap(vector &other)
508510
{
509511
std::swap(m_data, other.m_data);
510-
std::swap(m_data_sizes, other.m_data_sizes);
511512
std::swap(m_data_indices, other.m_data_indices);
512513
std::swap(m_size, other.m_size);
513514
std::swap(m_allocators, other.m_allocators);
@@ -562,13 +563,11 @@ class vector
562563
{
563564
m_allocators.clear();
564565
m_data.clear();
565-
m_data_sizes.clear();
566566
m_data_indices.clear();
567567

568568
m_allocators.reserve(m_queue.size());
569569
m_data.reserve(m_queue.size());
570-
m_data_sizes.reserve(m_queue.size());
571-
m_data_indices.reserve(m_queue.size());
570+
m_data_indices.reserve(m_queue.size() + 1);
572571

573572
std::vector<size_t> partition =
574573
detail::partition(m_queue, weight, count, _align());
@@ -580,16 +579,15 @@ class vector
580579
m_allocators.back()
581580
.allocate((std::max)(data_size, _minimum_capacity()))
582581
);
583-
m_data_sizes.push_back(data_size);
584582
m_data_indices.push_back(partition[i]);
585583
}
584+
m_data_indices.push_back(partition[m_queue.size()]);
586585
}
587586

588587
private:
589588
command_queue m_queue;
590589
size_type m_size;
591590

592-
std::vector<size_type> m_data_sizes;
593591
std::vector<size_t> m_data_indices;
594592
std::vector<pointer> m_data;
595593
std::vector<allocator_type> m_allocators;

0 commit comments

Comments
 (0)