MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / comm_graph

Method comm_graph

cpp/dolfinx/graph/utils.cpp:17–102  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

15
16//-----------------------------------------------------------------------------
17graph::AdjacencyList<std::tuple<int, std::size_t, std::int8_t>,
18 std::pair<std::int32_t, std::int32_t>>
19graph::comm_graph(const common::IndexMap& map, int root)
20{
21 MPI_Comm comm = map.comm();
22
23 std::span<const int> dest = map.dest();
24 int ierr;
25
26 // Graph edge out(dest) weights
27 const std::vector<std::int32_t> w_dest = map.weights_dest();
28
29 // Group ranks by type
30 const auto [local_dest, local_src] = map.rank_type(MPI_COMM_TYPE_SHARED);
31
32 // Get number of edges for each node (rank)
33 int num_edges_local = dest.size();
34 std::vector<int> num_edges_remote(dolfinx::MPI::size(comm));
35 ierr = MPI_Gather(&num_edges_local, 1, MPI_INT, num_edges_remote.data(), 1,
36 MPI_INT, root, comm);
37 dolfinx::MPI::check_error(comm, ierr);
38
39 // Compute displacements
40 std::vector<int> disp(num_edges_remote.size() + 1, 0);
41 std::partial_sum(num_edges_remote.begin(), num_edges_remote.end(),
42 std::next(disp.begin()));
43 dolfinx::MPI::check_error(comm, ierr);
44
45 // For each node (rank), get edge indices
46 std::vector<int> edges_remote(disp.back());
47 edges_remote.reserve(1);
48 ierr = MPI_Gatherv(dest.data(), dest.size(), MPI_INT, edges_remote.data(),
49 num_edges_remote.data(), disp.data(), MPI_INT, root, comm);
50 dolfinx::MPI::check_error(comm, ierr);
51
52 // For each edge, get edge weight
53 std::vector<std::int32_t> weights_remote(disp.back());
54 weights_remote.reserve(1);
55 ierr = MPI_Gatherv(w_dest.data(), w_dest.size(), MPI_INT32_T,
56 weights_remote.data(), num_edges_remote.data(),
57 disp.data(), MPI_INT32_T, root, comm);
58 dolfinx::MPI::check_error(comm, ierr);
59
60 // For node get local and ghost sizes
61 std::vector<std::pair<std::int32_t, std::int32_t>> sizes_remote;
62 {
63 std::vector<std::int32_t> sizes_local(dolfinx::MPI::size(comm));
64 std::int32_t size = map.size_local();
65 ierr = MPI_Gather(&size, 1, MPI_INT32_T, sizes_local.data(), 1, MPI_INT32_T,
66 root, comm);
67 dolfinx::MPI::check_error(comm, ierr);
68
69 std::vector<std::int32_t> sizes_ghost(dolfinx::MPI::size(comm));
70 std::int32_t num_ghosts = map.num_ghosts();
71 ierr = MPI_Gather(&num_ghosts, 1, MPI_INT32_T, sizes_ghost.data(), 1,
72 MPI_INT32_T, root, comm);
73 dolfinx::MPI::check_error(comm, ierr);
74

Callers 2

comm_graphFunction · 0.80

Calls 12

transformFunction · 0.85
vectorFunction · 0.85
destMethod · 0.80
weights_destMethod · 0.80
rank_typeMethod · 0.80
dataMethod · 0.80
size_localMethod · 0.80
num_ghostsMethod · 0.80
AdjacencyListClass · 0.70
check_errorFunction · 0.50
commMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected