10 #include <dolfinx/common/IndexMap.h>
11 #include <dolfinx/common/Timer.h>
12 #include <dolfinx/graph/AdjacencyList.h>
25 namespace Partitioning
48 std::tuple<std::vector<std::int32_t>, std::vector<std::int64_t>,
51 const std::vector<std::int64_t>& global_indices,
52 const std::vector<bool>& shared_indices);
62 std::pair<graph::AdjacencyList<std::int32_t>, std::vector<std::int64_t>>
78 const std::vector<std::int64_t>& local_to_global_links,
79 const std::vector<bool>& shared_links);
92 std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<int>,
93 std::vector<std::int64_t>, std::vector<int>>
104 std::vector<std::int64_t>
106 const std::vector<std::int64_t>& global_indices,
107 const std::vector<int>& ghost_owners);
118 template <
typename T>
119 Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
120 distribute_data(MPI_Comm comm,
const std::vector<std::int64_t>& indices,
121 const Eigen::Ref<
const Eigen::Array<
122 T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>& x);
135 std::vector<std::int64_t>
147 std::vector<std::int32_t>
149 const std::vector<std::int64_t>& local1_to_global);
155 template <
typename T>
156 Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
158 MPI_Comm comm,
const std::vector<std::int64_t>& indices,
159 const Eigen::Ref<
const Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic,
160 Eigen::RowMajor>>& x)
162 common::Timer timer(
"Fetch float data from remote processes");
164 const std::int64_t num_points_local = x.rows();
167 std::vector<std::int64_t> global_sizes(size);
168 MPI_Allgather(&num_points_local, 1, MPI_INT64_T, global_sizes.data(), 1,
170 std::vector<std::int64_t> global_offsets(size + 1, 0);
171 std::partial_sum(global_sizes.begin(), global_sizes.end(),
172 global_offsets.begin() + 1);
175 std::vector<int> number_index_send(size, 0);
176 std::vector<int> index_owner(indices.size());
177 std::vector<int> index_order(indices.size());
178 std::iota(index_order.begin(), index_order.end(), 0);
179 std::sort(index_order.begin(), index_order.end(),
180 [&indices](
int a,
int b) { return (indices[a] < indices[b]); });
183 for (std::size_t i = 0; i < index_order.size(); ++i)
185 int j = index_order[i];
186 while (indices[j] >= global_offsets[p + 1])
189 number_index_send[p]++;
193 std::vector<int> disp_index_send(size + 1, 0);
194 std::partial_sum(number_index_send.begin(), number_index_send.end(),
195 disp_index_send.begin() + 1);
198 std::vector<std::int64_t> indices_send(disp_index_send.back());
199 std::vector<int> disp_tmp = disp_index_send;
200 for (std::size_t i = 0; i < indices.size(); ++i)
202 const int owner = index_owner[i];
203 indices_send[disp_tmp[owner]++] = indices[i];
207 std::vector<int> number_index_recv(size);
208 MPI_Alltoall(number_index_send.data(), 1, MPI_INT, number_index_recv.data(),
212 std::vector<int> disp_index_recv(size + 1, 0);
213 std::partial_sum(number_index_recv.begin(), number_index_recv.end(),
214 disp_index_recv.begin() + 1);
217 std::vector<std::int64_t> indices_recv(disp_index_recv.back());
218 MPI_Alltoallv(indices_send.data(), number_index_send.data(),
219 disp_index_send.data(), MPI_INT64_T, indices_recv.data(),
220 number_index_recv.data(), disp_index_recv.data(), MPI_INT64_T,
223 const int item_size = x.cols();
224 assert(item_size != 0);
226 Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> x_return(
227 indices_recv.size(), item_size);
228 for (
int p = 0; p < size; ++p)
230 for (
int i = disp_index_recv[p]; i < disp_index_recv[p + 1]; ++i)
232 const std::int32_t index_local = indices_recv[i] - global_offsets[rank];
233 assert(index_local >= 0);
234 x_return.row(i) = x.row(index_local);
238 MPI_Datatype compound_type;
239 MPI_Type_contiguous(item_size, dolfinx::MPI::mpi_type<T>(), &compound_type);
240 MPI_Type_commit(&compound_type);
243 Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> my_x(
244 disp_index_send.back(), item_size);
245 MPI_Alltoallv(x_return.data(), number_index_recv.data(),
246 disp_index_recv.data(), compound_type, my_x.data(),
247 number_index_send.data(), disp_index_send.data(), compound_type,
static int rank(MPI_Comm comm)
Return process rank for the communicator.
Definition: MPI.cpp:79
static int size(MPI_Comm comm)
Return size of the group (number of processes) associated with the communicator.
Definition: MPI.cpp:87
This class represents the distribution index arrays across processes. An index array is a contiguous ...
Definition: IndexMap.h:45
A timer can be used for timing tasks. The basic usage is.
Definition: Timer.h:31
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:28
std::tuple< graph::AdjacencyList< std::int32_t >, common::IndexMap > create_distributed_adjacency_list(MPI_Comm comm, const graph::AdjacencyList< std::int32_t > &list_local, const std::vector< std::int64_t > &local_to_global_links, const std::vector< bool > &shared_links)
Build a distributed AdjacencyList list with re-numbered links from an AdjacencyList that may have non...
Definition: Partitioning.cpp:391
std::vector< std::int64_t > compute_local_to_global_links(const graph::AdjacencyList< std::int64_t > &global, const graph::AdjacencyList< std::int32_t > &local)
Given an adjacency list with global, possibly non-contiguous, link indices and a local adjacency list...
Definition: Partitioning.cpp:651
std::vector< std::int64_t > compute_ghost_indices(MPI_Comm comm, const std::vector< std::int64_t > &global_indices, const std::vector< int > &ghost_owners)
Compute ghost indices in a global IndexMap space, from a list of arbitrary global indices,...
Definition: Partitioning.cpp:535
std::tuple< std::vector< std::int32_t >, std::vector< std::int64_t >, std::vector< int > > reorder_global_indices(MPI_Comm comm, const std::vector< std::int64_t > &global_indices, const std::vector< bool > &shared_indices)
Definition: Partitioning.cpp:22
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > distribute_data(MPI_Comm comm, const std::vector< std::int64_t > &indices, const Eigen::Ref< const Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >> &x)
Distribute data to process ranks where it it required.
Definition: Partitioning.h:157
std::vector< std::int32_t > compute_local_to_local(const std::vector< std::int64_t > &local0_to_global, const std::vector< std::int64_t > &local1_to_global)
Compute a local0-to-local1 map from two local-to-global maps with common global indices.
Definition: Partitioning.cpp:685
std::pair< graph::AdjacencyList< std::int32_t >, std::vector< std::int64_t > > create_local_adjacency_list(const graph::AdjacencyList< std::int64_t > &list)
Compute a local AdjacencyList list with contiguous indices from an AdjacencyList that may have non-co...
Definition: Partitioning.cpp:359
std::tuple< graph::AdjacencyList< std::int64_t >, std::vector< int >, std::vector< std::int64_t >, std::vector< int > > distribute(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &list, const graph::AdjacencyList< std::int32_t > &destinations)
Distribute adjacency list nodes to destination ranks. The global index of each node is assumed to be ...
Definition: Partitioning.cpp:420
Graph data structures and algorithms.
Definition: AdjacencyList.h:18