FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
parti_domain_control_base.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
9
10#include <kernel/util/dist.hpp>
11#include <kernel/util/dist_file_io.hpp>
12#include <kernel/runtime.hpp>
13#include <kernel/util/simple_arg_parser.hpp>
14#include <kernel/util/property_map.hpp>
15#include <kernel/util/statistics.hpp>
16#include <kernel/geometry/mesh_node.hpp>
17#include <kernel/geometry/partition_set.hpp>
18#include <kernel/geometry/parti_2lvl.hpp>
19#include <kernel/geometry/parti_iterative.hpp>
20#include <kernel/geometry/parti_parmetis.hpp>
21#include <kernel/geometry/parti_zoltan.hpp>
22#include <kernel/geometry/parti_scotch.hpp>
23
24#include <control/domain/domain_control.hpp>
25
26namespace FEAT
27{
28 namespace Control
29 {
30 namespace Domain
31 {
41 template<typename DomainLevel_>
43 public Control::Domain::DomainControl<DomainLevel_>
44 {
45 public:
49 using typename BaseClass::LevelType;
51 using typename BaseClass::LayerType;
53 using typename BaseClass::MeshType;
55 using typename BaseClass::AtlasType;
59 typedef typename LevelType::PartType MeshPartType;
60
63
68 {
69 public:
71 int layer;
79 int desired_level_max, desired_level_min;
80
83
92
97
106
117
118 Ancestor() :
119 layer(0), layer_p(0), num_procs(0), num_parts(0),
120 desired_level_max(0), desired_level_min(0),
123 progeny_comm(),
124 parti_found(false),
125 parti_info(),
126 parti_level(0),
127 parti_apriori(false),
129 {
130 }
131 }; // class Ancestor
132
133 protected:
138
149
152
154 std::deque<std::pair<int,int>> _desired_levels;
155
157 std::deque<std::pair<int,int>> _chosen_levels;
158
165
167 std::deque<Ancestor> _ancestry;
168
169 public:
179 explicit PartiDomainControlBase(const Dist::Comm& comm_, bool support_multi_layered) :
180 BaseClass(comm_),
181 _was_created(false),
182 _adapt_mode(Geometry::AdaptMode::chart),
183 _allow_parti_metis(false),
184 _allow_parti_genetic(false), // this one is exotic
185 _allow_parti_naive(true),
186 _allow_parti_zoltan(false),
187 _allow_parti_scotch(false),
188 _support_multi_layered(support_multi_layered),
193 _ancestry()
194 {
195 }
196
199 {
200 }
201
214 virtual bool parse_args(SimpleArgParser& args)
215 {
216 XASSERTM(!_was_created, "This function has to be called before domain control creation!");
217 // Try to parse --parti-type <types...>
218 {
219 auto it = args.query("parti-type");
220 if(it != nullptr)
221 {
222 // disallow all strategies by default
223 this->_reset_parti_types();
224
225 // loop over all allowed strategies
226 for(const auto& t : it->second)
227 {
228 // give derived classes a chance first
229 if(!this->_parse_parti_type(t))
230 {
231 this->_comm.print("ERROR: unknown partitioner type '" + t + "'");
232 return false;
233 }
234 }
235 }
236 }
237
238 // parse --parti-rank-elems <count>
239 args.parse("parti-rank-elems", _required_elems_per_rank);
240
241 // parse --parti-genetic-time <time-init> <time-mutate>
242 args.parse("parti-genetic-time", _genetic_time_init, _genetic_time_mutate);
243
244 // okay
245 return true;
246 }
247
258 virtual bool parse_property_map(const PropertyMap& pmap)
259 {
260 XASSERTM(!_was_created, "This function has to be called before domain control creation!");
261 auto parti_type_p = pmap.query("parti-type");
262 if(parti_type_p.second)
263 {
264 // disallow all strategies by default
265 this->_reset_parti_types();
266
267 std::deque<String> allowed_partitioners = parti_type_p.first.split_by_whitespaces();
268
269 for(const auto& t : allowed_partitioners)
270 {
271 if(!this->_parse_parti_type(t))
272 {
273 this->_comm.print("ERROR: unknown partitioner type '" + t + "'");
274 return false;
275 }
276 }
277 }
278
279 auto parti_rank_elems_p = pmap.query("parti-rank-elems");
280 if(parti_rank_elems_p.second)
281 {
282 if(!parti_rank_elems_p.first.parse(_required_elems_per_rank))
283 {
284 this->_comm.print("ERROR: Failed to parse 'parti-rank-elems'");
285 return false;
286 }
287 }
288
289 auto genetic_time_init_p = pmap.query("parti-genetic-time-init");
290 if(genetic_time_init_p.second)
291 {
292 if(!genetic_time_init_p.first.parse(_genetic_time_init))
293 {
294 this->_comm.print("ERROR: Failed to parse 'parti-genetic-time-init'");
295 return false;
296 }
297 }
298
299 auto genetic_time_mutate_p = pmap.query("parti-genetic-time-mutate");
300 if(genetic_time_mutate_p.second)
301 {
302 if(!genetic_time_mutate_p.first.parse(_genetic_time_mutate))
303 {
304 this->_comm.print("ERROR: Failed to parse 'parti-genetic-time-mutate'");
305 return false;
306 }
307 }
308
309 return true;
310 }
311
319 {
320 XASSERTM(!_was_created, "This function has to be called before domain control creation!");
321 _adapt_mode = adapt_mode;
322 }
323
331 {
332 return _adapt_mode;
333 }
334
341 void set_desired_levels(const String& slvls)
342 {
343 std::deque<String> sl = slvls.split_by_whitespaces();
345 }
346
355 virtual void set_desired_levels(const std::deque<String>& slvls)
356 {
357 XASSERTM(!_was_created, "This function has to be called before domain control creation!");
358
359 const int nranks = this->_comm.size();
360 std::deque<String> sv;
361
362 for(std::size_t i(0); i < slvls.size(); ++i)
363 {
364 int ilvl = -1, nprocs = -1;
365 sv = slvls.at(i).split_by_string(":");
366
367 if((sv.size() < std::size_t(1)) || (sv.size() > std::size_t(2)))
368 throw ParseError("Invalid input format", slvls.at(i), "an int-pair 'level:patches'");
369
370 if(!sv.front().parse(ilvl))
371 throw ParseError("Failed to parse level index", slvls.at(i), "an integer");
372 if((sv.size() > std::size_t(1)) && !sv.back().parse(nprocs))
373 throw ParseError("Failed to parse process count" , slvls.at(i), "an integer");
374
375 // level must be non-negative
376 if(ilvl < 0)
377 throw ParseError("Invalid negative level index", slvls.at(i), "a non-negative level index");
378
379 // first level index?
380 if(i == std::size_t(0))
381 {
382 // if the process count is given, it must match the communicator size
383 if((nprocs >= 0) && (nprocs != this->_comm.size()))
384 throw ParseError("Invalid number of processes for global level: '" + slvls.at(i) +
385 "', expected " + stringify(this->_comm.size()) + " but got " + stringify(nprocs));
386 _desired_levels.push_back(std::make_pair(ilvl, nranks));
387 continue;
388 }
389
390 // make sure the level parameter is non-ascending
391 if(_desired_levels.back().first < ilvl)
392 throw ParseError("Invalid non-descending level index: '" + slvls.at(i) +
393 "', expected <= " + stringify(_desired_levels.back().first) + " but got " + stringify(ilvl));
394
395 // ignore process count for last level
396 if((i + 1) == slvls.size())
397 nprocs = 0;
398 // if the number of processes is identical to the previous one, simply ignore this parameter
399 else if(_desired_levels.back().second == nprocs)
400 continue;
401 // the process count must not be ascending
402 else if(_desired_levels.back().second < nprocs)
403 throw ParseError("Invalid non-descending process count: '" + slvls.at(i) +
404 "', expected < " + stringify(_desired_levels.back().second) + " but got " + stringify(nprocs));
405 // the previous process count must be a multiple of the new one
406 else if(_desired_levels.back().second % nprocs != 0)
407 throw ParseError("Invalid indivisible process count: '" + slvls.at(i) +
408 "', expected a divisor of " + stringify(_desired_levels.back().second) + " but got " + stringify(nprocs));
409
410 // push the level-proc pair
411 _desired_levels.push_back(std::make_pair(ilvl, nprocs));
412 }
413 }
414
425 virtual void set_desired_levels(int lvl_max, int lvl_min = -1)
426 {
427 XASSERTM(!_was_created, "This function has to be called before domain control creation!");
428
429 // single-layered hierarchy
430 int _desired_level_max = lvl_max;
431 int _desired_level_min = (lvl_min >= 0 ? lvl_min : lvl_max + lvl_min + 1);
432
433 XASSERTM(_desired_level_max >= 0, "Invalid level-max");
434 XASSERTM(_desired_level_min >= 0, "Invalid level-min");
435 XASSERTM(_desired_level_max >= _desired_level_min, "Invalid level-min/max combination");
436
437 _desired_levels.emplace_back(std::make_pair(_desired_level_max, this->_comm.size()));
438 _desired_levels.emplace_back(std::make_pair(_desired_level_min, 0));
439 }
440
455 virtual void set_desired_levels(int lvl_max, int lvl_med, int lvl_min)
456 {
457 XASSERTM(!_was_created, "This function has to be called before domain control creation!");
458
459 // double-layered hierarchy
460 int _desired_level_max = lvl_max;
461 int _desired_level_med = (lvl_med >= 0 ? lvl_med : lvl_max + lvl_med + 1);
462 int _desired_level_min = (lvl_min >= 0 ? lvl_min : lvl_med + lvl_min + 1);
463
464 XASSERTM(_desired_level_max >= 0, "Invalid level-max");
465 XASSERTM(_desired_level_med >= 0, "Invalid level-med");
466 XASSERTM(_desired_level_min >= 0, "Invalid level-min");
467
468 // level_max must be strictly greater than level_med
469 XASSERTM(_desired_level_max > _desired_level_med, "Invalid level-max/med combination");
470
471 // level_med must be greater or equal level_min
472 XASSERTM(_desired_level_med >= _desired_level_min, "Invalid level-med/min combination");
473
474 _desired_levels.emplace_back(std::make_pair(_desired_level_max, this->_comm.size()));
475 _desired_levels.emplace_back(std::make_pair(_desired_level_med, 1));
476 _desired_levels.emplace_back(std::make_pair(_desired_level_min, 0));
477 }
478
485 {
486 return _desired_levels.front().first;
487 }
488
495 {
496 return _desired_levels.back().first;
497 }
498
507 {
508 String s;
509 for(std::size_t i(0); (i + 1) < _desired_levels.size(); ++i)
510 {
511 s += stringify(_desired_levels.at(i).first);
512 s += ":";
513 s += stringify(_desired_levels.at(i).second);
514 s += " ";
515 }
516 s += stringify(_desired_levels.back().first);
517 return s;
518 }
519
528 {
529 String s;
530 for(std::size_t i(0); (i + 1) < _chosen_levels.size(); ++i)
531 {
532 s += stringify(_chosen_levels.at(i).first);
533 s += ":";
534 s += stringify(_chosen_levels.at(i).second);
535 s += " ";
536 }
537 s += stringify(_chosen_levels.back().first);
538 return s;
539 }
540
554 {
555 String s;
556
557 for(auto it = this->_ancestry.rbegin(); it != this->_ancestry.rend(); ++it)
558 {
559 if(it != this->_ancestry.rbegin())
560 s += "\n";
561 s += it->parti_info;
562 s += " on level ";
563 s += stringify(it->parti_level);
564 s += " for ";
565 s += stringify(it->num_parts);
566 s += (it->num_parts > 1 ? " patches on " : " patch on ");
567 s += stringify(it->num_procs);
568 s += (it->num_procs > 1 ? " processes" : " process");
569 }
570
571 return s;
572 }
573
579 const std::deque<std::pair<int, int>> get_desired_levels() const
580 {
581 return this->_desired_levels;
582 }
583
589 const std::deque<std::pair<int, int>> get_chosen_levels() const
590 {
591 return this->_chosen_levels;
592 }
593
598 {
599 String s;
600 for(auto it = this->_ancestry.begin(); it != this->_ancestry.end(); ++it)
601 {
602 if(it != this->_ancestry.begin())
603 s += " | ";
604 s += stringify((*it).num_procs);
605 s += ":";
606 s += stringify((*it).num_parts);
607 s += "[";
608 s += stringify((*it).progeny_group).pad_front(2);
609 s += "+";
610 s += stringify((*it).progeny_child);
611 s += ":";
612 s += stringify((*it).progeny_first).pad_front(2);
613 s += "+";
614 s += stringify((*it).progeny_count);
615 s += ".";
616 s += stringify((*it).progeny_comm.rank());
617 s += "]";
618 s += "(";
619 s += stringify((*it).desired_level_max);
620 s += ":";
621 s += stringify((*it).desired_level_min);
622 s += ")";
623 s += ((*it).layer >= 0 ? "*" : " ");
624 s += ((*it).layer_p >= 0 ? ">" : " ");
625 }
626 return s;
627 }
628
632 const std::deque<Ancestor>& get_ancestry() const
633 {
634 return this->_ancestry;
635 }
636
640 std::vector<char> serialize_partitioning() const
641 {
642 BinaryStream bs;
643 typedef std::uint64_t u64;
644
645 // serialization magic number: "F3PaDoCo"
646 const std::uint64_t magic = 0x6F436F4461503346;
647
648 XASSERT(this->_num_global_layers >= this->_ancestry.size());
649
650 if(this->_comm.rank() == 0)
651 {
652 // dump magic
653 bs.write((const char*)&magic, 8u);
654
655 // write finest level
656 const u64 lev = u64(this->_virt_levels.front()->get_level_index());
657 bs.write((const char*)&lev, 8u);
658
659 // serialize ancestry/layers
660 const u64 na = u64(this->_ancestry.size());
661 bs.write((const char*)&na, 8u);
662
663 // write number of ranks per layer in reverse order
664 for(auto it = this->_ancestry.rbegin(); it != this->_ancestry.rend(); ++it)
665 {
666 // write ranks
667 const u64 np = u64(it->num_procs);
668 const u64 pl = u64(it->parti_level);
669 bs.write((const char*)&np, 8u);
670 bs.write((const char*)&pl, 8u);
671 }
672 }
673
674 // loop over all ancestry graphs
675 for(auto it = this->_ancestry.rbegin(); it != this->_ancestry.rend(); ++it)
676 {
677 if(it == this->_ancestry.rbegin())
678 {
679 std::vector<char> buf = it->parti_graph.serialize();
680 bs.write(buf.data(), std::streamsize(buf.size()));
681 continue;
682 }
683
684 // get layer index
685 if(it->layer_p < 0)
686 continue;
687
688 // get parent layer communicator
689 const std::size_t ilp = std::size_t(it->layer_p);
690 XASSERT(ilp < this->_layers.size());
691 const Dist::Comm& comm_p = this->_layers.at(ilp)->comm();
692
693 // serialize graph
694 std::vector<char> buf = it->parti_graph.serialize();
695
696 // choose maximum size
697 u64 buf_size = buf.size();
698
699 // gather individual buffer sizes on rank 0
700 std::vector<u64> all_sizes;
701 if(comm_p.rank() == 0)
702 all_sizes.resize(std::size_t(comm_p.size()));
703 comm_p.gather(&buf_size, 1u, all_sizes.data(), 1u, 0);
704
705 // allreduce maximum size
706 comm_p.allreduce(&buf_size, &buf_size, std::size_t(1), Dist::op_max);
707
708 // adjust buffer size
709 if(buf_size > u64(buf.size()))
710 buf.resize(buf_size);
711
712 // on rank 0, allocate common buffer
713 std::vector<char> com_buf;
714 if(comm_p.rank() == 0)
715 com_buf.resize(std::size_t(buf_size * u64(comm_p.size())));
716
717 // gather all buffers on rank 0
718 comm_p.gather(buf.data(), buf_size, com_buf.data(), buf_size, 0);
719
720 // write each individual buffer
721 if(comm_p.rank() == 0)
722 {
723 char* x = com_buf.data();
724 for(u64 k(0); k < u64(comm_p.size()); ++k)
725 bs.write(&x[k*buf_size], std::streamsize(all_sizes[k]));
726 }
727 }
728
729 return bs.container();
730 }
731
732 protected:
739 virtual void _reset_parti_types()
740 {
743 _allow_parti_scotch = false;
744 }
745
754 virtual bool _parse_parti_type(const String& type)
755 {
756 if((type.compare_no_case("metis") == 0) || (type.compare_no_case("parmetis") == 0))
757 return _allow_parti_metis = true;
758 else if(type.compare_no_case("genetic") == 0)
759 return _allow_parti_genetic = true;
760 else if(type.compare_no_case("naive") == 0)
761 return _allow_parti_naive = true;
762 else if(type.compare_no_case("zoltan") == 0)
763 return _allow_parti_zoltan = true;
764 else if((type.compare_no_case("scotch") == 0) || (type.compare_no_case("ptscotch") == 0))
765 return _allow_parti_scotch = true;
766 else
767 return false;
768 }
769
780 virtual std::vector<WeightType> _compute_weights(Ancestor& DOXY(ancestor), const MeshNodeType& DOXY(base_mesh_node))
781 {
782 return std::vector<WeightType>();
783 }
784
789 {
790 // for more than 2 desired levels, call _create_ancestry_scattered
791 XASSERTM(this->_desired_levels.size() <= std::size_t(2), "multi-layered control is desired here");
792
793 // allocate and create ancestry
794 this->_ancestry.resize(std::size_t(1));
795 Ancestor& ancestor = this->_ancestry.front();
796
797 // set the layer index to 0
798 ancestor.layer = 0;
799
800 // set the parent layer index to -1
801 ancestor.layer_p = -1;
802
803 // set the total number of processes for this layer
804 ancestor.num_procs = this->_comm.size();
805
806 // set the total number of partitions per progeny group
807 ancestor.num_parts = this->_comm.size();
808
809 // set desired maximum level
810 ancestor.desired_level_max = this->_desired_levels.front().first;
811
812 // set desired minimum level (may be = level_max)
813 ancestor.desired_level_min = this->_desired_levels.back().first;
814
815 // set the progeny group
816 ancestor.progeny_group = 0;
817 ancestor.progeny_child = this->_comm.rank();
818
819 // create the progeny communicator
820 ancestor.progeny_count = this->_comm.size();
821 ancestor.progeny_first = 0;
822 ancestor.progeny_comm = this->_comm.comm_dup();
823 }
824
825 // Note: all following member functions are only required for parallel builds,
826 // so we enclose them in the following #if-block to reduce compile times.
827
828#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
829
834 {
835 // create and push global layer
836 this->push_layer(std::make_shared<LayerType>(this->_comm.comm_dup(), 0));
837
838 // loop over all desired layers
839 for(std::size_t ilay(1u); (ilay+1u) < this->_desired_levels.size(); ++ilay)
840 {
841 // get child layer
842 std::shared_ptr<LayerType> layer_c = this->_layers.back();
843
844 // get child layer communicator
845 const Dist::Comm& comm_c = layer_c->comm();
846
847 // get number of processes in child comm
848 const int nprocs_c = comm_c.size();
849
850 // get desired number of processes for parent comm
851 const int nprocs_p = this->_desired_levels.at(ilay).second;
852 XASSERT(nprocs_p < nprocs_c);
853 XASSERT(nprocs_p > 0);
854 XASSERT(nprocs_c % nprocs_p == 0); // same number of children for each parent
855
856 // compute number of siblings = children per parent
857 const int num_sibs = nprocs_c / nprocs_p;
858
859 // get my rank in child comm
860 const int my_rank_c = comm_c.rank();
861
862 // compute my parent's rank in child comm
863 const int parent_rank_c = (my_rank_c / num_sibs) * num_sibs;
864
865 // create our sibling communicator and set the parent rank
866 layer_c->set_parent(comm_c.comm_create_range_incl(num_sibs, parent_rank_c), 0);
867
868 // next, create the actual parent communicator
869 Dist::Comm comm_p = comm_c.comm_create_range_incl(nprocs_p, 0, num_sibs);
870
871 // Are we the parent?
872 if(parent_rank_c == my_rank_c)
873 {
874 // make sure we have a valid communicator
875 XASSERT(!comm_p.is_null());
876
877 // push the parent layer
878 this->push_layer(std::make_shared<LayerType>(std::move(comm_p), int(ilay)));
879 }
880 else
881 {
882 // We are not a parent, so we must have received a null communicator
883 XASSERT(comm_p.is_null());
884
885 // Exit the loop, as we are not part of the party anymore...
886 break;
887 }
888 }
889 }
890
895 {
896 // the layers must have been created already
897 XASSERT(!this->_layers.empty());
898
899 // create a deque with the number of processes for each layer
900 std::deque<std::int64_t> num_procs;
901 for(auto it = this->_desired_levels.begin(); it != this->_desired_levels.end(); ++it)
902 {
903 if(it->second > 1)
904 num_procs.push_back(it->second);
905 }
906 // manually add the base-layer
907 num_procs.push_back(1);
908
909 // allocate and create ancestry
910 this->_ancestry.resize(num_procs.size()-std::size_t(1));
911
912 // set up the ancestry
913 const std::int64_t main_rank = this->_comm.rank();
914 const std::int64_t main_size = this->_comm.size();
915 for(std::size_t i(0); i < this->_ancestry.size(); ++i)
916 {
917 // get our ancestor info
918 Ancestor& ancestor = this->_ancestry.at(i);
919
920 // set the layer index (or -1, if this process is not part of that layer)
921 ancestor.layer = (i < this->_layers.size() ? int(i) : -1);
922
923 // set the parent layer index (or -1, if this process is not in the parent layer)
924 ancestor.layer_p = ((i+1u) < this->_layers.size() ? int(i)+1 : -1);
925
926 // set the total number of processes for this layer
927 ancestor.num_procs = int(num_procs.at(i));
928
929 // set the total number of partitions per progeny group
930 ancestor.num_parts = int(num_procs.at(i) / num_procs.at(i+1u));
931
932 // set desired maximum level
933 XASSERT(i < this->_desired_levels.size());
934 ancestor.desired_level_max = this->_desired_levels.at(i).first;
935
936 // set desired minimum level
937 if((i+1u) < this->_desired_levels.size())
938 ancestor.desired_level_min = this->_desired_levels.at(i+1).first;
939 else
940 ancestor.desired_level_min = ancestor.desired_level_max;
941
942 // set the progeny group
943 ancestor.progeny_group = int((main_rank * num_procs.at(i+1u)) / main_size) * ancestor.num_parts;
944 ancestor.progeny_child = int((main_rank * num_procs.at(i)) / main_size) % ancestor.num_parts;
945
946 // create the progeny communicator
947 ancestor.progeny_count = int(main_size / num_procs.at(i+1u));
948 ancestor.progeny_first = int(main_rank / ancestor.progeny_count) * ancestor.progeny_count;
949 ancestor.progeny_comm = this->_comm.comm_create_range_incl(ancestor.progeny_count, ancestor.progeny_first);
950 }
951 }
952
971 const Ancestor& ancestor,
972 const MeshNodeType& base_mesh_node,
973 MeshNodeType& patch_mesh_node,
974 std::vector<int>& neighbor_ranks)
975 {
976 // get the map of the base-mesh halos
977 const std::map<int, std::unique_ptr<MeshPartType>>& base_halo_map = base_mesh_node.get_halo_map();
978
979 // if the base mesh has no halos, then we can jump out of here
980 if(base_halo_map.empty())
981 return;
982
983 // get number of halos
984 const std::size_t num_halos = base_halo_map.size();
985
986 // create a halo splitter
987 Geometry::PatchHaloSplitter<MeshType> halo_splitter(*base_mesh_node.get_mesh(),
988 *base_mesh_node.get_patch(ancestor.progeny_child));
989
990 // add each base-mesh halo to our halo splitter and store the resulting split data size
991 std::vector<int> halo_ranks;
992 std::vector<std::size_t> halo_sizes;
993 for(auto it = base_halo_map.begin(); it != base_halo_map.end(); ++it)
994 {
995 // store halo rank
996 halo_ranks.push_back(it->first);
997
998 // try to split the halo and store the resulting data size
999 halo_sizes.push_back(halo_splitter.add_halo(it->first, *it->second));
1000 }
1001
1002 // This vector will receive the split halo data from all our potential neighbor processes
1003 std::vector<Index> halo_recv_data;
1004 std::vector<std::vector<Index>> halo_send_data;
1005
1006 /* ******************************************************************************************************* */
1007 /* ******************************************************************************************************* */
1008 // PHASE I: collect halo data from our siblings
1009 /* ******************************************************************************************************* */
1010 /* ******************************************************************************************************* */
1011 if(ancestor.layer >= 0)
1012 {
1013 XASSERT(this->_layers.size() > std::size_t(ancestor.layer));
1014 const LayerType& layer = *this->_layers.at(std::size_t(ancestor.layer));
1015 const Dist::Comm& sibling_comm = *layer.sibling_comm_ptr();
1016 XASSERT(!sibling_comm.is_null());
1017 const std::size_t num_sibls = std::size_t(sibling_comm.size());
1018
1019 // get the rank of this process in various communicators
1020 const int sibl_rank = sibling_comm.rank();
1021 const int layer_rank = layer.comm().rank();
1022
1023 // gather halo infos of all siblings at sibling rank 0
1024 std::vector<std::size_t> sibl_halo_sizes(sibl_rank == 0 ? num_halos*num_sibls : 0u);
1025 sibling_comm.gather(halo_sizes.data(), halo_sizes.size(), sibl_halo_sizes.data(), halo_sizes.size(), 0);
1026
1027 if(sibl_rank > 0)
1028 {
1029 std::vector<std::vector<Index>> halo_split_data(num_halos);
1030 Dist::RequestVector send_reqs(num_halos);
1031
1032 // serialize all split halos
1033 for(std::size_t i(0); i < num_halos; ++i)
1034 {
1035 // skip empty halos
1036 if(halo_sizes.at(i) == Index(0))
1037 continue;
1038
1039 // serialize split halo data
1040 halo_split_data.at(i) = halo_splitter.serialize_split_halo(halo_ranks[i], layer_rank);
1041 XASSERT(halo_split_data.at(i).size() == halo_sizes.at(i));
1042
1043 // send split data over to our parent process
1044 send_reqs[i] = sibling_comm.isend(halo_split_data.at(i).data(), halo_sizes.at(i), 0);
1045 }
1046
1047 // wait for all pending sends to finish
1048 send_reqs.wait_all();
1049 }
1050 else // if(sibl_rank == 0)
1051 {
1052 halo_send_data.resize(num_halos);
1053
1054 // compute halo send data sizes
1055 for(std::size_t i(0); i < num_halos; ++i)
1056 {
1057 // determine the number of child processes for this halo
1058 // as well as the required send buffer size
1059 Index num_halo_childs = 0u;
1060 std::size_t buffer_size = 0u, offset = 0u;
1061 for(std::size_t j(0); j < num_sibls; ++j)
1062 {
1063 // update required buffer size
1064 buffer_size += sibl_halo_sizes.at(j*num_halos + i);
1065
1066 // this sibling is a child if its split halo is not empty
1067 if(sibl_halo_sizes.at(j*num_halos + i) > std::size_t(0))
1068 ++num_halo_childs;
1069 }
1070
1071 // increase buffer size to store child data offsets
1072 buffer_size += num_halo_childs + Index(1);
1073
1074 // allocate send buffer and get a pointer to its data array
1075 halo_send_data.at(i).resize(buffer_size);
1076 Index* halo_buffer = halo_send_data.at(i).data();
1077
1078 // store child count as first entry of buffer
1079 halo_buffer[0u] = num_halo_childs;
1080
1081 // initialize offset for first child
1082 offset = num_halo_childs + Index(1);
1083 Index coi = 0u; // child offset index
1084
1085 // collect my own split halo
1086 if(sibl_halo_sizes.at(i) > Index(0))
1087 {
1088 std::vector<Index> my_data(halo_splitter.serialize_split_halo(halo_ranks[i], layer_rank));
1089 std::size_t data_size = sibl_halo_sizes.at(i);
1090 halo_buffer[++coi] = Index(offset);
1091 for(std::size_t k(0); k < data_size; ++k)
1092 halo_buffer[offset+k] = my_data[k];
1093 offset += my_data.size();
1094 }
1095
1096 Dist::RequestVector sibl_recv_reqs(num_sibls);
1097
1098 // collect the other siblings
1099 for(std::size_t j(1); j < num_sibls; ++j)
1100 {
1101 // skips all sibling with empty halos
1102 std::size_t data_size = sibl_halo_sizes.at(j*num_halos + i);
1103 if(data_size == std::size_t(0))
1104 continue;
1105 XASSERT(offset+data_size <= buffer_size);
1106
1107 // store offset for this child
1108 halo_buffer[++coi] = Index(offset);
1109
1110 // receive serialized data from this sibling
1111 sibl_recv_reqs[j] = sibling_comm.irecv(&halo_buffer[offset], data_size, int(j));
1112 offset += data_size;
1113 }
1114 XASSERT(offset == buffer_size);
1115
1116 // wait for all pending receives to finish
1117 sibl_recv_reqs.wait_all();
1118 }
1119 }
1120 } // if(ancestor.layer >= 0)
1121
1122 /* ******************************************************************************************************* */
1123 /* ******************************************************************************************************* */
1124 // PHASE II: exchange split halos over parent layer communicator
1125 /* ******************************************************************************************************* */
1126 /* ******************************************************************************************************* */
1127
1128 if(ancestor.layer_p >= 0)
1129 {
1130 XASSERT(!halo_send_data.empty());
1131
1132 // get the parent layer communicator
1133 const Dist::Comm& parent_comm = this->_layers.at(std::size_t(ancestor.layer_p))->comm();
1134
1135 std::vector<std::size_t> halo_recv_sizes(num_halos), halo_send_sizes(num_halos);
1136 Dist::RequestVector halo_recv_reqs(num_halos), halo_send_reqs(num_halos);
1137
1138 // exchange halo send data sizes
1139 for(std::size_t i(0); i < num_halos; ++i)
1140 {
1141 // get halo send size
1142 halo_send_sizes.at(i) = halo_send_data.at(i).size();
1143
1144 // post receive requests
1145 halo_recv_reqs[i] = parent_comm.irecv(&halo_recv_sizes[i], std::size_t(1), halo_ranks[i]);
1146
1147 // post send requests
1148 halo_send_reqs[i] = parent_comm.isend(&halo_send_sizes[i], std::size_t(1), halo_ranks[i]);
1149 }
1150
1151 // wait for sends and receives to finish
1152 halo_recv_reqs.wait_all();
1153 halo_send_reqs.wait_all();
1154
1155 // compute total receive buffer size
1156 std::size_t recv_buf_size = num_halos + std::size_t(1);
1157 for(std::size_t i(0); i < num_halos; ++i)
1158 recv_buf_size += halo_recv_sizes[i];
1159
1160 // allocate receive buffer
1161 halo_recv_data.resize(recv_buf_size);
1162
1163 // set up receive data pointers
1164 halo_recv_data[0] = Index(num_halos) + Index(1);
1165 for(std::size_t i(0); i < num_halos; ++i)
1166 halo_recv_data[i+1u] = Index(halo_recv_data[i] + halo_recv_sizes[i]);
1167
1168 // allocate receive buffers and post receives
1169 for(std::size_t i(0); i < num_halos; ++i)
1170 {
1171 // resize buffer and post receive
1172 halo_recv_reqs[i] = parent_comm.irecv(&halo_recv_data[halo_recv_data[i]], halo_recv_sizes.at(i), halo_ranks[i]);
1173
1174 // post send of actual halo buffer
1175 halo_send_reqs[i] = parent_comm.isend(halo_send_data.at(i).data(), halo_send_sizes.at(i), halo_ranks[i]);
1176 }
1177
1178 // wait for sends and receives to finish
1179 halo_recv_reqs.wait_all();
1180 halo_send_reqs.wait_all();
1181 } // if(ancestor.layer_p >= 0)
1182
1183 /* ******************************************************************************************************* */
1184 /* ******************************************************************************************************* */
1185 // PHASE III: broadcast halo receive data over progeny comm
1186 /* ******************************************************************************************************* */
1187 /* ******************************************************************************************************* */
1188
1189 {
1190 // broadcast receive buffer size
1191 std::size_t recv_data_size = halo_recv_data.size();
1192 ancestor.progeny_comm.bcast(&recv_data_size, std::size_t(1), 0);
1193
1194 // allocate buffer
1195 if(ancestor.progeny_comm.rank() != 0)
1196 {
1197 XASSERT(halo_recv_data.empty()); // should be empty until now
1198 halo_recv_data.resize(recv_data_size);
1199 }
1200 else
1201 {
1202 XASSERT(!halo_recv_data.empty()); // must not be empty
1203 }
1204
1205 // broadcast buffer
1206 ancestor.progeny_comm.bcast(halo_recv_data.data(), recv_data_size, 0);
1207 }
1208
1209 /*{
1210 String s;
1211 for(std::size_t i(0); i < num_halos; ++i)
1212 {
1213 s += stringify(halo_ranks[i]);
1214 s += " >";
1215 for(Index j(halo_recv_data[i]); j < halo_recv_data[i+1]; ++j)
1216 (s += " ") += stringify(halo_recv_data[j]);
1217 s += "\n";
1218 }
1219 this->_comm.allprint(s);
1220 }*/
1221
1222 /* ******************************************************************************************************* */
1223 /* ******************************************************************************************************* */
1224 // PHASE IV: intersect received halo splits
1225 /* ******************************************************************************************************* */
1226 /* ******************************************************************************************************* */
1227
1228 for(std::size_t i(0); i < num_halos; ++i)
1229 {
1230 // get the offset of the first date for this halo
1231 const Index offset = halo_recv_data.at(i);
1232
1233 // get the number of child processes for this halo
1234 const Index num_childs = halo_recv_data.at(offset);
1235
1236 // loop over all child processes
1237 for(Index j(0); j < num_childs; ++j)
1238 {
1239 // compute the offset of this child's data within the large buffer
1240 const Index buffer_offset = offset + halo_recv_data.at(offset+j+1u);
1241
1242 // intersect with our other halo
1243 if(!halo_splitter.intersect_split_halo(halo_ranks[i], halo_recv_data, buffer_offset))
1244 continue; // no intersection
1245
1246 // get the new neighbor's rank
1247 const int neighbor_rank = int(halo_recv_data.at(buffer_offset));
1248
1249 // add the new neighbor to our list
1250 neighbor_ranks.push_back(neighbor_rank);
1251
1252 // create new mesh-part
1253 patch_mesh_node.add_halo(neighbor_rank, halo_splitter.make_unique());
1254 }
1255 }
1256 }
1257
1283 virtual bool _check_parti(Ancestor& ancestor, const MeshNodeType& mesh_node, bool DOXY(is_base_layer))
1284 {
1285 // We need to determine the required partitioning level for a-posteriori partitioning.
1286 // For this, first determine the factor by which the number of elements increases for each refinement:
1287 const Index factor = Index(Geometry::Intern::StandardRefinementTraits<typename BaseClass::ShapeType, BaseClass::ShapeType::dimension>::count);
1288
1289 // compute minimum number of elements for a-posteriori partitioning
1290 const Index min_elems = Index(ancestor.num_parts) * Index(_required_elems_per_rank);
1291
1292 // Okay, get the number of elements on base-mesh level 0
1293 Index num_elems = mesh_node.get_mesh()->get_num_elements();
1294
1295 // compute refinement level on which we have enough elements
1296 int level = 0;
1297 for(; num_elems < min_elems; ++level)
1298 {
1299 num_elems *= factor;
1300 }
1301
1302 // assume that we did not find a partitioning yet
1303 ancestor.parti_found = false;
1304
1305 // finally, the user may have ancestor a greater level for partitioning:
1306 ancestor.parti_level = Math::max(ancestor.parti_level, level);
1307
1308 // No a-priori partitioning; try a-posteriori partitioner later
1309 return false;
1310 }
1311
1324 virtual bool _apply_parti(Ancestor& ancestor, /*const*/ MeshNodeType& base_mesh_node)
1325 {
1326 // compute weights
1327 std::vector<WeightType> weights = this->_compute_weights(ancestor, base_mesh_node);
1328
1329 // First of all, check whether an a-priori partitioning was selected;
1330 // if so, then we do not have to apply any a-posteriori partitioner
1331 if(weights.empty() && ancestor.parti_apriori)
1332 return true;
1333
1334 // ensure that the mesh has enough elements
1335 //XASSERT(ancestor.num_parts <= int(base_mesh_node.get_mesh()->get_num_elements()));
1336 if(base_mesh_node.get_mesh()->get_num_elements() < Index(ancestor.num_parts))
1337 return false;
1338
1339 // try the various a-posteriori partitioners
1340 if(this->_apply_parti_metis(ancestor, base_mesh_node, weights))
1341 return true;
1342 if(this->_apply_parti_zoltan(ancestor, base_mesh_node, weights))
1343 return true;
1344 if(this->_apply_parti_scotch(ancestor, base_mesh_node, weights))
1345 return true;
1346 if(this->_apply_parti_genetic(ancestor, base_mesh_node, weights))
1347 return true;
1348 if(this->_apply_parti_naive(ancestor, base_mesh_node, weights))
1349 return true;
1350
1351 // we should not arrive here...
1352 return false;
1353 }
1354
1370 bool _apply_parti_zoltan(Ancestor& ancestor, const MeshNodeType& base_mesh_node, const std::vector<WeightType>& weights)
1371 {
1372#ifdef FEAT_HAVE_ZOLTAN
1373 // is this even allowed?
1374 if(!this->_allow_parti_zoltan)
1375 return false;
1376
1377 // create partitioner on the corresponding progeny communicator
1378 Geometry::PartiZoltan partitioner(ancestor.progeny_comm);
1379
1380 // get the corresponding adjacency graph for partitioning
1381 constexpr int shape_dim = MeshNodeType::MeshType::ShapeType::dimension;
1382 const auto& faces_at_elem = base_mesh_node.get_mesh()->template get_index_set<shape_dim, 0>();
1383
1384 // call the partitioner
1385 if(!partitioner.execute(faces_at_elem, Index(ancestor.num_parts), weights))
1386 return false;
1387
1388 // create partition graph
1389 ancestor.parti_graph = partitioner.build_elems_at_rank();
1390
1391 // set info string
1392 ancestor.parti_info = String("Applied Zoltan partitioner");
1393
1394 // partitioning found
1395 ancestor.parti_found = true;
1396
1397 // okay
1398 return true;
1399#else // FEAT_HAVE_ZOLTAN
1400 (void)ancestor;
1401 (void)base_mesh_node;
1402 (void)weights;
1403 return false;
1404#endif // FEAT_HAVE_ZOLTAN
1405 }
1406
1422 bool _apply_parti_metis(Ancestor& ancestor, const MeshNodeType& base_mesh_node, const std::vector<WeightType>& weights)
1423 {
1424#ifdef FEAT_HAVE_PARMETIS
1425 // is this even allowed?
1426 if(!this->_allow_parti_metis)
1427 return false;
1428
1429 // create partitioner on the corresponding progeny communicator
1430 Geometry::PartiParMETIS partitioner(ancestor.progeny_comm);
1431
1432 // get the corresponding adjacency graph for partitioning
1433 constexpr int shape_dim = MeshNodeType::MeshType::ShapeType::dimension;
1434 const auto& faces_at_elem = base_mesh_node.get_mesh()->template get_index_set<shape_dim, 0>();
1435
1436 // get vertices-at-element and vertex set
1437 const auto& verts_at_elem = base_mesh_node.get_mesh()->template get_index_set<shape_dim, 0>();
1438 const auto& vertex_set = base_mesh_node.get_mesh()->get_vertex_set();
1439
1440 // call the partitioner
1441 if(!partitioner.execute(faces_at_elem, verts_at_elem, vertex_set, Index(ancestor.num_parts), weights))
1442 return false;
1443
1444 // create partition graph
1445 ancestor.parti_graph = partitioner.build_elems_at_rank();
1446
1447 // set info string
1448 ancestor.parti_info = String("Applied ParMETIS partitioner");
1449
1450 // partitioning found
1451 ancestor.parti_found = true;
1452
1453 // okay
1454 return true;
1455#else
1456 (void)ancestor;
1457 (void)base_mesh_node;
1458 (void)weights;
1459 return false;
1460#endif // FEAT_HAVE_PARMETIS
1461 }
1462
1478 bool _apply_parti_scotch(Ancestor& ancestor, const MeshNodeType& base_mesh_node, const std::vector<WeightType>& weights)
1479 {
1480#ifdef FEAT_HAVE_SCOTCH
1481 // is this even allowed?
1482 if(!this->_allow_parti_scotch)
1483 return false;
1484
1485 // create partitioner on the corresponding progeny communicator
1486 Geometry::PartiScotch partitioner(ancestor.progeny_comm);
1487
1488 // get the corresponding adjacency graph for partitioning
1489 constexpr int shape_dim = MeshNodeType::MeshType::ShapeType::dimension;
1490 const auto& faces_at_elem = base_mesh_node.get_mesh()->template get_index_set<shape_dim, 0>();
1491
1492 // call the partitioner
1493 if(!partitioner.execute(faces_at_elem, Index(ancestor.num_parts), weights))
1494 return false;
1495
1496 // create partition graph
1497 ancestor.parti_graph = partitioner.build_elems_at_rank();
1498
1499 // set info string
1500 ancestor.parti_info = String("Applied Scotch partitioner");
1501
1502 // partitioning found
1503 ancestor.parti_found = true;
1504
1505 // okay
1506 return true;
1507#else
1508 (void)ancestor;
1509 (void)base_mesh_node;
1510 (void)weights;
1511 return false;
1512#endif
1513 }
1514
1527 bool _apply_parti_genetic(Ancestor& ancestor, /*const*/ MeshNodeType& base_mesh_node, const std::vector<WeightType>& weights)
1528 {
1529 // is this even allowed?
1530 if(!this->_allow_parti_genetic || !weights.empty())
1531 return false;
1532
1533 // create a genetic partitioner
1535 *base_mesh_node.get_mesh(),
1536 ancestor.progeny_comm,
1537 (Index)ancestor.num_parts,
1538 this->_genetic_time_init,
1539 this->_genetic_time_mutate);
1540
1541 // create elems-at-rank graph
1542 ancestor.parti_graph = partitioner.build_elems_at_rank();
1543
1544 // set info string
1545 ancestor.parti_info = String("Applied genetic partitioner");
1546
1547 // partitioning found
1548 ancestor.parti_found = true;
1549
1550 // okay
1551 return true;
1552 }
1553
1569 bool _apply_parti_naive(Ancestor& ancestor, const MeshNodeType& mesh_node, const std::vector<WeightType>& weights)
1570 {
1571 // is this even allowed?
1572 if(!this->_allow_parti_naive)
1573 return false;
1574
1575 const Index num_parts = Index(ancestor.num_parts);
1576 const Index num_elems = mesh_node.get_mesh()->get_num_elements();
1577 XASSERTM(num_parts <= num_elems, "Base-Mesh does not have enough elements");
1578
1579 // create elems-at-rank graph
1580 ancestor.parti_graph = Adjacency::Graph(num_parts, num_elems, num_elems);
1581 Index* ptr = ancestor.parti_graph.get_domain_ptr();
1582 Index* idx = ancestor.parti_graph.get_image_idx();
1583
1584 // weighted partitioning?
1585 // If num_elems == num_parts, we have to assign one element to each part, independent of weight.
1586 if(!weights.empty() && num_elems > num_parts)
1587 {
1588 // compute total number of non-zero weight elements
1589 WeightType weight_sum(0.0);
1590 for(auto w : weights)
1591 {
1592 weight_sum += w;
1593 }
1594
1595 ptr[0] = Index(0);
1596 WeightType weight_count(0.);
1597 for(Index i(1), last(0); i < num_parts; ++i)
1598 {
1599 // add as many elements as we need to achieve the target weight for this partition
1600 // Set target_weight to at least weight_count. Otherwise we might produce an empty block
1601 // because a previous block already surpassed the new target_weight.
1602 WeightType target_weight = Math::max(weight_count, weight_sum * WeightType(i) / WeightType(num_parts));
1603 for(; (weight_count <= target_weight) && (last < num_elems); ++last)
1604 weight_count += weights[last];
1605
1606 ptr[i] = last;
1607 }
1608 ptr[num_parts] = num_elems;
1609 }
1610 else
1611 {
1612 // unweighted partitioning
1613 ptr[0] = Index(0);
1614 for(Index i(1); i < num_parts; ++i)
1615 ptr[i] = (i*num_elems) / num_parts;
1616 ptr[num_parts] = num_elems;
1617 }
1618
1619 for(Index j(0); j < num_elems; ++j)
1620 idx[j] = j;
1621
1622 // set info string
1623 ancestor.parti_info = String("Applied naive partitioner");
1624
1625 // partitioning found
1626 ancestor.parti_found = true;
1627
1628 // okay
1629 return true;
1630 }
1631#endif // defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1632 }; // class HierarchDomainControl<...>
1633 } // namespace Domain
1634 } // namespace Control
1635} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Adjacency Graph implementation.
Definition: graph.hpp:34
Index * get_domain_ptr()
Returns the domain pointer array.
Definition: graph.hpp:359
Index * get_image_idx()
Returns the image node index array.
Definition: graph.hpp:374
Binary Stream class.
std::vector< char > & container()
Returns a reference to the internal vector container.
Domain control base-class template.
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
int progeny_first
First process of the progeny group of this process. Numbered w.r.t. the DomainControllers communicato...
String parti_info
a string containing some information about the chosen partitioning
bool parti_found
specifies whether a partitioning was found
int num_procs
the number of processes that participate in this layer
int progeny_count
Size of the progeny group of this process.
Adjacency::Graph parti_graph
this is the actual elements-at-rank partitioning graph
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.
const std::deque< std::pair< int, int > > get_chosen_levels() const
Returns the deque of chosen refinement levels.
virtual String format_desired_levels() const
Returns the desired levels formatted as a parsable string.
int get_desired_level_min() const
Returns the desired minimum refinement level.
PartiDomainControlBase(const Dist::Comm &comm_, bool support_multi_layered)
Constructor.
virtual std::vector< WeightType > _compute_weights(Ancestor &ancestor, const MeshNodeType &base_mesh_node)
Computes the element partitioning weights.
virtual void _reset_parti_types()
Resets/disables all partitioner types.
void set_adapt_mode(Geometry::AdaptMode adapt_mode)
Sets the adapt-mode for refinement.
String dump_ancestry() const
Debugging function: Returns a string containing encoded ancestry information.
void set_desired_levels(const String &slvls)
Sets the desired levels for the partitioned hierarchy.
const std::deque< std::pair< int, int > > get_desired_levels() const
Returns the deque of desired refinement levels.
std::deque< std::pair< int, int > > _desired_levels
desired level deque
bool _apply_parti_scotch(Ancestor &ancestor, const MeshNodeType &base_mesh_node, const std::vector< WeightType > &weights)
Applies the SCOTCH partitioner onto the base-mesh.
int _required_elems_per_rank
required number of elements per rank for a-posteriori partitioning
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
double _genetic_time_mutate
time for genetic partitioner mutation
std::deque< Ancestor > _ancestry
the partition ancestry deque
bool _apply_parti_zoltan(Ancestor &ancestor, const MeshNodeType &base_mesh_node, const std::vector< WeightType > &weights)
Applies the Zoltan partitioner onto the base-mesh.
bool _apply_parti_naive(Ancestor &ancestor, const MeshNodeType &mesh_node, const std::vector< WeightType > &weights)
Applies the naive partitioner onto the base-mesh.
bool _apply_parti_metis(Ancestor &ancestor, const MeshNodeType &base_mesh_node, const std::vector< WeightType > &weights)
Applies the METIS partitioner onto the base-mesh.
virtual bool parse_args(SimpleArgParser &args)
Parses the partitioner options from an argument parser.
bool _apply_parti_genetic(Ancestor &ancestor, MeshNodeType &base_mesh_node, const std::vector< WeightType > &weights)
Applies the genetic partitioner onto the base-mesh.
Geometry::RootMeshNode< MeshType > MeshNodeType
our root mesh node type
const std::deque< Ancestor > & get_ancestry() const
Returns a const reference to the ancestry.
std::vector< char > serialize_partitioning() const
Serializes the partitioning information into a binary buffer.
virtual bool _parse_parti_type(const String &type)
Parses a partitioner type.
virtual String format_chosen_levels() const
Returns the chosen levels formatted as a parsable string.
virtual void set_desired_levels(int lvl_max, int lvl_med, int lvl_min)
Sets the desired refinement levels for a double-layered hierarchy.
LevelType::PartType MeshPartType
our mesh-part type
Geometry::AdaptMode get_adapt_mode() const
Gets the adapt-mode for refinement.
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
int get_desired_level_max() const
Returns the desired maximum refinement level.
virtual void set_desired_levels(const std::deque< String > &slvls)
Sets the desired levels for the partitioned hierarchy.
bool _was_created
specifies whether the domain control was already created
virtual String get_chosen_parti_info() const
Returns an informative string about the chosen partitioning.
virtual bool parse_property_map(const PropertyMap &pmap)
Parses the partitioner options from a PropertyMap.
double _genetic_time_init
time for genetic partitioner initialization
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.
Control::Domain::DomainControl< DomainLevel_ > BaseClass
Our base class.
virtual void set_desired_levels(int lvl_max, int lvl_min=-1)
Sets the desired refinement levels for a single-layered hierarchy.
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.
Communicator class.
Definition: dist.hpp:1657
void bcast(void *buffer, std::size_t count, const Datatype &datatype, int root) const
Blocking broadcast.
Definition: dist.cpp:544
Comm comm_create_range_incl(int count, int first=0, int stride=1) const
Creates a new sub-communicator from a strided range of ranks.
Definition: dist.cpp:475
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
Definition: dist.cpp:658
int size() const
Returns the size of this communicator.
Definition: dist.hpp:1814
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Definition: dist.cpp:719
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
Definition: dist.cpp:707
MPI_Comm comm
our MPI communicator handle
Definition: dist.hpp:1661
void gather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Blocking gather.
Definition: dist.cpp:556
Comm comm_dup() const
Creates a copy of this communicator.
Definition: dist.cpp:462
int rank() const
Returns the rank of this process in this communicator.
Definition: dist.hpp:1802
bool is_null() const
Checks whether this communicator is a null communicator.
Definition: dist.cpp:457
void print(std::ostream &os, const String &msg, int root=0) const
Prints a message line to an output stream.
Definition: dist.cpp:800
Communication Request vector class.
Definition: dist.hpp:948
void wait_all()
Blocks until all active requests are fulfilled.
Definition: dist.cpp:327
MeshType * get_mesh()
Returns the mesh of this node.
Definition: mesh_node.hpp:225
Iterative-Partitioner class template declaration.
ParMETIS mesh/graph partitioner backend.
bool execute(const IndexSet< nf_ > &faces_at_elem, const IndexSet< nv_ > &verts_at_elem, const VertexSet_ &vertices, const Index num_parts, const std::vector< Real > &weights)
Executes the ParMETIS graph partitioner.
Adjacency::Graph build_elems_at_rank() const
Builds and returns the elements-at-rank graph representing the partitioning.
Zoltan hypergraph partitioner backend.
bool execute(const IndexSet< n_ > &faces_at_elem, const Index num_parts, const std::vector< Real > &weights)
Executes the Zoltan partitioner.
Adjacency::Graph build_elems_at_rank() const
Builds and returns the elements-at-rank graph representing the partitioning.
Base-Mesh Patch Halo splitter.
Root mesh node class template.
Definition: mesh_node.hpp:748
const MeshPartType * get_patch(int rank) const
Returns a patch meshpart for a given child.
Definition: mesh_node.hpp:962
const std::map< int, std::unique_ptr< MeshPartType > > & get_halo_map() const
Definition: mesh_node.hpp:896
void add_halo(int rank, std::unique_ptr< MeshPartType > halo_part)
Adds a halo mesh part to this mesh node.
Definition: mesh_node.hpp:874
Class for parser related errors.
Definition: exception.hpp:132
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.
int parse(const String &option, Prms_ &&... prms) const
Parses the parameters of an option.
String class implementation.
Definition: string.hpp:47
std::deque< String > split_by_whitespaces() const
Splits the string by white-spaces.
Definition: string.hpp:519
int compare_no_case(const String &other) const
Compares two strings without regard to case.
Definition: string.hpp:680
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
Definition: string.hpp:393
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
Definition: dist.hpp:573
AdaptMode
Adapt mode enumeration.
Definition: mesh_node.hpp:53
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
std::uint64_t Index
Index data type.