SpECTRE  v2026.04.01
Loading...
Searching...
No Matches
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.
CkSectionInfo & cookie ()
 The Charm++ section cookie that keeps track of reductions.

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
Parallel::Tags::Section<ArrayComponent, EvenOrOddTag>,
Parallel::Tags::Section<ArrayComponent, IsFirstElementTag>>;
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 =
// 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));
using EvenOrOddSection = Parallel::Section<ArrayComponent, EvenOrOddTag>;
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 =
Parallel::Section<ArrayComponent, IsFirstElementTag>;
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) {
initialization_items) = i % 2 == 0 ? even_section : odd_section;
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();
}
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:
  • src/Parallel/Section.hpp