Skip to content

Commit

Permalink
Fix bad size and optimization flags during archive creation
Browse files Browse the repository at this point in the history
The archive size only grows if the data is written into the container,
when chunks are added, we do not need to increment the size of the
archive itself.

This fixes a bug where the archive containter is allocated with a much
larger size than needed.
  • Loading branch information
biddisco committed Jun 6, 2017
1 parent 67870fc commit b94b8cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hpx/runtime/serialization/container.hpp
Expand Up @@ -31,7 +31,7 @@ namespace hpx { namespace serialization
naming::gid_type const & split_gid) = 0;
virtual void set_filter(binary_filter* filter) = 0;
virtual void save_binary(void const* address, std::size_t count) = 0;
virtual void save_binary_chunk(void const* address, std::size_t count) = 0;
virtual std::size_t save_binary_chunk(void const* address, std::size_t count) = 0;
virtual void reset() = 0;
virtual std::size_t get_num_chunks() const = 0;
virtual void flush() = 0;
Expand Down
12 changes: 8 additions & 4 deletions hpx/runtime/serialization/output_archive.hpp
Expand Up @@ -197,6 +197,7 @@ namespace hpx { namespace serialization

private:
friend struct basic_archive<output_archive>;

template <class T>
friend class array;

Expand Down Expand Up @@ -357,11 +358,14 @@ namespace hpx { namespace serialization
void save_binary_chunk(void const * address, std::size_t count)
{
if(count == 0) return;
size_ += count;
if (disable_data_chunking())
if (disable_data_chunking()) {
size_ += count;
buffer_->save_binary(address, count);
else
buffer_->save_binary_chunk(address, count);
}
else {
// the size might grow if optimizations are not used
size_ += buffer_->save_binary_chunk(address, count);
}
}

typedef std::map<const void *, std::uint64_t> pointer_tracker;
Expand Down
11 changes: 8 additions & 3 deletions hpx/runtime/serialization/output_container.hpp
Expand Up @@ -315,12 +315,14 @@ namespace hpx { namespace serialization
current_ = new_current;
}

void save_binary_chunk(void const* address, std::size_t count) // override
std::size_t save_binary_chunk(void const* address, std::size_t count) // override
{
if (count < HPX_ZERO_COPY_SERIALIZATION_THRESHOLD)
{
// fall back to serialization_chunk-less archive
this->output_container::save_binary(address, count);
// the container has grown by count bytes
return count;
}
else {
HPX_ASSERT(
Expand All @@ -339,6 +341,8 @@ namespace hpx { namespace serialization
// add a new serialization_chunk referring to the external
// buffer
chunker_.push_back(create_pointer_chunk(address, count));
// the container did not grow
return 0;
}
}

Expand Down Expand Up @@ -408,17 +412,18 @@ namespace hpx { namespace serialization
this->current_ += count;
}

void save_binary_chunk(void const* address, std::size_t count) // override
std::size_t save_binary_chunk(void const* address, std::size_t count) // override
{
if (count < HPX_ZERO_COPY_SERIALIZATION_THRESHOLD)
{
// fall back to serialization_chunk-less archive
HPX_ASSERT(count != 0);
filter_->save(address, count);
this->current_ += count;
return count;
}
else {
this->base_type::save_binary_chunk(address, count);
return this->base_type::save_binary_chunk(address, count);
}
}

Expand Down

0 comments on commit b94b8cf

Please sign in to comment.