SpECTRE  v2024.04.12
Parallel::Section< ParallelComponent, SectionIdTag > Struct Template Reference

A subset of chares in a parallel component. More...

#include <Section.hpp>

Public Types

using parallel_component = ParallelComponent
 
using cproxy_section = typename charm_type::cproxy_section
 
using section_id_tag = SectionIdTag
 

Public Member Functions

 Section (IdType id, cproxy_section proxy)
 
 Section (Section &&rhs)=default
 
Sectionoperator= (Section &&rhs)=default
 
 Section (const Section &)=default
 
Sectionoperator= (const Section &)=default
 
const IdType & id () const
 The section ID corresponding to the SectionIdTag
 
void pup (PUP::er &p)
 
const cproxy_section & proxy () const
 The Charm++ section proxy.
 
cproxy_section & proxy ()
 The Charm++ section proxy.
 
const CkSectionInfo & cookie () const
 The Charm++ section cookie that keeps track of reductions. More...
 
CkSectionInfo & cookie ()
 The Charm++ section cookie that keeps track of reductions. More...
 

Detailed Description

template<typename ParallelComponent, typename SectionIdTag>
struct Parallel::Section< ParallelComponent, SectionIdTag >

A subset of chares in a parallel component.

The section is identified at compile time by the parallel component and a SectionIdTag. The SectionIdTag describes the quantity that partitions the chares into one or more sections. For example, the SectionIdTag could be the block ID in the computational domain, so elements are partitioned per block. Chares can be a member of multiple sections.

Here's an example how to work with sections in an array parallel component:

using array_allocation_tags = tmpl::list<
// The section proxy will be stored in each element's DataBox in this tag
// for convenient access
using simple_tags_from_options =
phase_dependent_action_list>>,
array_allocation_tags>;
static void allocate_array(
Parallel::CProxy_GlobalCache<Metavariables>& global_cache,
tuples::tagged_tuple_from_typelist<simple_tags_from_options>
initialization_items,
const tuples::tagged_tuple_from_typelist<array_allocation_tags>&
/*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<ArrayComponent>(local_cache);
// Create sections from element IDs (the corresponding elements will be
// created below)
const size_t num_elements = 5;
std::vector<CkArrayIndex> even_elements{};
std::vector<CkArrayIndex> odd_elements{};
for (size_t i = 0; i < num_elements; ++i) {
(i % 2 == 0 ? even_elements : odd_elements)
.push_back(Parallel::ArrayIndex<int>(static_cast<int>(i)));
}
std::vector<CkArrayIndex> first_element{};
first_element.push_back(Parallel::ArrayIndex<int>(0));
const EvenOrOddSection even_section{
EvenOrOdd::Even, EvenOrOddSection::cproxy_section::ckNew(
array_proxy.ckGetArrayID(), even_elements.data(),
even_elements.size())};
const EvenOrOddSection odd_section{
EvenOrOdd::Odd, EvenOrOddSection::cproxy_section::ckNew(
array_proxy.ckGetArrayID(), odd_elements.data(),
odd_elements.size())};
using IsFirstElementSection =
const IsFirstElementSection is_first_element_section{
true, IsFirstElementSection::cproxy_section::ckNew(
array_proxy.ckGetArrayID(), first_element.data(),
first_element.size())};
// Create array elements, copying the appropriate section proxy into their
// DataBox
const size_t number_of_procs = static_cast<size_t>(sys::number_of_procs());
size_t which_proc = 0;
for (size_t i = 0; i < 5; ++i) {
tuples::get<Parallel::Tags::Section<ArrayComponent, EvenOrOddTag>>(
initialization_items) = i % 2 == 0 ? even_section : odd_section;
tuples::get<Parallel::Tags::Section<ArrayComponent, IsFirstElementTag>>(
initialization_items) =
i == 0 ? std::make_optional(is_first_element_section) : std::nullopt;
while (procs_to_ignore.find(which_proc) != procs_to_ignore.end()) {
which_proc = which_proc + 1 == number_of_procs ? 0 : which_proc + 1;
}
array_proxy[static_cast<int>(i)].insert(global_cache,
initialization_items, which_proc);
which_proc = which_proc + 1 == number_of_procs ? 0 : which_proc + 1;
}
array_proxy.doneInserting();
}
CoordinateMap< SourceFrame, TargetFrame, Maps..., NewMap > push_back(CoordinateMap< SourceFrame, TargetFrame, Maps... > old_map, NewMap new_map)
Creates a CoordinateMap by appending the new map to the end of the old maps.
T number_of_procs(const DistribObject &distributed_object)
Number of processing elements.
Definition: Info.hpp:26
tmpl::remove_duplicates< tmpl::flatten< tmpl::transform< InitializationActionsList, detail::get_simple_tags_from_options_from_action< tmpl::_1 > > > > get_simple_tags_from_options
Given a list of initialization actions, returns a list of the unique simple_tags_from_options for all...
Definition: ParallelComponentHelpers.hpp:296
tmpl::flatten< tmpl::transform< PhaseDepActionList, detail::get_initialization_actions_list< tmpl::_1 > > > get_initialization_actions_list
Given the phase dependent action list, return the list of actions in the Initialization phase (or an ...
Definition: ParallelComponentHelpers.hpp:274
auto * local_branch(Proxy &&proxy)
Wrapper for calling Charm++'s .ckLocalBranch() on a proxy.
Definition: Local.hpp:48
The array index used for indexing Chare Arrays, mostly an implementation detail.
Definition: ArrayIndex.hpp:28
A subset of chares in a parallel component.
Definition: Section.hpp:36
The Parallel::Section<ParallelComponent, SectionIdTag> that this element belongs to.
Definition: Section.hpp:29
Warning
The Charm++ documentation indicates some creation order restrictions for sections that may become relevant if we encounter issues with race conditions in the future.

Member Function Documentation

◆ cookie() [1/2]

template<typename ParallelComponent , typename SectionIdTag >
CkSectionInfo & Parallel::Section< ParallelComponent, SectionIdTag >::cookie ( )
inline

The Charm++ section cookie that keeps track of reductions.

The section cookie must be stored on each element and updated when performing reductions. For details on Charm++ sections and section reductions see: https://charm.readthedocs.io/en/latest/charm++/manual.html?#sections-subsets-of-a-chare-array-group

◆ cookie() [2/2]

template<typename ParallelComponent , typename SectionIdTag >
const CkSectionInfo & Parallel::Section< ParallelComponent, SectionIdTag >::cookie ( ) const
inline

The Charm++ section cookie that keeps track of reductions.

The section cookie must be stored on each element and updated when performing reductions. For details on Charm++ sections and section reductions see: https://charm.readthedocs.io/en/latest/charm++/manual.html?#sections-subsets-of-a-chare-array-group


The documentation for this struct was generated from the following file: