10#include <kernel/geometry/mesh_file_reader.hpp>
11#include <kernel/geometry/boundary_factory.hpp>
12#include <kernel/geometry/common_factories.hpp>
13#include <kernel/geometry/hit_test_factory.hpp>
15#include <control/domain/parti_domain_control_base.hpp>
34 args.
support(
"parti-type",
"<types...>\n"
35 "Specifies which partitioner types are allowed to be used.\n"
36 "May contain the following types:\n"
37 "2level extern genetic metis naive scotch zoltan"
39 args.
support(
"parti-extern-name",
"<names...>\n"
40 "Specifies the names of the allowed extern partitions."
42 args.
support(
"parti-rank-elems",
"<count>\n"
43 "Specifies the minimum number of elements per rank for a-posteriori partitioning."
45 args.
support(
"parti-genetic-time",
"<time-init> <time-mutate>\n"
46 "Specifies the time for initial distribution and mutation for the genetic partitioner."
61 template<
typename DomainLevel_>
69 using typename BaseClass::LevelType;
73 using typename BaseClass::MeshType;
86 static constexpr int shape_dim = MeshType::shape_dim;
149 auto it = args.
query(
"parti-extern-name");
173 auto parti_extern_name_p = pmap.
query(
"parti-extern-name");
174 if(parti_extern_name_p.second)
176 this->_extern_parti_names = parti_extern_name_p.first.split_by_whitespaces();
191 virtual void create(
const std::deque<String>& filenames,
String dirpath =
"")
200 this->
create(mesh_reader);
213 XASSERT(this->size_physical() == std::size_t(0));
214 XASSERT(this->size_virtual() == std::size_t(0));
234 virtual void create(std::unique_ptr<MeshNodeType> base_mesh_node)
239 this->
_create(std::move(base_mesh_node));
262 XASSERT(this->size_physical() == std::size_t(0));
263 XASSERT(this->size_virtual() == std::size_t(0));
274 base_mesh_node->add_mesh_part(
"bnd", bnd_factory.make_unique());
278 this->
create(std::move(base_mesh_node));
296 XASSERT(this->size_physical() == std::size_t(0));
297 XASSERT(this->size_virtual() == std::size_t(0));
308 base_mesh_node->add_mesh_part(
"bnd", bnd_factory.make_unique());
312 this->
create(std::move(base_mesh_node));
339 XASSERT(this->size_physical() == std::size_t(0));
340 XASSERT(this->size_virtual() == std::size_t(0));
352 auto hit = [tol](
auto p){
return p[0] < tol;};
354 base_mesh_node->add_mesh_part(
"bnd:l", factory.make_unique());
358 auto hit = [tol](
auto p){
return p[0] > (
CoordType(1)-tol);};
360 base_mesh_node->add_mesh_part(
"bnd:r", factory.make_unique());
366 auto hit = [tol](
auto p){
return p[1] < tol;};
368 base_mesh_node->add_mesh_part(
"bnd:b", factory.make_unique());
372 auto hit = [tol](
auto p){
return p[1] > (
CoordType(1)-tol);};
374 base_mesh_node->add_mesh_part(
"bnd:t", factory.make_unique());
381 auto hit = [tol](
auto p){
return p[2] < tol;};
383 base_mesh_node->add_mesh_part(
"bnd:f", factory.make_unique());
387 auto hit = [tol](
auto p){
return p[2] > (
CoordType(1)-tol);};
389 base_mesh_node->add_mesh_part(
"bnd:n", factory.make_unique());
395 auto& vtx = base_mesh_node->get_mesh()->get_vertex_set();
396 Index n = vtx.get_num_vertices();
397 for(
Index i(0); i < n; ++i)
399 vtx[i][0] = x_min + (x_max - x_min) * vtx[i][0];
401 vtx[i][1] = y_min + (y_max - y_min) * vtx[i][1];
403 vtx[i][2] = z_min + (z_max - z_min) * vtx[i][2];
407 this->
create(std::move(base_mesh_node));
421 XASSERTM(!this->
_was_created,
"This function has to be called before domain control creation!");
422 _permutation_strategy = strategy;
441 for(std::size_t i(0); i < this->size_physical(); ++i)
443 this->at(i)->get_mesh_node()->create_permutation(this->_permutation_strategy);
484 virtual void _create(std::unique_ptr<MeshNodeType> base_mesh_node)
488 XASSERT(this->size_physical() == std::size_t(0));
489 XASSERT(this->size_virtual() == std::size_t(0));
495 if(this->_comm.
size() == 1)
519 this->compile_virtual_levels();
542 this->push_layer(std::make_shared<LayerType>(this->_comm.
comm_dup(), 0));
553 for(; lvl < ancestor.desired_level_min; ++lvl)
556 base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
567 auto refined_node = base_mesh_node->refine_unique(this->
_adapt_mode);
570 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
573 base_mesh_node = std::move(refined_node);
580 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
586#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
597 std::shared_ptr<LayerType> layer = std::make_shared<LayerType>(this->_comm.
comm_dup(), 0);
598 this->push_layer(layer);
615 base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
621 XABORTM(
"Failed to find a suitable partitioning");
625 std::vector<int> neighbor_ranks;
626 std::unique_ptr<MeshNodeType> patch_mesh_node(
627 base_mesh_node->extract_patch(neighbor_ranks, ancestor.
parti_graph, this->_comm.rank()));
630 layer->set_neighbor_ranks(neighbor_ranks);
636 for(
int i(1); i < ancestor.
num_parts; ++i)
638 base_mesh_node->create_patch_meshpart(ancestor.
parti_graph, i);
643 for(; lvl < ancestor.desired_level_min; ++lvl)
646 patch_mesh_node = patch_mesh_node->refine_unique(this->
_adapt_mode);
650 base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
661 auto refined_node = patch_mesh_node->refine_unique(this->
_adapt_mode);
664 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(patch_mesh_node)));
667 patch_mesh_node = std::move(refined_node);
673 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
676 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
679 base_mesh_node = std::move(refined_base_mesh_node);
687 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(patch_mesh_node)));
691 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
712 XASSERTM(!keep_base || (this->
_ancestry.size() <= std::size_t(1)),
"cannot keep base levels for more than 2 domain layers (yet)");
719 std::unique_ptr<MeshNodeType> parent_mesh_node = std::move(base_mesh_node);
720 base_mesh_node.reset();
723 for(std::size_t slayer = this->
_ancestry.size(); slayer > std::size_t(0); )
726 const bool is_base_layer = (slayer == this->
_ancestry.size());
734 int parent_min_lvl = -1;
741 this->
_check_parti(ancestor, *parent_mesh_node, is_base_layer);
755 auto refined_node = parent_mesh_node->refine_unique(this->
_adapt_mode);
758 if((ancestor.
layer_p >= 0) && (parent_min_lvl >= 0) && (lvl >= parent_min_lvl))
760 this->push_level_front(ancestor.
layer_p, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
764 parent_mesh_node = std::move(refined_node);
770 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
773 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
776 base_mesh_node = std::move(refined_base_mesh_node);
783 XABORTM(
"Failed to find a suitable partitioning");
787 std::vector<int> neighbor_ranks;
788 std::unique_ptr<MeshNodeType> patch_mesh_node(
794 std::map<int,int> halo_map;
795 for(
auto& i : neighbor_ranks)
800 patch_mesh_node->rename_halos(halo_map);
804 if((ancestor.
layer_p >= 0) || (keep_base && is_base_layer))
807 for(
int i(1); i < ancestor.
num_parts; ++i)
809 parent_mesh_node->create_patch_meshpart(ancestor.
parti_graph, i);
824 for(; lvl < global_level_min; ++lvl)
827 std::unique_ptr<MeshNodeType> coarse_mesh_node(std::move(parent_mesh_node));
828 parent_mesh_node = coarse_mesh_node->refine_unique(this->
_adapt_mode);
831 if((ancestor.
layer_p >= 0) && (parent_min_lvl >= 0) && (lvl >= parent_min_lvl))
834 coarse_mesh_node->clear_patches();
835 this->push_level_front(ancestor.
layer_p, std::make_shared<LevelType>(lvl, std::move(coarse_mesh_node)));
839 patch_mesh_node = patch_mesh_node->refine_unique(this->
_adapt_mode);
845 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
848 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
851 base_mesh_node = std::move(refined_base_mesh_node);
859 if(ancestor.
layer >= 0)
862 this->_layers.at(std::size_t(ancestor.
layer))->set_neighbor_ranks(neighbor_ranks);
868 else if(parent_min_lvl < 0)
872 this->
_chosen_levels.push_front(std::make_pair(parent_min_lvl, 0));
878 if(keep_base && is_base_layer)
880 XASSERT(base_mesh_node.get() ==
nullptr);
881 base_mesh_node = parent_mesh_node->clone_unique();
887 this->push_level_front(ancestor.
layer_p, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
891 parent_mesh_node = std::move(patch_mesh_node);
899 for(; lvl < desired_level_max; ++lvl)
902 auto refined_node = parent_mesh_node->refine_unique(this->
_adapt_mode);
905 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
908 parent_mesh_node = std::move(refined_node);
914 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->
_adapt_mode);
917 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
920 base_mesh_node = std::move(refined_base_mesh_node);
925 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
932 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
985 if(!this->_allow_parti_extern)
1016 if(!this->_allow_parti_2level)
1023 if(!partitioner.success())
1029 ancestor.
parti_level = int(partitioner.parti_level());
1030 ancestor.
parti_graph = partitioner.build_elems_at_rank();
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Graph clone() const
Clones this graph.
bool _keep_base_levels
keep base-mesh levels on root process?
bool parti_apriori
specifies whether the chosen partitioning is an a-priori partitioning strategy
int desired_level_max
the desired minimum and maximum refinement levels for this layer
int parti_level
the refinement level on which the patch is to be partitioned
String parti_info
a string containing some information about the chosen partitioning
Adjacency::Graph parti_graph
this is the actual elements-at-rank partitioning graph
int progeny_group
Progeny group of this process.
int layer_p
the index of the parent layer or -1, if this process is not part of the parent layer
int layer
the index of the layer that this ancestor object belongs to
int num_parts
the number of partitions for each patch of the parent layer
int progeny_child
Which direct child this process belongs to in its progeny group.
Base-Class for Hierarchical Domain Control implementations.
virtual void _reset_parti_types()
Resets/disables all partitioner types.
std::deque< std::pair< int, int > > _desired_levels
desired level deque
std::deque< std::pair< int, int > > _chosen_levels
chosen level deque
virtual void _create_ancestry_scattered()
Creates the layers for a multi-layered domain control in a scattered fashion.
Real WeightType
weight type for partitioner element weights; always Real
std::deque< Ancestor > _ancestry
the partition ancestry deque
virtual bool parse_args(SimpleArgParser &args)
Parses the partitioner options from an argument parser.
Geometry::RootMeshNode< MeshType > MeshNodeType
our root mesh node type
virtual bool _parse_parti_type(const String &type)
Parses a partitioner type.
LevelType::PartType MeshPartType
our mesh-part type
virtual void _create_ancestry_single()
Creates the ancestry for a single layer (or a single process)
Geometry::AdaptMode _adapt_mode
the adapt mode for refinement
bool _was_created
specifies whether the domain control was already created
virtual bool parse_property_map(const PropertyMap &pmap)
Parses the partitioner options from a PropertyMap.
virtual bool _check_parti(Ancestor &ancestor, const MeshNodeType &mesh_node, bool is_base_layer)
Checks for an appropriate partitioning strategy.
bool _support_multi_layered
support multi-layered hierarchy?
virtual bool _apply_parti(Ancestor &ancestor, MeshNodeType &base_mesh_node)
Applies an a-posteriori partitioner.
virtual void _create_multi_layers_scattered()
Creates the layers for a multi-layered domain control in a scattered fashion.
virtual void _split_basemesh_halos(const Ancestor &ancestor, const MeshNodeType &base_mesh_node, MeshNodeType &patch_mesh_node, std::vector< int > &neighbor_ranks)
Splits the base-mesh halos and computes the inter-patch-mesh halos.
Recursively Partitioned Domain Control.
PartiDomainControl(const Dist::Comm &comm_, bool support_multi_layered)
Constructor.
bool _allow_parti_extern
allow extern partitioner?
virtual void _create(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a domain control from a base-mesh node.
virtual void create_rectilinear(Index num_elems_x, Index num_elems_y=0u, Index num_elems_z=0u)
Creates a domain control from a structured rectilinear base mesh.
virtual bool _parse_parti_type(const String &type) override
Parses a partitioner type.
virtual void _create_multi_layered(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a multi-layered mesh hierarchy.
Geometry::PermutationStrategy get_permutation_strategy() const
MeshType::CoordType CoordType
coordinate type
static constexpr int shape_dim
shape dimension
bool _allow_parti_2level
allow 2-level partitioner?
Geometry::PartitionSet _parti_set
the extern partition sets
Control::Domain::PartiDomainControlBase< DomainLevel_ > BaseClass
Our base class.
virtual void create_unit_hypercube(Index num_elems_x, Index num_elems_y=0u, Index num_elems_z=0u)
Creates a domain control from a structured rectilinear base mesh.
Geometry::PermutationStrategy _permutation_strategy
the permutation strategy for the mesh permutation
virtual void _create_single_process(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a single-layered mesh hierarchy for a single process.
virtual void _create_single_layered(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a single-layered mesh hierarchy.
virtual bool parse_args(SimpleArgParser &args) override
Parses the partitioner options from an argument parser.
bool _check_parti_2level(Ancestor &ancestor, const MeshNodeType &base_mesh_node)
Checks whether the 2-level partitioner can be applied.
virtual void create(Geometry::MeshFileReader &mesh_reader)
Creates a domain control from a MeshFileReader.
virtual void create(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a domain control from a base-mesh node.
virtual void create_mesh_permutations()
Creates the mesh permutations based on the chosen permutation strategy.
void set_permutation_strategy(Geometry::PermutationStrategy strategy)
Sets the permutation strategy for mesh permutation.
bool _check_parti_extern(Ancestor &ancestor)
Checks whether an extern partition is given.
virtual void create(const std::deque< String > &filenames, String dirpath="")
Creates a domain control from a list of filenames.
virtual void create_rectilinear(Index num_elems_x, CoordType x_min, CoordType x_max, Index num_elems_y=0u, CoordType y_min=CoordType(0), CoordType y_max=CoordType(0), Index num_elems_z=0u, CoordType z_min=CoordType(0), CoordType z_max=CoordType(0))
Creates a domain control from a structured rectilinear base mesh for specific size and add standard b...
std::deque< String > _extern_parti_names
required partition name for extern partitioning
virtual void _reset_parti_types() override
Resets/disables all partitioner types.
virtual bool _check_parti(Ancestor &ancestor, const MeshNodeType &mesh_node, bool is_base_layer) override
Checks for an appropriate partitioning strategy.
virtual bool parse_property_map(const PropertyMap &pmap) override
Parses the partitioner options from a PropertyMap.
virtual ~PartiDomainControl()
virtual destructor
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
int size() const
Returns the size of this communicator.
Comm comm_dup() const
Creates a copy of this communicator.
int rank() const
Returns the rank of this process in this communicator.
BoundaryFactory implementation.
Hit-Test Factory class template.
void add_mesh_files(const Dist::Comm &comm, const std::deque< String > &filenames, String dirpath="")
Adds a list of mesh files to the list of streams to be parsed.
void parse(MeshNodeLinker< RootMesh_ > &linker, RootMeshNode< RootMesh_ > &root_mesh_node, MeshAtlas< RootMesh_ > &mesh_atlas, PartitionSet *part_set=nullptr)
Parses the mesh file into a mesh node and a mesh atlas.
MeshType * get_mesh()
Returns the mesh of this node.
2-Level-Partitioner class template declaration
const Adjacency::Graph & get_patches() const
const Partition * find_partition(int size, const String &name="", int prio=0) const
Tries to find a suitable partition in the set.
static std::unique_ptr< RootMeshNode > make_unique(std::unique_ptr< MeshType > mesh, MeshAtlasType *atlas=nullptr)
Creates a new RootMeshNode on the heap and returns a unique pointer to it.
Structured unit-cube mesh factory.
Math Limits class template.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Simple argument parser implementation.
const std::pair< int, std::deque< String > > * query(const String &option) const
Query the parameters of an option.
void support(const String &option, const String &description=String())
Adds an option to the set of supported options.
static double toe_partition
time of partitioning in seconds, needs initialization
String class implementation.
int compare_no_case(const String &other) const
Compares two strings without regard to case.
double elapsed_now() const
Calculates the time elapsed between the time stamp and now.
void add_supported_pdc_args(SimpleArgParser &args)
Adds the supported arguments of the PartiDomainControl to an argument parser.
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
PermutationStrategy
Mesh permutation strategy enumeration.
@ none
no permutation strategy
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
std::uint64_t Index
Index data type.