Chi-Tech
LinearGraphPartitioner.cc
Go to the documentation of this file.
2
3#include "ChiObjectFactory.h"
4#include "utils/chi_utils.h"
5
6#include "chi_log.h"
7
8#include <cmath>
9
10namespace chi
11{
12
14
16{
18
19 // clang-format off
20 params.SetGeneralDescription("Basic linear partitioning. "
21"This type of partitioner works basically only for testing. Orthogonal meshes"
22" can produce decent partitioning but for unstructured grids it can be pretty"
23" bad. It partitions cells based on their linear index \"global_id\" instead "
24"of actually working with the graph.");
25 // clang-format on
26 params.SetDocGroup("Graphs");
27
28 params.AddOptionalParameter("all_to_rank",
29 -1,
30 "If non-zero will restrict all cells to this rank, "
31 "essentially transforming this partitioner into a "
32 "single-rank partitioner.");
33
34 return params;
35}
36
38 : GraphPartitioner(params),
39 all_to_rank_(params.GetParamValue<int>("all_to_rank"))
40{
41}
42
43/**Given a graph. Returns the partition ids of each row in the graph.*/
45 const std::vector<std::vector<uint64_t>>& graph,
46 const std::vector<chi_mesh::Vector3>&,
47 const int number_of_parts)
48{
49 Chi::log.Log0Verbose1() << "Partitioning with LinearGraphPartitioner";
50
51 const std::vector<chi::SubSetInfo> sub_sets =
52 chi::MakeSubSets(graph.size(), number_of_parts);
53
54 std::vector<int64_t> pids(graph.size(), 0);
55
56 if (all_to_rank_ < 0)
57 {
58 size_t n = 0;
59 for (int k = 0; k < number_of_parts; ++k)
60 for (size_t m = 0; m < sub_sets[k].ss_size; ++m)
61 pids[n++] = k;
62 }
63 else
64 pids.assign(graph.size(), all_to_rank_);
65
66 Chi::log.Log0Verbose1() << "Done partitioning with LinearGraphPartitioner";
67 return pids;
68}
69
70} // namespace chi
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log0Verbose1()
Definition: chi_log.h:234
static InputParameters GetInputParameters()
void SetDocGroup(const std::string &doc_group)
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
void SetGeneralDescription(const std::string &description)
LinearGraphPartitioner(const InputParameters &params)
std::vector< int64_t > Partition(const std::vector< std::vector< uint64_t > > &graph, const std::vector< chi_mesh::Vector3 > &centroids, int number_of_parts) override
static InputParameters GetInputParameters()
std::vector< SubSetInfo > MakeSubSets(size_t num_items, size_t desired_num_subsets)
Definition: subsets.cc:10
RegisterChiObject(chi, KBAGraphPartitioner)