Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
kidder committed Apr 1, 2024
1 parent 284175d commit 11514c8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/DataStructures/DataBox/DataBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,19 @@ std::map<std::string, size_t> DataBox<tmpl::list<Tags...>>::size_of_items()
(void)this;
using tag = tmpl::type_from<decltype(tag_v)>;
if constexpr (not db::is_reference_tag_v<tag>) {
const auto& item = get_item<tag>();
result[pretty_type::get_name<tag>()] = size_of_object_in_bytes(item);
// For item of ItemType::Compute, this will not evaluate its function
// (i.e. if the item has never been evaluated its size will be that of a
// default initialized object)
const auto& item = get_item<tag>().get();
if constexpr (tt::is_a_v<std::unique_ptr, typename tag::type>) {
if (item == nullptr) {
result[pretty_type::get_name<tag>()] = 0;
} else {
result[pretty_type::get_name<tag>()] = size_of_object_in_bytes(*item);
}
} else {
result[pretty_type::get_name<tag>()] = size_of_object_in_bytes(item);
}
}
};
tmpl::for_each<mutable_item_creation_tags>(add_item_size);
Expand Down
9 changes: 8 additions & 1 deletion src/ParallelAlgorithms/Events/ObserveDataBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ReduceDataBoxSize {
auto& observer_writer_proxy = Parallel::get_parallel_component<
observers::ObserverWriter<Metavariables>>(cache);
const std::string subfile_name =
"/ObserveDataBox/" + pretty_type::name<ContributingComponent>();
"/DataBoxSizeInMb/" + pretty_type::name<ContributingComponent>();
std::vector<std::string> legend;
legend.reserve(item_sizes.size() + 1);
legend.emplace_back("Time");
Expand Down Expand Up @@ -95,6 +95,13 @@ struct ContributeDataBoxSize {
};
} // namespace detail

/// \brief Event that will collect the size in MBs used by each DataBox item on
/// each parallel component.
///
/// \details The data will be written to disk in the reductions file under the
/// `/DataBoxSizeInMb/` group. The name of each file is the `pretty_type::name`
/// of each parallel component. There will be a column for each item in the
/// DataBox that is not a subitem or reference item.
class ObserveDataBox : public Event {
public:
/// \cond
Expand Down
31 changes: 29 additions & 2 deletions tests/Unit/DataStructures/DataBox/Test_DataBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3269,9 +3269,36 @@ void test_output() {
CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag1") == 32);
CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag2") == 24);
CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag4Compute") ==
9);
8);
CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag5Compute") ==
29);
28);

const auto box_with_ptrs =
db::create<db::AddSimpleTags<test_databox_tags::Pointer>,
db::AddComputeTags<test_databox_tags::PointerToCounterCompute,
test_databox_tags::PointerToSumCompute>>(
std::make_unique<int>(3));
const auto item_size_ptrs = box_with_ptrs.size_of_items();
CHECK(item_size_ptrs.size() == 3);
CHECK(item_size_ptrs.at(
"(anonymous namespace)::test_databox_tags::Pointer") == 4);
CHECK(item_size_ptrs.at(
"(anonymous "
"namespace)::test_databox_tags::PointerToCounterCompute") == 0);
CHECK(item_size_ptrs.at(
"(anonymous namespace)::test_databox_tags::PointerToSumCompute") ==
0);
db::get<test_databox_tags::PointerToSumCompute>(box_with_ptrs);
const auto item_size_ptrs_after = box_with_ptrs.size_of_items();
CHECK(item_size_ptrs_after.size() == 3);
CHECK(item_size_ptrs_after.at(
"(anonymous namespace)::test_databox_tags::Pointer") == 4);
CHECK(item_size_ptrs_after.at(
"(anonymous "
"namespace)::test_databox_tags::PointerToCounterCompute") == 4);
CHECK(item_size_ptrs_after.at(
"(anonymous namespace)::test_databox_tags::PointerToSumCompute") ==
4);
}

void test_exception_safety() {
Expand Down

0 comments on commit 11514c8

Please sign in to comment.