Skip to content

Commit

Permalink
Merge pull request sxs-collaboration#5741 from kidder/fix_array_alloc…
Browse files Browse the repository at this point in the history
…ation_tags

Fix bug in using allocation_array_tags
  • Loading branch information
knelli2 authored Feb 7, 2024
2 parents 4f1d3f5 + 7b4b5db commit fd4fd2a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
26 changes: 17 additions & 9 deletions src/Parallel/Main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,6 @@ class Main : public CBase_Main<Metavariables> {
// current_termination_check_index_
void check_if_component_terminated_correctly();

template <typename ParallelComponent>
using parallel_component_options = Parallel::get_option_tags<
typename ParallelComponent::simple_tags_from_options, Metavariables>;
using option_list = tmpl::remove_duplicates<tmpl::flatten<tmpl::list<
Parallel::OptionTags::ResourceInfo<Metavariables>,
Parallel::get_option_tags<const_global_cache_tags, Metavariables>,
Parallel::get_option_tags<mutable_global_cache_tags, Metavariables>,
tmpl::transform<component_list,
tmpl::bind<parallel_component_options, tmpl::_1>>>>>;
// Lists of all parallel component types
using group_component_list =
tmpl::filter<component_list, tmpl::or_<Parallel::is_group<tmpl::_1>,
Expand All @@ -186,6 +177,23 @@ class Main : public CBase_Main<Metavariables> {
using singleton_component_list =
tmpl::filter<component_list, Parallel::is_singleton<tmpl::_1>>;

template <typename ParallelComponent>
using parallel_component_options = Parallel::get_option_tags<
typename ParallelComponent::simple_tags_from_options, Metavariables>;
template <typename ArrayComponent>
using array_component_allocation_options =
Parallel::get_option_tags<typename ArrayComponent::array_allocation_tags,
Metavariables>;
using option_list = tmpl::remove_duplicates<tmpl::flatten<tmpl::list<
Parallel::OptionTags::ResourceInfo<Metavariables>,
Parallel::get_option_tags<const_global_cache_tags, Metavariables>,
Parallel::get_option_tags<mutable_global_cache_tags, Metavariables>,
tmpl::transform<component_list,
tmpl::bind<parallel_component_options, tmpl::_1>>,
tmpl::transform<
all_array_component_list,
tmpl::bind<array_component_allocation_options, tmpl::_1>>>>>;

Parallel::Phase current_phase_{Parallel::Phase::Initialization};
CProxy_GlobalCache<Metavariables> global_cache_proxy_;
detail::CProxy_AtSyncIndicator<Metavariables> at_sync_indicator_proxy_;
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ add_algorithm_test(
from inside of an Action. This is only possible if the simple_action \
function is not invoked via a proxy, which we do not allow.")
add_algorithm_test("AlgorithmNodelock")
add_algorithm_test("AlgorithmParallel")
add_algorithm_test("AlgorithmParallel"
INPUT_FILE "Test_AlgorithmParallel.yaml")
add_algorithm_test("AlgorithmReduction")
add_algorithm_test("Callback")
add_algorithm_test("DetectHangArray"
Expand Down
26 changes: 22 additions & 4 deletions tests/Unit/Parallel/Test_AlgorithmParallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "DataStructures/DataBox/DataBox.hpp"
#include "DataStructures/DataBox/Tag.hpp"
#include "Helpers/Parallel/RoundRobinArrayElements.hpp"
#include "Options/String.hpp"
#include "Parallel/AlgorithmExecution.hpp"
#include "Parallel/Algorithms/AlgorithmArray.hpp"
#include "Parallel/Algorithms/AlgorithmGroup.hpp"
Expand Down Expand Up @@ -66,7 +67,22 @@ struct UnpackCounter {
};
} // namespace AlgorithmParallel_detail

namespace OptionTags {
struct NumberOfElements {
using type = int;
static constexpr Options::String help{"Number of elements"};
};
} // namespace OptionTags

namespace Tags {
struct NumberOfElements : db::SimpleTag {
using type = int;
using option_tags = tmpl::list<OptionTags::NumberOfElements>;
static constexpr bool pass_metavariables = false;
static int create_from_options(const int number_of_elements) {
return number_of_elements;
}
};
struct ReceiveArrayComponentsOnceMore : db::SimpleTag {
using type = bool;
};
Expand Down Expand Up @@ -535,21 +551,23 @@ struct ArrayParallelComponent {
tmpl::list<ArrayActions::CheckWasUnpacked>>>;
using simple_tags_from_options = Parallel::get_simple_tags_from_options<
Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
using array_allocation_tags = tmpl::list<>;
using array_allocation_tags = tmpl::list<Tags::NumberOfElements>;
using array_index = int;

static void allocate_array(
Parallel::CProxy_GlobalCache<Metavariables>& global_cache,
const tuples::tagged_tuple_from_typelist<simple_tags_from_options>&
/*initialization_items*/,
const tuples::tagged_tuple_from_typelist<array_allocation_tags>&
/*array_allocation_items*/
= {},
array_allocation_items,
const std::unordered_set<size_t>& procs_to_ignore = {}) {
auto& local_cache = *Parallel::local_branch(global_cache);
auto& array_proxy =
Parallel::get_parallel_component<ArrayParallelComponent>(local_cache);

// This corrects that parsing array_allocation_tags works correctly
const auto number_of_elements =
tuples::get<Tags::NumberOfElements>(array_allocation_items);
SPECTRE_PARALLEL_REQUIRE(number_of_elements == number_of_1d_array_elements);
TestHelpers::Parallel::assign_array_elements_round_robin_style(
array_proxy, static_cast<size_t>(number_of_1d_array_elements),
static_cast<size_t>(sys::number_of_procs()), {}, global_cache,
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Parallel/Test_AlgorithmParallel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Distributed under the MIT License.
# See LICENSE.txt for details.

---
---

NumberOfElements: 14

ResourceInfo:
AvoidGlobalProc0: false
Singletons: Auto

0 comments on commit fd4fd2a

Please sign in to comment.