Skip to content

Commit 2ddfcf2

Browse files
committed
Remove huge section heuristic from input file
We now know which sections are legacy, so we do not communicate these to all ranks.
1 parent 6151fb1 commit 2ddfcf2

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/core/io/src/4C_io_input_file.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,6 @@ namespace Core::IO
321321

322322
namespace
323323
{
324-
/**
325-
* Sections that contain at least this number of entries are considered huge and are only
326-
* available on rank 0.
327-
*/
328-
constexpr std::size_t huge_section_threshold = 10'000;
329-
330324
//! The different ways we want to handle sections in the input file.
331325
enum class SectionType
332326
{
@@ -726,31 +720,28 @@ namespace Core::IO
726720
// Communicate the dat content
727721
if (Core::Communication::my_mpi_rank(pimpl_->comm_) == 0)
728722
{
729-
// Temporarily move the sections that are not huge into a separate map.
730-
std::unordered_map<std::string, Internal::SectionContent> non_huge_sections;
723+
// Temporarily move the sections that we want to broadcast into a separate map.
724+
std::unordered_map<std::string, Internal::SectionContent> non_legacy_sections;
731725

732726
for (auto&& [section_name, content] : pimpl_->content_by_section_)
733727
{
734-
if (std::holds_alternative<Internal::SectionContent::DatContent>(content.content))
728+
if (std::holds_alternative<Internal::SectionContent::DatContent>(content.content) &&
729+
!pimpl_->is_legacy_section(section_name))
735730
{
736-
if (content.as_dat().lines.size() < huge_section_threshold)
737-
{
738-
non_huge_sections[section_name] = std::move(content);
739-
}
731+
non_legacy_sections[section_name] = std::move(content);
740732
}
741733
}
742734

743-
Core::Communication::broadcast(non_huge_sections, 0, pimpl_->comm_);
735+
Core::Communication::broadcast(non_legacy_sections, 0, pimpl_->comm_);
744736

745-
// Move the non-huge sections back into the main map.
746-
for (auto&& [section_name, content] : non_huge_sections)
737+
for (auto&& [section_name, content] : non_legacy_sections)
747738
{
748739
pimpl_->content_by_section_[section_name] = std::move(content);
749740
}
750741
}
751742
else
752743
{
753-
// Other ranks receive the non-huge sections.
744+
// Other ranks receive the non-legacy sections.
754745
Core::Communication::broadcast(pimpl_->content_by_section_, 0, pimpl_->comm_);
755746
}
756747

@@ -760,7 +751,7 @@ namespace Core::IO
760751
{
761752
ryml::Tree tree_with_small_sections = init_yaml_tree_with_exceptions();
762753
tree_with_small_sections.rootref() |= ryml::MAP;
763-
// Go through the tree and drop the huge sections from the tree.
754+
// Go through the tree and drop the legacy sections from the tree.
764755
for (auto file_node : pimpl_->yaml_tree_.rootref())
765756
{
766757
auto new_file_node = tree_with_small_sections.rootref().append_child();
@@ -769,8 +760,7 @@ namespace Core::IO
769760

770761
for (auto section_node : file_node.children())
771762
{
772-
if (section_node.is_map() ||
773-
(section_node.is_seq() && section_node.num_children() < huge_section_threshold))
763+
if (!pimpl_->is_legacy_section(to_string(section_node.key())))
774764
{
775765
// Copy the node to the new tree.
776766
auto new_section_node = new_file_node.append_child();

src/core/io/src/4C_io_input_file.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ namespace Core::IO
8989
* @endcode
9090
*
9191
*
92-
* @note The file is only read on rank 0 to save memory. Sections that are huge are only
93-
* distributed to other ranks if they are accessed through line_in_section(). If you only
94-
* want to read a section on rank 0, use in_section_rank_0_only().
92+
* @note The file is only read on rank 0 to save memory. All sections are broadcast to all other
93+
* ranks, except for the legacy sections (see the constructor). Legacy sections need to be
94+
* consumed on rank 0 with the help of in_section_rank_0_only().
9595
*/
9696
class InputFile
9797
{

0 commit comments

Comments
 (0)