hpx::collectives::create_hierarchical_communicator#
Defined in header hpx/collectives.hpp.
See Public API for a list of names and headers that are part of the public HPX API.
See also:
-
hierarchical_communicator hpx::collectives::create_hierarchical_communicator(char const *basename, num_sites_arg num_sites = num_sites_arg(), this_site_arg this_site = this_site_arg(), arity_arg arity = arity_arg(), generation_arg generation = generation_arg(), root_site_arg root_site = root_site_arg(), flat_fallback_threshold_arg threshold = flat_fallback_threshold_arg())#
Create a new hierarchical communicator object usable with collective operations
This functions creates a new hierarchical_communicator object that can be called in order to pre-allocate a communicator object usable with multiple invocations of a collective operation (such as all_gather, all_reduce, all_to_all, broadcast, etc.).
Note
The sub-communicators of a hierarchical_communicator share one generation sequence per registered name. Every hierarchical collective advances each sub-communicator it touches by exactly two internal generations per call (a single-pass collective such as broadcast, gather, scatter or reduce, and the inter-group exchange of all_to_all, skip the second generation in one step rather than performing a second round-trip). A single hierarchical_communicator instance may therefore be shared freely across collective operations, provided every call uses an explicit, strictly consecutive generation number so the shared sequence stays gap-free. Because the two-phase hierarchical collectives (all_gather, all_reduce, all_to_all, inclusive_scan, exclusive_scan and the hierarchical barrier) derive their phase generations from that explicit number, they require it and reject an auto (default) generation. The non-hierarchical (flat) collectives keep supporting the default generation, falling back to the internal per-communicator counter maintained in the and_gate. Once any operation on a communicator has used that default, later operations on the same instance may no longer pass an explicit generation number: the counter’s position is no longer reliably known to the caller. The reverse transition, from explicit numbering back to the default, remains valid. All participants of a single operation must use the same generation mode.
Note
Hierarchical collective overloads that return hpx::future may still perform internal waits while walking the communicator tree. They should not be treated as fully non-blocking: validation failures are reported through the returned exceptional future, but internal phase hand-offs can throw or block before that future is delivered.
- Parameters:
basename – The base name identifying the collective operation
num_sites – The number of participating sites (default: all localities).
this_site – The sequence number of this invocation (usually the locality id). This value is optional and defaults to whatever hpx::get_locality_id() returns.
arity – The arity of the hierarchical tree of communicators to create for the given endpoint. The default arity is 2 and the value must be at least 2.
generation – The generational counter identifying the sequence number of the collective operation performed on the given base name. This is optional and needs to be supplied only if the collective operation on the given base name has to be performed more than once.
root_site – The site at the root of the tree of communicators (default: 0). Any site may serve as the root. All sites must pass the same root site. The root site is the only site that may call the root-side operations (broadcast_to, gather_here, reduce_here, scatter_to). In the composite operations that take a root_site argument (all_gather, all_reduce, barrier, scans) it must be 0 (the default) or the root of the communicator; an explicit 0 is not checked.
threshold – The site-count threshold below which the communicator collapses to a single flat communicator spanning all sites (strict comparison: num_sites < threshold). The default is 16; pass 0 to disable the fallback and always build a tree.
- Throws:
hpx::exception – with hpx::error::bad_parameter if basename is null or empty, if the (resolved) num_sites is zero, if the (resolved) this_site is not smaller than num_sites, if the (resolved) root_site is not smaller than num_sites, or if arity is smaller than 2.
- Returns:
This function returns a new communicator object usable with the collective operation.