Skip to content

Commit

Permalink
Merge pull request sxs-collaboration#5647 from macedo22/bbh_compilati…
Browse files Browse the repository at this point in the history
…on_improvements_1

Reduce compilation memory of executables
  • Loading branch information
nilsvu authored Dec 7, 2023
2 parents 59fc369 + 3c03848 commit a26db87
Show file tree
Hide file tree
Showing 10 changed files with 487 additions and 235 deletions.
9 changes: 5 additions & 4 deletions src/DataStructures/DataBox/DataBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,11 @@ db::DataBox<tmpl::list<Tags...>>::reset_compute_items_after_mutate(
using current_tags_to_reset = tmpl::list<TagsOfImmutableItemsToReset...>;
using next_compute_tags_to_reset = tmpl::list_difference<
tmpl::remove_duplicates<tmpl::transform<
tmpl::append<
tmpl::filter<typename DataBox<tmpl::list<Tags...>>::edge_list,
std::is_same<tmpl::pin<TagsOfImmutableItemsToReset>,
tmpl::get_source<tmpl::_1>>>...>,
tmpl::filter<
typename DataBox<tmpl::list<Tags...>>::edge_list,
tmpl::lazy::list_contains<
tmpl::pin<tmpl::list<TagsOfImmutableItemsToReset...>>,
tmpl::get_source<tmpl::_1>>>,
tmpl::get_destination<tmpl::_1>>>,
current_tags_to_reset>;
reset_compute_items_after_mutate(next_compute_tags_to_reset{});
Expand Down
113 changes: 55 additions & 58 deletions src/Options/OptionsDetails.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,51 +190,49 @@ struct has_upper_bound_on_size<
S, std::void_t<decltype(std::declval<S>().upper_bound_on_size())>>
: std::true_type {};

template <typename OptionList>
struct print {
using value_type = std::string;
template <typename Tag>
void operator()(tmpl::type_<Tag> /*meta*/);
std::string indent{" "};
value_type value{};
};
template <typename Tag>
std::string print_tag(const std::string& indent) {
const std::string new_line = "\n" + indent + " ";
std::ostringstream ss;
ss << indent << pretty_type::name<Tag>() << ":" << new_line
<< "type=" << yaml_type<typename Tag::type>::value();
if constexpr (has_suggested<Tag>::value) {
if constexpr (tt::is_a_v<std::unique_ptr, typename Tag::type>) {
call_with_dynamic_type<
void, typename Tag::type::element_type::creatable_classes>(
Tag::suggested_value().get(), [&new_line, &ss](const auto* derived) {
ss << new_line << "suggested=" << std::boolalpha
<< pretty_type::short_name<decltype(*derived)>();
});
} else {
ss << new_line << "suggested="
<< (MakeString{} << std::boolalpha << Tag::suggested_value());
}
}
if constexpr (has_lower_bound<Tag>::value) {
ss << new_line << "min=" << (MakeString{} << Tag::lower_bound());
}
if constexpr (has_upper_bound<Tag>::value) {
ss << new_line << "max=" << (MakeString{} << Tag::upper_bound());
}
if constexpr (has_lower_bound_on_size<Tag>::value) {
ss << new_line << "min size=" << Tag::lower_bound_on_size();
}
if constexpr (has_upper_bound_on_size<Tag>::value) {
ss << new_line << "max size=" << Tag::upper_bound_on_size();
}
ss << "\n" << wrap_text(Tag::help, 77, indent + " ") << "\n\n";
return ss.str();
}

template <typename OptionList, typename TagsAndSubgroups>
struct print;

template <typename Tag, typename OptionList>
struct print_impl {
static std::string apply(const std::string& indent) {
if constexpr (tmpl::list_contains_v<OptionList, Tag>) {
const std::string new_line = "\n" + indent + " ";
std::ostringstream ss;
ss << indent << pretty_type::name<Tag>() << ":" << new_line
<< "type=" << yaml_type<typename Tag::type>::value();
if constexpr (has_suggested<Tag>::value) {
if constexpr (tt::is_a_v<std::unique_ptr, typename Tag::type>) {
call_with_dynamic_type<
void, typename Tag::type::element_type::creatable_classes>(
Tag::suggested_value().get(),
[&new_line, &ss](const auto* derived) {
ss << new_line << "suggested=" << std::boolalpha
<< pretty_type::short_name<decltype(*derived)>();
});
} else {
ss << new_line << "suggested="
<< (MakeString{} << std::boolalpha << Tag::suggested_value());
}
}
if constexpr (has_lower_bound<Tag>::value) {
ss << new_line << "min=" << (MakeString{} << Tag::lower_bound());
}
if constexpr (has_upper_bound<Tag>::value) {
ss << new_line << "max=" << (MakeString{} << Tag::upper_bound());
}
if constexpr (has_lower_bound_on_size<Tag>::value) {
ss << new_line << "min size=" << Tag::lower_bound_on_size();
}
if constexpr (has_upper_bound_on_size<Tag>::value) {
ss << new_line << "max size=" << Tag::upper_bound_on_size();
}
ss << "\n" << wrap_text(Tag::help, 77, indent + " ") << "\n\n";
return ss.str();
return print_tag<Tag>(indent);
} else {
// A group
std::ostringstream ss;
Expand All @@ -245,32 +243,31 @@ struct print_impl {
}
};

template <typename... Alternatives>
std::string print_alternatives(const std::string& header,
const std::string& indent) {
return (
indent + header + "\n" + ... +
(print<tmpl::list<Alternatives...>, Alternatives>::apply(indent + " ")));
}

template <typename FirstAlternative, typename... OtherAlternatives,
typename OptionList>
struct print_impl<Alternatives<FirstAlternative, OtherAlternatives...>,
OptionList> {
static std::string apply(const std::string& indent) {
std::ostringstream ss;
const auto print_alternatives = [&indent, &ss](const std::string& header,
auto alternatives) {
using AlternativeOptions = decltype(alternatives);
ss << indent << header << "\n"
<< tmpl::for_each<AlternativeOptions>(
print<AlternativeOptions>{indent + " "})
.value;
};

print_alternatives("EITHER", FirstAlternative{});
EXPAND_PACK_LEFT_TO_RIGHT(print_alternatives("OR", OtherAlternatives{}));
return ss.str();
return print_alternatives<FirstAlternative>("EITHER", indent) +
print_alternatives<OtherAlternatives...>("OR", indent);
}
};

template <typename OptionList>
template <typename Tag>
void print<OptionList>::operator()(tmpl::type_<Tag> /*meta*/) {
value += print_impl<Tag, OptionList>::apply(indent);
}
template <typename OptionList, typename... TagsAndSubgroups>
struct print<OptionList, tmpl::list<TagsAndSubgroups...>> {
static std::string apply(const std::string& indent) {
return ("" + ... +
(print_impl<TagsAndSubgroups, OptionList>::apply(indent)));
}
};

template <typename T, typename Metavariables>
struct CreateWrapper {
Expand Down
95 changes: 93 additions & 2 deletions src/Options/ParseOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@

#include "Options/ParseOptions.hpp"

#include <cstddef>
#include <exception>
#include <limits>
#include <ostream>
#include <string>
#include <unordered_set>
#include <vector>
#include <yaml-cpp/yaml.h>

#include "Informer/InfoFromBuild.hpp"
#include "Options/Context.hpp"
#include "Options/ParseError.hpp"
#include "Parallel/Printf.hpp"
#include "Utilities/Algorithm.hpp"
#include "Utilities/FileSystem.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeString.hpp"

namespace Options::detail {
namespace Options {
namespace detail {
namespace {
void check_metadata(const YAML::Node& metadata) {
// Validate executable name
Expand Down Expand Up @@ -63,4 +74,84 @@ YAML::Node load_and_check_yaml(const std::string& options,
std::to_string(yaml_docs.size()) + ".");
}
}
} // namespace Options::detail
} // namespace detail

namespace parse_detail {
std::unordered_set<std::string> get_given_options(
const Options::Context& context, const YAML::Node& node,
const std::string& help) {
if (not(node.IsMap() or node.IsNull())) {
PARSE_ERROR(context, "'" << node << "' does not look like options.\n"
<< help);
}

std::unordered_set<std::string> given_options{};
for (const auto& name_and_value : node) {
given_options.insert(name_and_value.first.as<std::string>());
}
return given_options;
}

void check_for_unique_choice(const std::vector<size_t>& alternative_choices,
const Options::Context& context,
const std::string& parsing_help) {
if (alg::any_of(alternative_choices, [](const size_t x) {
return x == std::numeric_limits<size_t>::max();
})) {
PARSE_ERROR(context, "Cannot decide between alternative options.\n"
<< parsing_help);
}
}

void add_name_to_valid_option_names(
const gsl::not_null<std::vector<std::string>*> valid_option_names,
const std::string& label) {
ASSERT(alg::find(*valid_option_names, label) == valid_option_names->end(),
"Duplicate option name: " << label);
valid_option_names->push_back(label);
}

[[noreturn]] void option_specified_twice_error(
const Options::Context& context, const std::string& name,
const std::string& parsing_help) {
PARSE_ERROR(context, "Option '" << name << "' specified twice.\n"
<< parsing_help);
}

[[noreturn]] void unused_key_error(const Context& context,
const std::string& name,
const std::string& parsing_help) {
PARSE_ERROR(context, "Option '"
<< name
<< "' is unused because of other provided options.\n"
<< parsing_help);
}

[[noreturn]] void option_invalid_error(const Options::Context& context,
const std::string& name,
const std::string& parsing_help) {
PARSE_ERROR(context, "Option '" << name << "' is not a valid option.\n"
<< parsing_help);
}

void check_for_missing_option(const std::vector<std::string>& valid_names,
const Options::Context& context,
const std::string& parsing_help) {
if (not valid_names.empty()) {
PARSE_ERROR(context, "You did not specify the option"
<< (valid_names.size() == 1 ? " " : "s ")
<< (MakeString{} << valid_names) << "\n"
<< parsing_help);
}
}

std::string add_group_prefix_to_name(const std::string& name) {
return "In group " + name;
}

void print_top_level_error_message() {
Parallel::printf_error(
"The following options differ from their suggested values:\n");
}
} // namespace parse_detail
} // namespace Options
Loading

0 comments on commit a26db87

Please sign in to comment.