Chi-Tech
volmesher_predefunpart_kba.cc
Go to the documentation of this file.
2
7
8
9#include "chi_runtime.h"
10#include "chi_log.h"
11#include "chi_mpi.h"
12
13
14//###################################################################
15/** Applies KBA-style partitioning to the mesh.*/
18{
19 Chi::log.Log() << "Partitioning mesh KBA-style.";
20
21 const size_t num_raw_cells = umesh.GetNumberOfCells();
22
23 //======================================== Lambda to get partition-id
24 // from centroid
25 auto GetPIDFromCentroid = [](const chi_mesh::Vertex& centroid)
26 {
27 auto& handler = chi_mesh::GetCurrentHandler();
28
29 int Px = handler.GetVolumeMesher().options.partition_x;
30 int Py = handler.GetVolumeMesher().options.partition_y;
31
33 temp_cell.centroid_ = centroid;
34
35 auto xyz = GetCellXYZPartitionID(&temp_cell);
36
37 int nxi = std::get<0>(xyz);
38 int nyi = std::get<1>(xyz);
39 int nzi = std::get<2>(xyz);
40
41 return nzi*Px*Py + nyi*Px + nxi;
42 };
43
44 //======================================== Determine cell partition-IDs
45 // only on home location
46 std::vector<int64_t> cell_pids(num_raw_cells, 0);
47 if (Chi::mpi.location_id == 0)
48 {
49 uint64_t cell_id = 0;
50 for (auto& raw_cell : umesh.GetRawCells())
51 cell_pids[cell_id++] = GetPIDFromCentroid(raw_cell->centroid);
52 }//if home location
53
54 //======================================== Broadcast partitioning to all
55 // locations
56 MPI_Bcast(cell_pids.data(), //buffer [IN/OUT]
57 static_cast<int>(num_raw_cells), //count
58 MPI_LONG_LONG_INT, //data type
59 0, //root
60 Chi::mpi.comm); //communicator
61 Chi::log.Log() << "Done partitioning mesh.";
62
63 return cell_pids;
64}
static chi::ChiLog & log
Definition: chi_runtime.h:81
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
const MPI_Comm & comm
MPI communicator.
Definition: mpi_info.h:28
Vertex centroid_
Definition: cell.h:78
std::vector< LightWeightCell * > & GetRawCells()
static std::tuple< int, int, int > GetCellXYZPartitionID(chi_mesh::Cell *cell)
static std::vector< int64_t > KBA(const chi_mesh::UnpartitionedMesh &umesh)
MeshHandler & GetCurrentHandler()