18 Chi::log.
Log() <<
"Partitioning mesh with ParMETIS.";
23 size_t num_raw_faces = 0;
25 num_raw_faces += cell->faces.size();
26 size_t avg_num_face_per_cell =
27 std::ceil(
static_cast<double>(num_raw_faces)/
28 static_cast<double>(num_raw_cells));
31 std::vector<int64_t> cell_pids(num_raw_cells, 0);
34 if (num_raw_cells > 1)
37 std::vector<int64_t> i_indices(num_raw_cells+1,0);
38 std::vector<int64_t> j_indices;
39 j_indices.reserve(num_raw_cells * avg_num_face_per_cell);
45 i_indices[i] = icount;
47 for (
auto& face : cell->faces)
48 if (face.has_neighbor)
50 j_indices.push_back(
static_cast<int64_t
>(face.neighbor));
55 i_indices[i] = icount;
61 int64_t* i_indices_raw;
62 int64_t* j_indices_raw;
63 PetscMalloc(i_indices.size()*
sizeof(int64_t),&i_indices_raw);
64 PetscMalloc(j_indices.size()*
sizeof(int64_t),&j_indices_raw);
66 for (int64_t j=0; j<static_cast<int64_t>(i_indices.size()); ++j)
67 i_indices_raw[j] = i_indices[j];
69 for (int64_t j=0; j<static_cast<int64_t>(j_indices.size()); ++j)
70 j_indices_raw[j] = j_indices[j];
76 MatCreateMPIAdj(PETSC_COMM_SELF,
77 (int64_t)num_raw_cells,
78 (int64_t)num_raw_cells,
79 i_indices_raw, j_indices_raw,
nullptr, &Adj);
86 MatPartitioningCreate(MPI_COMM_SELF,&part);
87 MatPartitioningSetAdjacency(part,Adj);
88 MatPartitioningSetType(part,
"parmetis");
89 MatPartitioningSetNParts(part,
Chi::mpi.process_count);
90 MatPartitioningApply(part,&is);
91 MatPartitioningDestroy(&part);
93 ISPartitioningToNumbering(is,&isg);
97 const int64_t* cell_pids_raw;
98 ISGetIndices(is,&cell_pids_raw);
99 for (
size_t i=0; i<num_raw_cells; ++i)
100 cell_pids[i] = cell_pids_raw[i];
101 ISRestoreIndices(is,&cell_pids_raw);
109 MPI_Bcast(cell_pids.data(),
110 static_cast<int>(num_raw_cells),
static chi::MPI_Info & mpi
LogStream Log(LOG_LVL level=LOG_0)
const MPI_Comm & comm
MPI communicator.
std::vector< LightWeightCell * > & GetRawCells()
size_t GetNumberOfCells() const