Skip to content

Commit c8e7339

Browse files
committed
Use partitioning neighborhood directly for hypergraph
1 parent b848783 commit c8e7339

File tree

1 file changed

+10
-110
lines changed

1 file changed

+10
-110
lines changed

dccrg.hpp

Lines changed: 10 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,110 +2832,6 @@ template <
28322832
return ret;
28332833
}
28342834

2835-
std::set<uint64_t> get_vlasov_neighbors(
2836-
const uint64_t cell,
2837-
const int neighborhood_id,
2838-
const int dimension,
2839-
const int stencil_width
2840-
) const {
2841-
std::set<uint64_t> ret;
2842-
const auto* p = get_neighbors_of(cell, neighborhood_id);
2843-
if (!p) {
2844-
std::cerr << "Cell " << cell << ", neighborhood " << neighborhood_id << ", dimension " << dimension << " not found" << std::endl;
2845-
return ret;
2846-
}
2847-
2848-
// Create list of unique distances
2849-
std::set<int> distances_plus;
2850-
std::set<int> distances_minus;
2851-
std::set<uint64_t> found_neighbors_plus;
2852-
std::set<uint64_t> found_neighbors_minus;
2853-
/** Using sets of cells as well, we should only get one distance per
2854-
(potentially less refined) cell. This should result in safe behaviour
2855-
as long as the neighborhood of a cell does not contain cells with a
2856-
refinement level more than 1 level apart from the cell itself.
2857-
*/
2858-
for (const auto& [neighbor, coords] : *p) {
2859-
if(coords[dimension] > 0) {
2860-
if (!found_neighbors_plus.count(neighbor)) {
2861-
distances_plus.insert(coords[dimension]);
2862-
found_neighbors_plus.insert(neighbor);
2863-
}
2864-
}
2865-
if(coords[dimension] < 0) {
2866-
if (!found_neighbors_minus.count(neighbor)) {
2867-
distances_minus.insert(-coords[dimension]);
2868-
found_neighbors_minus.insert(neighbor);
2869-
}
2870-
}
2871-
}
2872-
2873-
int iSrc = stencil_width - 1;
2874-
// Iterate through positive distances for VLASOV_STENCIL_WIDTH elements starting from the smallest distance.
2875-
for (const auto& distance : distances_plus) {
2876-
if (iSrc < 0)
2877-
break; // found enough elements
2878-
for (const auto& [neighbor, coords] : *p) {
2879-
if (neighbor == error_cell)
2880-
continue;
2881-
if (coords[dimension] == distance) {
2882-
if (ret.count(neighbor))
2883-
continue;
2884-
ret.insert(neighbor);
2885-
}
2886-
} // end loop over neighbors
2887-
iSrc--;
2888-
} // end loop over positive distances
2889-
2890-
iSrc = stencil_width - 1;
2891-
// Iterate through negtive distances for VLASOV_STENCIL_WIDTH elements starting from the smallest distance.
2892-
for (const auto& distance : distances_minus) {
2893-
if (iSrc < 0)
2894-
break; // found enough elements
2895-
for (const auto& [neighbor, coords] : *p) {
2896-
if (neighbor == error_cell)
2897-
continue;
2898-
if (coords[dimension] == distance) {
2899-
if (ret.count(neighbor))
2900-
continue;
2901-
ret.insert(neighbor);
2902-
}
2903-
} // end loop over neighbors
2904-
iSrc--;
2905-
} // end loop over negative distances
2906-
2907-
return ret;
2908-
}
2909-
2910-
// Get actual Vlasov stencil neighbors
2911-
// Assumes linear 3 linear stencils from neighborhood_id to neighborhood_id + 2
2912-
std::set<uint64_t> get_vlasov_neighbors(
2913-
const uint64_t cell
2914-
) const {
2915-
int stencil_width {0};
2916-
switch (neighborhood_length) {
2917-
case 1:
2918-
break;
2919-
case 3:
2920-
stencil_width = 2;
2921-
break;
2922-
case 5:
2923-
stencil_width = 3;
2924-
break;
2925-
default:
2926-
// Placeholder error
2927-
std::cerr << "Weird stencil width" << std::endl;
2928-
break;
2929-
}
2930-
2931-
std::set<uint64_t> ret;
2932-
for (int dim = 0; dim < 3; ++dim) {
2933-
auto neighs_dim = get_vlasov_neighbors(cell, partitioning_neighborhood_id + dim, dim, stencil_width);
2934-
ret.insert(neighs_dim.begin(), neighs_dim.end());
2935-
}
2936-
return ret;
2937-
}
2938-
29392835

