SpECTRE Documentation Coverage Report
Current view: top level - Parallel/PhaseControl - ContributeToPhaseChangeReduction.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 66.7 % 3 2
Test Date: 2026-10-22 17:29:42
Legend: Lines:     hit not hit

            Line data    Source code
       1            0 : // Distributed under the MIT License.
       2              : // See LICENSE.txt for details.
       3              : 
       4              : #pragma once
       5              : 
       6              : #include <functional>
       7              : #include <optional>
       8              : #include <type_traits>
       9              : 
      10              : #include "DataStructures/TaggedTuple.hpp"
      11              : #include "Parallel/CharmRegistration.hpp"
      12              : #include "Parallel/GlobalCache.hpp"
      13              : #include "Parallel/Local.hpp"
      14              : #include "Parallel/PhaseControl/PhaseControlTags.hpp"
      15              : #include "Parallel/PhaseControlReductionHelpers.hpp"
      16              : 
      17              : #include "Parallel/Main.decl.h"
      18              : 
      19              : namespace Parallel {
      20              : /// @{
      21              : /// Send data from a parallel component to the Main chare for making
      22              : /// phase-change decisions.
      23              : ///
      24              : /// This function is distinct from `Parallel::contribute_to_reduction` because
      25              : /// this function contributes reduction data to the Main chare via the entry
      26              : /// method `phase_change_reduction`. This must be done because the entry method
      27              : /// must alter member data specific to the Main chare, and the Main chare cannot
      28              : /// execute actions like most SpECTRE parallel components.
      29              : /// For all cases other than sending phase-change decision data to the Main
      30              : /// chare, you should use `Parallel::contribute_to_reduction`.
      31              : template <typename SenderComponent, typename ArrayIndex, typename Metavariables,
      32              :           class... Ts>
      33            1 : void contribute_to_phase_change_reduction(
      34              :     tuples::TaggedTuple<Ts...> data_for_reduction,
      35              :     Parallel::GlobalCache<Metavariables>& cache,
      36              :     const ArrayIndex& array_index) {
      37              :   using phase_change_tags_and_combines_list =
      38              :       PhaseControl::get_phase_change_tags<Metavariables>;
      39              :   using reduction_data_type =
      40              :       PhaseControl::reduction_data<tmpl::list<Ts...>,
      41              :                                    phase_change_tags_and_combines_list>;
      42              :   (void)Parallel::charmxx::RegisterReducerFunction<
      43              :       reduction_data_type::combine>::registrar;
      44              :   CkCallback callback(CProxy_Main<Metavariables>::index_t::
      45              :                           template redn_wrapper_phase_change_reduction<
      46              :                               PhaseControl::TaggedTupleCombine, Ts...>(nullptr),
      47              :                       cache.get_main_proxy().value());
      48              :   reduction_data_type reduction_data{data_for_reduction};
      49              :   Parallel::local(
      50              :       Parallel::get_parallel_component<SenderComponent>(cache)[array_index])
      51              :       ->contribute(static_cast<int>(reduction_data.size()),
      52              :                    reduction_data.packed().get(),
      53              :                    Parallel::charmxx::charm_reducer_functions.at(
      54              :                        std::hash<Parallel::charmxx::ReducerFunctions>{}(
      55              :                            &reduction_data_type::combine)),
      56              :                    callback);
      57              : }
      58              : 
      59              : template <typename SenderComponent, typename Metavariables, class... Ts>
      60            1 : void contribute_to_phase_change_reduction(
      61              :     tuples::TaggedTuple<Ts...> data_for_reduction,
      62              :     Parallel::GlobalCache<Metavariables>& cache) {
      63              :   using phase_change_tags_and_combines_list =
      64              :       PhaseControl::get_phase_change_tags<Metavariables>;
      65              :   using reduction_data_type =
      66              :       PhaseControl::reduction_data<tmpl::list<Ts...>,
      67              :                                    phase_change_tags_and_combines_list>;
      68              :   (void)Parallel::charmxx::RegisterReducerFunction<
      69              :       reduction_data_type::combine>::registrar;
      70              :   CkCallback callback(CProxy_Main<Metavariables>::index_t::
      71              :                           template redn_wrapper_phase_change_reduction<
      72              :                               PhaseControl::TaggedTupleCombine, Ts...>(nullptr),
      73              :                       cache.get_main_proxy().value());
      74              :   reduction_data_type reduction_data{data_for_reduction};
      75              : 
      76              :   if constexpr (std::is_same_v<typename SenderComponent::chare_type,
      77              :                                Parallel::Algorithms::Singleton>) {
      78              :     Parallel::local(Parallel::get_parallel_component<SenderComponent>(cache))
      79              :         ->contribute(static_cast<int>(reduction_data.size()),
      80              :                      reduction_data.packed().get(),
      81              :                      Parallel::charmxx::charm_reducer_functions.at(
      82              :                          std::hash<Parallel::charmxx::ReducerFunctions>{}(
      83              :                              &reduction_data_type::combine)),
      84              :                      callback);
      85              : 
      86              :   } else {
      87              :     Parallel::local_branch(
      88              :         Parallel::get_parallel_component<SenderComponent>(cache))
      89              :         ->contribute(static_cast<int>(reduction_data.size()),
      90              :                      reduction_data.packed().get(),
      91              :                      Parallel::charmxx::charm_reducer_functions.at(
      92              :                          std::hash<Parallel::charmxx::ReducerFunctions>{}(
      93              :                              &reduction_data_type::combine)),
      94              :                      callback);
      95              :   }
      96              : }
      97              : /// @}
      98              : }  // namespace Parallel
        

Generated by: LCOV version 2.0-1