23 "type",
"parmetis",
"The type of PETSc partitioner");
34 const std::vector<std::vector<uint64_t>>& graph,
35 const std::vector<chi_mesh::Vector3>&,
42 const size_t num_raw_cells = graph.size();
43 size_t num_raw_faces = 0;
44 for (
auto& cell_row : graph)
45 num_raw_faces += cell_row.size();
46 size_t avg_num_face_per_cell = std::ceil(
static_cast<double>(num_raw_faces) /
47 static_cast<double>(num_raw_cells));
50 std::vector<int64_t> cell_pids(num_raw_cells, 0);
51 if (num_raw_cells > 1)
54 std::vector<int64_t> i_indices(num_raw_cells + 1, 0);
55 std::vector<int64_t> j_indices;
56 j_indices.reserve(num_raw_cells * avg_num_face_per_cell);
60 for (
const auto& cell : graph)
62 i_indices[i] = icount;
64 for (
const uint64_t neighbor_id : cell)
66 j_indices.push_back(
static_cast<int64_t
>(neighbor_id));
71 i_indices[i] = icount;
77 int64_t* i_indices_raw;
78 int64_t* j_indices_raw;
79 PetscMalloc(i_indices.size() *
sizeof(int64_t), &i_indices_raw);
80 PetscMalloc(j_indices.size() *
sizeof(int64_t), &j_indices_raw);
82 for (int64_t j = 0; j < static_cast<int64_t>(i_indices.size()); ++j)
83 i_indices_raw[j] = i_indices[j];
85 for (int64_t j = 0; j < static_cast<int64_t>(j_indices.size()); ++j)
86 j_indices_raw[j] = j_indices[j];
92 MatCreateMPIAdj(PETSC_COMM_SELF,
93 (int64_t)num_raw_cells,
94 (int64_t)num_raw_cells,
103 MatPartitioning part;
105 MatPartitioningCreate(MPI_COMM_SELF, &part);
106 MatPartitioningSetAdjacency(part, Adj);
107 MatPartitioningSetType(part,
type_.c_str());
108 MatPartitioningSetNParts(part, number_of_parts);
109 MatPartitioningApply(part, &is);
110 MatPartitioningDestroy(&part);
112 ISPartitioningToNumbering(is, &isg);
116 const int64_t* cell_pids_raw;
117 ISGetIndices(is, &cell_pids_raw);
118 for (
size_t i = 0; i < num_raw_cells; ++i)
119 cell_pids[i] = cell_pids_raw[i];
120 ISRestoreIndices(is, &cell_pids_raw);
static InputParameters GetInputParameters()
static InputParameters GetInputParameters()
std::vector< int64_t > Partition(const std::vector< std::vector< uint64_t > > &graph, const std::vector< chi_mesh::Vector3 > ¢roids, int number_of_parts) override
PETScGraphPartitioner(const InputParameters ¶ms)
RegisterChiObject(chi, KBAGraphPartitioner)