29402836
/*!
29412837
Returns true if given cell's neighbor types match given criterion, false otherwise.
@@ -11407,6 +11303,7 @@ template <
1140711303

1140811304

1140911305
/*!
11306+
Graph partitioning
1141011307
Writes the number of neighbors into number_of_neighbors for all cells given in global_ids.
1141111308
*/
1141211309
static void fill_number_of_neighbors_for_cells(
@@ -11444,12 +11341,13 @@ template <
1144411341
return;
1144511342
}
1144611343

11447-
number_of_neighbors[i] = dccrg_instance->get_vlasov_neighbors(cell).size();
11344+
number_of_neighbors[i] = dccrg_instance->get_neighbors_to(cell, dccrg_instance->partitioning_neighborhood_id)->size();
1144811345
}
1144911346
}
1145011347

1145111348

1145211349
/*!
11350+
Graph partitioning
1145311351
Writes neighbor lists of given cells into neighbors, etc.
1145411352
*/
1145511353
static void fill_neighbor_lists(
@@ -11493,7 +11391,9 @@ template <
1149311391

1149411392
number_of_neighbors[i] = 0;
1149511393

11496-
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(cell)) {
11394+
// We consider the communication weight from this cell to others
11395+
auto weight {dccrg_instance->get_communication_weight(cell)};
11396+
for (const auto& [neighbor, dir] : *dccrg_instance->get_neighbors_to(cell, dccrg_instance->partitioning_neighborhood_id)) {
1149711397
// Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
1149811398
if (neighbor == 0 || neighbor == cell) {
1149911399
continue;
@@ -11507,7 +11407,7 @@ template <
1150711407

1150811408
// weight of edge from cell to *neighbor
1150911409
if (number_of_weights_per_edge > 0) {
11510-
edge_weights[current_neighbor_number] = dccrg_instance->get_communication_weight(neighbor);
11410+
edge_weights[current_neighbor_number] = weight;
1151111411
}
1151211412

1151311413
current_neighbor_number++;
@@ -11560,7 +11460,7 @@ template <
1156011460

1156111461

1156211462
/*!
11563-
Writes the number of hyperedges (self + one per neighbor cell) in the grid for all cells on this process.
11463+
Writes the number of connections (self + one per neighbor cell) in the grid for all cells on this process.
1156411464
*/
1156511465
static void fill_number_of_hyperedges(
1156611466
void* data,
@@ -11588,7 +11488,7 @@ template <
1158811488

1158911489
*number_of_connections = 0;
1159011490
for (const auto& item: dccrg_instance->cell_data) {
11591-
(*number_of_connections) += 1 + dccrg_instance->get_vlasov_neighbors(item.first).size();
11491+
(*number_of_connections) += 1 + dccrg_instance->get_neighbors_to(item.first, dccrg_instance->partitioning_neighborhood_id)->size();
1159211492
}
1159311493
}
1159411494

@@ -11647,7 +11547,7 @@ template <
1164711547
// add a connection to the cell itself from its hyperedge
1164811548
connections[connection_number++] = item.first;
1164911549

11650-
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(item.first)) {
11550+
for (const auto& [neighbor, dir]: *dccrg_instance->get_neighbors_to(item.first, dccrg_instance->partitioning_neighborhood_id)) {
1165111551
// Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
1165211552
if (neighbor == 0 || neighbor == item.first) {
1165311553
continue;

0 commit comments

Comments
 (0)