18 #include <flecsi-config.h> 23 #if !defined(FLECSI_ENABLE_PARMETIS) 24 #error FLECSI_ENABLE_PARMETIS not defined! This file depends on ParMETIS! 46 std::set<size_t>
color(
const dcrs & naive)
override {
50 MPI_Comm_size(MPI_COMM_WORLD, &size);
51 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
60 std::vector<real_t> tpwgts(size);
63 for(
size_t i(0); i < tpwgts.size(); ++i) {
64 if(i == (tpwgts.size() - 1)) {
65 tpwgts[i] = 1.0 - sum;
68 tpwgts[i] = 1.0 / size;
74 std::cout << tpwgts[i] << std::endl;
83 MPI_Comm comm = MPI_COMM_WORLD;
84 std::vector<idx_t> part(naive.size(), std::numeric_limits<idx_t>::max());
87 const size_t output_rank(1);
88 if(rank == output_rank) {
89 std::cout <<
"rank " << rank <<
" naive: " << std::endl;
90 std::cout <<
"size: " << naive.size() << std::endl;
91 std::cout << naive << std::endl;
99 std::vector<idx_t> vtxdist = naive.distribution_as<idx_t>();
100 std::vector<idx_t> xadj = naive.offsets_as<idx_t>();
101 std::vector<idx_t> adjncy = naive.indices_as<idx_t>();
104 int result = ParMETIS_V3_PartKway(&vtxdist[0],
120 flog_assert(result == METIS_OK,
"ParMETIS_V3_PartKway returned " << result);
122 std::cout <<
"rank " << rank <<
": ";
123 for(
size_t i(0); i<naive.size(); ++i) {
124 std::cout <<
"[" << part[i] <<
", " << vtxdist[rank]+i <<
"] ";
126 std::cout << std::endl;
133 std::vector<idx_t> send_cnts(size, 0);
134 std::vector<std::vector<idx_t>> sbuffers;
136 std::set<size_t> primary;
139 for(
int r(0); r < size; ++r) {
140 std::vector<idx_t> indices;
142 for(
size_t i(0); i < naive.size(); ++i) {
144 indices.push_back(vtxdist[rank] + i);
146 else if(part[i] == rank) {
148 primary.insert(vtxdist[rank] + i);
152 sbuffers.push_back(indices);
153 send_cnts[r] = indices.size();
159 for(
auto r: sbuffers) {
160 std::cout <<
"rank " << rank <<
" sends " << rcnt++ <<
161 " " << send_cnts[rcnt] <<
": ";
163 std::cout << i <<
" ";
165 std::cout << std::endl;
171 std::vector<idx_t> recv_cnts(size);
172 result = MPI_Alltoall(&send_cnts[0],
182 std::cout <<
"rank " << rank <<
" receives: ";
184 for(
size_t i(0); i<size; ++i) {
185 std::cout << recv_cnts[i] <<
" ";
188 std::cout << std::endl;
193 std::vector<std::vector<idx_t>> rbuffers(size);
194 std::vector<MPI_Request> requests;
195 for(
int r(0); r < size; ++r) {
197 rbuffers[r].resize(recv_cnts[r]);
198 requests.push_back({});
199 MPI_Irecv(&rbuffers[r][0],
205 &requests[requests.size() - 1]);
210 for(
int r(0); r < size; ++r) {
212 sbuffers[r].resize(send_cnts[r]);
213 MPI_Send(&sbuffers[r][0],
223 std::vector<MPI_Status> status(requests.size());
224 MPI_Waitall(requests.size(), &requests[0], &status[0]);
227 for(
int r(0); r < size; ++r) {
229 for(
auto i : rbuffers[r]) {
237 std::cout <<
"rank " << rank <<
" primary coloring:" << std::endl;
238 for(
auto i: primary) {
239 std::cout << i <<
" ";
241 std::cout << std::endl;
246 "At least one rank has an empty primary coloring. Please either " 247 "increase the problem size or use fewer ranks");
260 MPI_Comm_size(MPI_COMM_WORLD, &size);
261 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
270 std::vector<real_t> tpwgts(ncon * size, 1.0 / size);
273 std::vector<real_t> ubvec(ncon, 1.05);
274 idx_t options[3] = {0, 0, 0};
276 MPI_Comm comm = MPI_COMM_WORLD;
277 std::vector<idx_t> part(naive.size(), std::numeric_limits<idx_t>::max());
280 std::vector<idx_t> vtxdist = naive.distribution_as<idx_t>();
281 std::vector<idx_t> xadj = naive.offsets_as<idx_t>();
282 std::vector<idx_t> adjncy = naive.indices_as<idx_t>();
285 int result = ParMETIS_V3_PartKway(&vtxdist[0],
301 flog_assert(result == METIS_OK,
"ParMETIS_V3_PartKway returned " << result);
303 std::vector<size_t> partitioning(part.begin(), part.end());
Definition: parmetis_colorer.hh:40
Definition: colorer.hh:31
#define flog_assert(test, message)
Definition: flog.hh:411
std::set< size_t > color(const dcrs &naive) override
Definition: parmetis_colorer.hh:46
std::vector< size_t > new_color(const dcrs &naive) override
Definition: parmetis_colorer.hh:256
Definition: mpi_type_traits.hh:38
Definition: control.hh:31